summaryrefslogtreecommitdiffstats
blob: d3aac69098ba3e7a2cdca67ba5fef755a4491708 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
 * Copyright (c) 2013 Remko Tronçon
 * Licensed under the GNU General Public License.
 * See the COPYING file for more information.
 */

#include <Swiften/Parser/PayloadParsers/UserLocationParser.h>

#include <boost/lexical_cast.hpp>

#include <Swiften/Base/DateTime.h>

using namespace Swift;

UserLocationParser::UserLocationParser() : level(0) {
}

UserLocationParser::~UserLocationParser() {
}

void UserLocationParser::handleStartElement(const std::string&, const std::string&, const AttributeMap&) {
	if (level == 1) {
		currentText = "";
	}
	++level;
}

void UserLocationParser::handleEndElement(const std::string& element, const std::string&) {
	--level;
	if (level == 1) {
		try {
			if (element == "accuracy") {
				getPayloadInternal()->setAccuracy(boost::lexical_cast<float>(currentText));
			}
			else if (element == "alt") {
				getPayloadInternal()->setAltitude(boost::lexical_cast<float>(currentText));
			}
			else if (element == "area") {
				getPayloadInternal()->setArea(currentText);
			}
			else if (element == "bearing") {
				getPayloadInternal()->setBearing(boost::lexical_cast<float>(currentText));
			}
			else if (element == "building") {
				getPayloadInternal()->setBuilding(currentText);
			}
			else if (element == "country") {
				getPayloadInternal()->setCountry(currentText);
			}
			else if (element == "countrycode") {
				getPayloadInternal()->setCountryCode(currentText);
			}
			else if (element == "datum") {
				getPayloadInternal()->setDatum(currentText);
			}
			else if (element == "description") {
				getPayloadInternal()->setDescription(currentText);
			}
			else if (element == "error") {
				getPayloadInternal()->setError(boost::lexical_cast<float>(currentText));
			}
			else if (element == "floor") {
				getPayloadInternal()->setFloor(currentText);
			}
			else if (element == "lat") {
				getPayloadInternal()->setLatitude(boost::lexical_cast<float>(currentText));
			}
			else if (element == "locality") {
				getPayloadInternal()->setLocality(currentText);
			}
			else if (element == "lon") {
				getPayloadInternal()->setLongitude(boost::lexical_cast<float>(currentText));
			}
			else if (element == "postalcode") {
				getPayloadInternal()->setPostalCode(currentText);
			}
			else if (element == "region") {
				getPayloadInternal()->setRegion(currentText);
			}
			else if (element == "room") {
				getPayloadInternal()->setRoom(currentText);
			}
			else if (element == "speed") {
				getPayloadInternal()->setSpeed(boost::lexical_cast<float>(currentText));
			}
			else if (element == "street") {
				getPayloadInternal()->setStreet(currentText);
			}
			else if (element == "text") {
				getPayloadInternal()->setText(currentText);
			}
			else if (element == "timestamp") {
				getPayloadInternal()->setTimestamp(stringToDateTime(currentText));
			}
			else if (element == "uri") {
				getPayloadInternal()->setURI(currentText);
			}
		}
		catch (const boost::bad_lexical_cast&) {
		}
	}
}

void UserLocationParser::handleCharacterData(const std::string& data) {
	currentText += data;
}