<commit_before>/*
 *  Copyright (C) 2012-2013 Stichting Akvo (Akvo Foundation)
 *
 *  This file is part of Akvo RSR.
 *
 *  Akvo RSR is free software: you can redistribute it and modify it under the terms of
 *  the GNU Affero General Public License (AGPL) as published by the Free Software Foundation,
 *  either version 3 of the License or any later version.
 *
 *  Akvo RSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU Affero General Public License included with this program for more details.
 *
 *  The full license text can also be seen at <http://www.gnu.org/licenses/agpl.html>.
 */

package org.akvo.rsr.up.xml;

import org.akvo.rsr.up.dao.RsrDbAdapter;
import org.akvo.rsr.up.domain.User;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/*
 * http://rsr.uat.akvo.org/api/v1/user/2/?format=xml&depth=1
 * Example input:
 * 
<object>
<username>thomas</username>
<first_name>Thomas</first_name>
<last_name>Bjelkeman-Pettersson</last_name>
<user_profile>
	<organisation>/api/v1/organisation/42/</organisation>
	<is_org_admin type="boolean">False</is_org_admin>
	<is_org_editor type="boolean">False</is_org_editor>
	<user>/api/v1/user/2/</user>
	<resource_uri>/api/v1/user_profile/16/</resource_uri>
</user_profile>
<last_login>2013-11-14T12:21:59</last_login>
<email>thomas<EMAIL></email>
<resource_uri>/api/v1/user/2/</resource_uri>
</object>

V3: No profile anymore. if called by an admin, get a nested list
TODO:handle this.

<object><email><EMAIL></email><first_name>Lissy</first_name><last_login>2015-01-05T11:57:49</last_login><last_name><NAME></last_name>
<organisations type="list">
<object><absolute_url>/organisation/42/</absolute_url><allow_edit type="boolean">True</allow_edit><contact_email><EMAIL></contact_email><contact_person><NAME></contact_person><created_at>2008-08-04T00:00:00</created_at>
<description>Akvo develops and runs web and mobile services that are designed to support international development partnership networks. Akvo manages a number of unique and transformative services, backed by a partner support and training team: 
Akvo is a non-profit foundation with staff in the Netherlands, Britain, Sweden, Kenya, India and the United States. The Akvo tools are open source, used by over 700 organisations and applied throughout the world for better programming and reporting in areas such as water, sanitation, health, education and economic development.</description>
<facebook/><fax/><iati_org_id>NL-KVK-27327087</iati_org_id><id type="integer">42</id><language>en</language><last_modified_at>2015-03-18T09:29:15.913590</last_modified_at><linkedin/><locations type="list"><value>/api/v1/organisation_location/34/</value></locations><logo type="hash"><original>/media/db/org/42/Organisation_42_logo_2014-08-07_15.32.44.jpg</original><thumbnails type="null"/></logo><long_name>Akvo Foundation</long_name><mobile/><name>Akvo</name><new_organisation_type type="integer">22</new_organisation_type><notes>Organisation duplicate 2091 deleted</notes><organisation_type>N</organisation_type><partnerships type="list"><value>/api/v1/partnership/45021/</value><value>/api/v1/partnership/21186/</value><value>/api/v1/partnership/21296/</value><value>/api/v1/partnership/2226/</value><value>/api/v1/partnership/2389/</value><value>/api/v1/partnership/21396/</value><value>/api/v1/partnership/31/</value><value>/api/v1/partnership/27262/</value><value>/api/v1/partnership/42640/</value><value>/api/v1/partnership/8992/</value><value>/api/v1/partnership/12321/</value><value>/api/v1/partnership/12377/</value><value>/api/v1/partnership/16268/</value><value>/api/v1/partnership/41302/</value><value>/api/v1/partnership/324/</value><value>/api/v1/partnership/39398/</value><value>/api/v1/partnership/35739/</value><value>/api/v1/partnership/40636/</value><value>/api/v1/partnership/5752/</value><value>/api/v1/partnership/12028/</value><value>/api/v1/partnership/1099/</value><value>/api/v1/partnership/4950/</value><value>/api/v1/partnership/1515/</value><value>/api/v1/partnership/27522/</value><value>/api/v1/partnership/26412/</value><value>/api/v1/partnership/26448/</value><value>/api/v1/partnership/45772/</value><value>/api/v1/partnership/1130/</value><value>/api/v1/partnership/28067/</value><value>/api/v1/partnership/27000/</value><value>/api/v1/partnership/27261/</value><value>/api/v1/partnership/26441/</value><value>/api/v1/partnership/3452/</value><value>/api/v1/partnership/4123/</value><value>/api/v1/partnership/27258/</value><value>/api/v1/partnership/21338/</value><value>/api/v1/partnership/21340/</value><value>/api/v1/partnership/21341/</value><value>/api/v1/partnership/21342/</value><value>/api/v1/partnership/21343/</value><value>/api/v1/partnership/21345/</value><value>/api/v1/partnership/21346/</value><value>/api/v1/partnership/21348/</value><value>/api/v1/partnership/21349/</value><value>/api/v1/partnership/21350/</value><value>/api/v1/partnership/21351/</value><value>/api/v1/partnership/21352/</value><value>/api/v1/partnership/21353/</value><value>/api/v1/partnership/21354/</value><value>/api/v1/partnership/21355/</value><value>/api/v1/partnership/21356/</value><value>/api/v1/partnership/21357/</value><value>/api/v1/partnership/21359/</value><value>/api/v1/partnership/21360/</value><value>/api/v1/partnership/21361/</value><value>/api/v1/partnership/21362/</value><value>/api/v1/partnership/21363/</value><value>/api/v1/partnership/21364/</value><value>/api/v1/partnership/21365/</value><value>/api/v1/partnership/21366/</value><value>/api/v1/partnership/21367/</value><value>/api/v1/partnership/21405/</value><value>/api/v1/partnership/26355/</value><value>/api/v1/partnership/26402/</value><value>/api/v1/partnership/26405/</value><value>/api/v1/partnership/26406/</value><value>/api/v1/partnership/26407/</value><value>/api/v1/partnership/26408/</value><value>/api/v1/partnership/26410/</value><value>/api/v1/partnership/26411/</value><value>/api/v1/partnership/26413/</value><value>/api/v1/partnership/26414/</value><value>/api/v1/partnership/26415/</value><value>/api/v1/partnership/26416/</value><value>/api/v1/partnership/26440/</value><value>/api/v1/partnership/26456/</value><value>/api/v1/partnership/26457/</value><value>/api/v1/partnership/34071/</value><value>/api/v1/partnership/26547/</value><value>/api/v1/partnership/26701/</value><value>/api/v1/partnership/27259/</value><value>/api/v1/partnership/27257/</value><value>/api/v1/partnership/27007/</value><value>/api/v1/partnership/28091/</value><value>/api/v1/partnership/33923/</value><value>/api/v1/partnership/35701/</value><value>/api/v1/partnership/35702/</value><value>/api/v1/partnership/35703/</value><value>/api/v1/partnership/35704/</value><value>/api/v1/partnership/35705/</value><value>/api/v1/partnership/35706/</value><value>/api/v1/partnership/35707/</value><value>/api/v1/partnership/35708/</value><value>/api/v1/partnership/35709/</value><value>/api/v1/partnership/26998/</value><value>/api/v1/partnership/681/</value><value>/api/v1/partnership/851/</value><value>/api/v1/partnership/975/</value><value>/api/v1/partnership/26395/</value><value>/api/v1/partnership/1955/</value><value>/api/v1/partnership/2123/</value><value>/api/v1/partnership/26392/</value><value>/api/v1/partnership/3214/</value><value>/api/v1/partnership/3954/</value><value>/api/v1/partnership/26446/</value><value>/api/v1/partnership/21300/</value><value>/api/v1/partnership/21301/</value><value>/api/v1/partnership/21302/</value><value>/api/v1/partnership/21303/</value><value>/api/v1/partnership/21304/</value><value>/api/v1/partnership/21305/</value><value>/api/v1/partnership/21306/</value><value>/api/v1/partnership/21307/</value><value>/api/v1/partnership/21308/</value><value>/api/v1/partnership/21309/</value><value>/api/v1/partnership/21310/</value><value>/api/v1/partnership/21311/</value><value>/api/v1/partnership/21312/</value><value>/api/v1/partnership/21313/</value><value>/api/v1/partnership/21314/</value><value>/api/v1/partnership/21315/</value><value>/api/v1/partnership/21317/</value><value>/api/v1/partnership/21318/</value><value>/api/v1/partnership/21319/</value><value>/api/v1/partnership/21320/</value><value>/api/v1/partnership/21321/</value><value>/api/v1/partnership/21322/</value><value>/api/v1/partnership/21323/</value><value>/api/v1/partnership/21337/</value></partnerships><phone>+31-(0)20-8200175</phone><primary_location><address_1>'s-Gravenhekje 1A</address_1><address_2/><city>Amsterdam</city><country>/api/v1/country/3/</country><id type="integer">34</id><latitude type="float">52.3723</latitude><longitude type="float">4.907987</longitude><organisation>/api/v1/organisation/42/</organisation><postcode>1011 TG</postcode><resource_uri>/api/v1/organisation_location/34/</resource_uri><state>Noord-Holland</state></primary_location><resource_uri>/api/v1/organisation/42/</resource_uri><twitter/><url>http://www.akvo.org/</url>
</object>
</organisations>
<resource_uri>/api/v1/user/394/</resource_uri>
<username>Lissyvn</username>
</object>


<commit_msg>[#164]Update comments and copyright notice<commit_after>/*
 *  Copyright (C) 2012-2015 <NAME> (Akvo Foundation)
 *
 *  This file is part of Akvo RSR.
 *
 *  Akvo RSR is free software: you can redistribute it and modify it under the terms of
 *  the GNU Affero General Public License (AGPL) as published by the Free Software Foundation,
 *  either version 3 of the License or any later version.
 *
 *  Akvo RSR is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 *  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *  See the GNU Affero General Public License included with this program for more details.
 *
 *  The full license text can also be seen at <http://www.gnu.org/licenses/agpl.html>.
 */

package org.akvo.rsr.up.xml;

import org.akvo.rsr.up.dao.RsrDbAdapter;
import org.akvo.rsr.up.domain.User;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

/*
 * http://rsr.uat.akvo.org/api/v1/user/2/?format=xml&depth=1
 * Example input if not same org:
 * 
<object>
    <first_name>Robert </first_name>
    <last_login>2013-01-11T10:43:21</last_login>
    <last_name>Knol</last_name>
    <resource_uri>/api/v1/user/222/</resource_uri>
</object>

If called by an admin, get a nested list of organisations

<object><email><EMAIL></email><first_name>Lissy</first_name><last_login>2015-01-05T11:57:49</last_login><last_name><NAME></last_name>
<organisations type="list">
<object><absolute_url>/organisation/42/</absolute_url><allow_edit type="boolean">True</allow_edit><contact_email><EMAIL></contact_email><contact_person><NAME></contact_person><created_at>2008-08-04T00:00:00</created_at>
<description>Akvo develops and runs web and mobile services that are designed to support international development partnership networks. Akvo manages a number of unique and transformative services, backed by a partner support and training team: 
Akvo is a non-profit foundation with staff in the Netherlands, Britain, Sweden, Kenya, India and the United States. The Akvo tools are open source, used by over 700 organisations and applied throughout the world for better programming and reporting in areas such as water, sanitation, health, education and economic development.</description>
<facebook/><fax/><iati_org_id>NL-KVK-27327087</iati_org_id><id type="integer">42</id><language>en</language><last_modified_at>2015-03-18T09:29:15.913590</last_modified_at><linkedin/><locations type="list"><value>/api/v1/organisation_location/34/</value></locations><logo type="hash"><original>/media/db/org/42/Organisation_42_logo_2014-08-07_15.32.44.jpg</original><thumbnails type="null"/></logo><long_name>Akvo Foundation</long_name><mobile/><name>Akvo</name><new_organisation_type type="integer">22</new_organisation_type><notes>Organisation duplicate 2091 deleted</notes><organisation_type>N</organisation_type><partnerships type="list"><value>/api/v1/partnership/45021/</value><value>/api/v1/partnership/21186/</value><value>/api/v1/partnership/21296/</value><value>/api/v1/partnership/2226/</value><value>/api/v1/partnership/2389/</value><value>/api/v1/partnership/21396/</value><value>/api/v1/partnership/31/</value><value>/api/v1/partnership/27262/</value><value>/api/v1/partnership/42640/</value><value>/api/v1/partnership/8992/</value><value>/api/v1/partnership/12321/</value><value>/api/v1/partnership/12377/</value><value>/api/v1/partnership/16268/</value><value>/api/v1/partnership/41302/</value><value>/api/v1/partnership/324/</value><value>/api/v1/partnership/39398/</value><value>/api/v1/partnership/35739/</value><value>/api/v1/partnership/40636/</value><value>/api/v1/partnership/5752/</value><value>/api/v1/partnership/12028/</value><value>/api/v1/partnership/1099/</value><value>/api/v1/partnership/4950/</value><value>/api/v1/partnership/1515/</value><value>/api/v1/partnership/27522/</value><value>/api/v1/partnership/26412/</value><value>/api/v1/partnership/26448/</value><value>/api/v1/partnership/45772/</value><value>/api/v1/partnership/1130/</value><value>/api/v1/partnership/28067/</value><value>/api/v1/partnership/27000/</value><value>/api/v1/partnership/27261/</value><value>/api/v1/partnership/26441/</value><value>/api/v1/partnership/3452/</value><value>/api/v1/partnership/4123/</value><value>/api/v1/partnership/27258/</value><value>/api/v1/partnership/21338/</value><value>/api/v1/partnership/21340/</value><value>/api/v1/partnership/21341/</value><value>/api/v1/partnership/21342/</value><value>/api/v1/partnership/21343/</value><value>/api/v1/partnership/21345/</value><value>/api/v1/partnership/21346/</value><value>/api/v1/partnership/21348/</value><value>/api/v1/partnership/21349/</value><value>/api/v1/partnership/21350/</value><value>/api/v1/partnership/21351/</value><value>/api/v1/partnership/21352/</value><value>/api/v1/partnership/21353/</value><value>/api/v1/partnership/21354/</value><value>/api/v1/partnership/21355/</value><value>/api/v1/partnership/21356/</value><value>/api/v1/partnership/21357/</value><value>/api/v1/partnership/21359/</value><value>/api/v1/partnership/21360/</value><value>/api/v1/partnership/21361/</value><value>/api/v1/partnership/21362/</value><value>/api/v1/partnership/21363/</value><value>/api/v1/partnership/21364/</value><value>/api/v1/partnership/21365/</value><value>/api/v1/partnership/21366/</value><value>/api/v1/partnership/21367/</value><value>/api/v1/partnership/21405/</value><value>/api/v1/partnership/26355/</value><value>/api/v1/partnership/26402/</value><value>/api/v1/partnership/26405/</value><value>/api/v1/partnership/26406/</value><value>/api/v1/partnership/26407/</value><value>/api/v1/partnership/26408/</value><value>/api/v1/partnership/26410/</value><value>/api/v1/partnership/26411/</value><value>/api/v1/partnership/26413/</value><value>/api/v1/partnership/26414/</value><value>/api/v1/partnership/26415/</value><value>/api/v1/partnership/26416/</value><value>/api/v1/partnership/26440/</value><value>/api/v1/partnership/26456/</value><value>/api/v1/partnership/26457/</value><value>/api/v1/partnership/34071/</value><value>/api/v1/partnership/26547/</value><value>/api/v1/partnership/26701/</value><value>/api/v1/partnership/27259/</value><value>/api/v1/partnership/27257/</value><value>/api/v1/partnership/27007/</value><value>/api/v1/partnership/28091/</value><value>/api/v1/partnership/33923/</value><value>/api/v1/partnership/35701/</value><value>/api/v1/partnership/35702/</value><value>/api/v1/partnership/35703/</value><value>/api/v1/partnership/35704/</value><value>/api/v1/partnership/35705/</value><value>/api/v1/partnership/35706/</value><value>/api/v1/partnership/35707/</value><value>/api/v1/partnership/35708/</value><value>/api/v1/partnership/35709/</value><value>/api/v1/partnership/26998/</value><value>/api/v1/partnership/681/</value><value>/api/v1/partnership/851/</value><value>/api/v1/partnership/975/</value><value>/api/v1/partnership/26395/</value><value>/api/v1/partnership/1955/</value><value>/api/v1/partnership/2123/</value><value>/api/v1/partnership/26392/</value><value>/api/v1/partnership/3214/</value><value>/api/v1/partnership/3954/</value><value>/api/v1/partnership/26446/</value><value>/api/v1/partnership/21300/</value><value>/api/v1/partnership/21301/</value><value>/api/v1/partnership/21302/</value><value>/api/v1/partnership/21303/</value><value>/api/v1/partnership/21304/</value><value>/api/v1/partnership/21305/</value><value>/api/v1/partnership/21306/</value><value>/api/v1/partnership/21307/</value><value>/api/v1/partnership/21308/</value><value>/api/v1/partnership/21309/</value><value>/api/v1/partnership/21310/</value><value>/api/v1/partnership/21311/</value><value>/api/v1/partnership/21312/</value><value>/api/v1/partnership/21313/</value><value>/api/v1/partnership/21314/</value><value>/api/v1/partnership/21315/</value><value>/api/v1/partnership/21317/</value><value>/api/v1/partnership/21318/</value><value>/api/v1/partnership/21319/</value><value>/api/v1/partnership/21320/</value><value>/api/v1/partnership/21321/</value><value>/api/v1/partnership/21322/</value><value>/api/v1/partnership/21323/</value><value>/api/v1/partnership/21337/</value></partnerships><phone>+31-(0)20-8200175</phone><primary_location><address_1>'s-Gravenhekje 1A</address_1><address_2/><city>Amsterdam</city><country>/api/v1/country/3/</country><id type="integer">34</id><latitude type="float">52.3723</latitude><longitude type="float">4.907987</longitude><organisation>/api/v1/organisation/42/</organisation><postcode>1011 TG</postcode><resource_uri>/api/v1/organisation_location/34/</resource_uri><state>Noord-Holland</state></primary_location><resource_uri>/api/v1/organisation/42/</resource_uri><twitter/><url>http://www.akvo.org/</url>
</object>
</organisations>
<resource_uri>/api/v1/user/394/</resource_uri>
<username>Lissyvn</username>
</object>
{'fraction_non_alphanumeric': 0.20144719399027838, 'fraction_numerical': 0.10207688908528502, 'mean_word_length': 6.017441860465116, 'pattern_counts': {'":': 0, '<': 753, '<?xml version=': 0, '>': 753, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 10}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2274063', 'n_tokens_mistral': 7507, 'n_tokens_neox': 6554, 'n_words': 523}