blob: e53c6b7bd8ad22dba947bfd1d091f51253ff99d0 (
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
|
#include "Swiften/Serializer/PayloadSerializers/SecurityLabelSerializer.h"
#include "Swiften/Base/foreach.h"
#include "Swiften/Serializer/XML/XMLRawTextNode.h"
#include "Swiften/Serializer/XML/XMLTextNode.h"
#include "Swiften/Serializer/XML/XMLElement.h"
namespace Swift {
SecurityLabelSerializer::SecurityLabelSerializer() : GenericPayloadSerializer<SecurityLabel>() {
}
String SecurityLabelSerializer::serializePayload(boost::shared_ptr<SecurityLabel> label) const {
XMLElement element("securitylabel", "urn:xmpp:sec-label:0");
if (!label->getDisplayMarking().isEmpty()) {
boost::shared_ptr<XMLElement> displayMarking(new XMLElement("displaymarking"));
if (!label->getForegroundColor().isEmpty()) {
displayMarking->setAttribute("fgcolor", label->getForegroundColor());
}
if (!label->getBackgroundColor().isEmpty()) {
displayMarking->setAttribute("bgcolor", label->getBackgroundColor());
}
displayMarking->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode(label->getDisplayMarking())));
element.addNode(displayMarking);
}
if (!label->getLabel().isEmpty()) {
boost::shared_ptr<XMLElement> labelElement(new XMLElement("label"));
labelElement->addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(label->getLabel())));
element.addNode(labelElement);
}
foreach(const String& equivalentLabel, label->getEquivalentLabels()) {
boost::shared_ptr<XMLElement> equivalentLabelElement(new XMLElement("equivalentlabel"));
equivalentLabelElement->addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(equivalentLabel)));
element.addNode(equivalentLabelElement);
}
return element.serialize();
}
}
|