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
|
/*
* Copyright (c) 2013-2016 Isode Limited.
* All rights reserved.
* See the COPYING file for more information.
*/
#pragma clang diagnostic ignored "-Wunused-private-field"
#include <Swiften/Serializer/PayloadSerializers/UserLocationSerializer.h>
#include <Swiften/Serializer/XML/XMLElement.h>
#include <Swiften/Base/DateTime.h>
#include <boost/lexical_cast.hpp>
#include <memory>
#include <Swiften/Serializer/PayloadSerializerCollection.h>
#include <Swiften/Serializer/XML/XMLElement.h>
using namespace Swift;
UserLocationSerializer::UserLocationSerializer(PayloadSerializerCollection* serializers) : serializers(serializers) {
}
UserLocationSerializer::~UserLocationSerializer() {
}
std::string UserLocationSerializer::serializePayload(std::shared_ptr<UserLocation> payload) const {
if (!payload) {
return "";
}
XMLElement element("geoloc", "http://jabber.org/protocol/geoloc");
if (payload->getArea()) {
element.addNode(std::make_shared<XMLElement>("area", "", *payload->getArea()));
}
if (payload->getAltitude()) {
element.addNode(std::make_shared<XMLElement>("alt", "", boost::lexical_cast<std::string>(*payload->getAltitude())));
}
if (payload->getLocality()) {
element.addNode(std::make_shared<XMLElement>("locality", "", *payload->getLocality()));
}
if (payload->getLatitude()) {
element.addNode(std::make_shared<XMLElement>("lat", "", boost::lexical_cast<std::string>(*payload->getLatitude())));
}
if (payload->getAccuracy()) {
element.addNode(std::make_shared<XMLElement>("accuracy", "", boost::lexical_cast<std::string>(*payload->getAccuracy())));
}
if (payload->getDescription()) {
element.addNode(std::make_shared<XMLElement>("description", "", *payload->getDescription()));
}
if (payload->getCountryCode()) {
element.addNode(std::make_shared<XMLElement>("countrycode", "", *payload->getCountryCode()));
}
if (payload->getTimestamp()) {
element.addNode(std::make_shared<XMLElement>("timestamp", "", dateTimeToString(*payload->getTimestamp())));
}
if (payload->getFloor()) {
element.addNode(std::make_shared<XMLElement>("floor", "", *payload->getFloor()));
}
if (payload->getBuilding()) {
element.addNode(std::make_shared<XMLElement>("building", "", *payload->getBuilding()));
}
if (payload->getRoom()) {
element.addNode(std::make_shared<XMLElement>("room", "", *payload->getRoom()));
}
if (payload->getCountry()) {
element.addNode(std::make_shared<XMLElement>("country", "", *payload->getCountry()));
}
if (payload->getRegion()) {
element.addNode(std::make_shared<XMLElement>("region", "", *payload->getRegion()));
}
if (payload->getURI()) {
element.addNode(std::make_shared<XMLElement>("uri", "", *payload->getURI()));
}
if (payload->getLongitude()) {
element.addNode(std::make_shared<XMLElement>("lon", "", boost::lexical_cast<std::string>(*payload->getLongitude())));
}
if (payload->getError()) {
element.addNode(std::make_shared<XMLElement>("error", "", boost::lexical_cast<std::string>(*payload->getError())));
}
if (payload->getPostalCode()) {
element.addNode(std::make_shared<XMLElement>("postalcode", "", *payload->getPostalCode()));
}
if (payload->getBearing()) {
element.addNode(std::make_shared<XMLElement>("bearing", "", boost::lexical_cast<std::string>(*payload->getBearing())));
}
if (payload->getText()) {
element.addNode(std::make_shared<XMLElement>("text", "", *payload->getText()));
}
if (payload->getDatum()) {
element.addNode(std::make_shared<XMLElement>("datum", "", *payload->getDatum()));
}
if (payload->getStreet()) {
element.addNode(std::make_shared<XMLElement>("street", "", *payload->getStreet()));
}
if (payload->getSpeed()) {
element.addNode(std::make_shared<XMLElement>("speed", "", boost::lexical_cast<std::string>(*payload->getSpeed())));
}
return element.serialize();
}
|