1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "jingle/notifier/listener/xml_element_util.h"
6
7 #include <sstream>
8 #include <string>
9
10 #include "base/strings/string_number_conversions.h"
11 #include "third_party/libjingle_xmpp/xmllite/qname.h"
12 #include "third_party/libjingle_xmpp/xmllite/xmlconstants.h"
13 #include "third_party/libjingle_xmpp/xmllite/xmlelement.h"
14 #include "third_party/libjingle_xmpp/xmllite/xmlprinter.h"
15
16 namespace notifier {
17
XmlElementToString(const jingle_xmpp::XmlElement & xml_element)18 std::string XmlElementToString(const jingle_xmpp::XmlElement& xml_element) {
19 std::ostringstream xml_stream;
20 jingle_xmpp::XmlPrinter::PrintXml(&xml_stream, &xml_element);
21 return xml_stream.str();
22 }
23
MakeBoolXmlElement(const char * name,bool value)24 jingle_xmpp::XmlElement* MakeBoolXmlElement(const char* name, bool value) {
25 const jingle_xmpp::QName elementQName(jingle_xmpp::STR_EMPTY, name);
26 const jingle_xmpp::QName boolAttrQName(jingle_xmpp::STR_EMPTY, "bool");
27 jingle_xmpp::XmlElement* bool_xml_element =
28 new jingle_xmpp::XmlElement(elementQName, true);
29 bool_xml_element->AddAttr(boolAttrQName, value ? "true" : "false");
30 return bool_xml_element;
31 }
32
MakeIntXmlElement(const char * name,int value)33 jingle_xmpp::XmlElement* MakeIntXmlElement(const char* name, int value) {
34 const jingle_xmpp::QName elementQName(jingle_xmpp::STR_EMPTY, name);
35 const jingle_xmpp::QName intAttrQName(jingle_xmpp::STR_EMPTY, "int");
36 jingle_xmpp::XmlElement* int_xml_element =
37 new jingle_xmpp::XmlElement(elementQName, true);
38 int_xml_element->AddAttr(intAttrQName, base::NumberToString(value));
39 return int_xml_element;
40 }
41
MakeStringXmlElement(const char * name,const char * value)42 jingle_xmpp::XmlElement* MakeStringXmlElement(const char* name, const char* value) {
43 const jingle_xmpp::QName elementQName(jingle_xmpp::STR_EMPTY, name);
44 const jingle_xmpp::QName dataAttrQName(jingle_xmpp::STR_EMPTY, "data");
45 jingle_xmpp::XmlElement* data_xml_element =
46 new jingle_xmpp::XmlElement(elementQName, true);
47 data_xml_element->AddAttr(dataAttrQName, value);
48 return data_xml_element;
49 }
50
51 } // namespace notifier
52