diff options
Diffstat (limited to 'Swiften/Serializer/XML')
m--------- | Swiften | 0 | ||||
-rw-r--r-- | Swiften/Serializer/XML/UnitTest/XMLElementTest.cpp | 62 | ||||
-rw-r--r-- | Swiften/Serializer/XML/XMLElement.cpp | 49 | ||||
-rw-r--r-- | Swiften/Serializer/XML/XMLElement.h | 27 | ||||
-rw-r--r-- | Swiften/Serializer/XML/XMLNode.cpp | 8 | ||||
-rw-r--r-- | Swiften/Serializer/XML/XMLNode.h | 15 | ||||
-rw-r--r-- | Swiften/Serializer/XML/XMLRawTextNode.h | 21 | ||||
-rw-r--r-- | Swiften/Serializer/XML/XMLTextNode.h | 21 |
8 files changed, 0 insertions, 203 deletions
diff --git a/Swiften b/Swiften new file mode 160000 +Subproject 8213ba16d0043d2461f4b031c881d61dda5a38c diff --git a/Swiften/Serializer/XML/UnitTest/XMLElementTest.cpp b/Swiften/Serializer/XML/UnitTest/XMLElementTest.cpp deleted file mode 100644 index 49eb109..0000000 --- a/Swiften/Serializer/XML/UnitTest/XMLElementTest.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include <cppunit/extensions/HelperMacros.h> -#include <cppunit/extensions/TestFactoryRegistry.h> - -#include "Swiften/Serializer/XML/XMLElement.h" -#include "Swiften/Serializer/XML/XMLTextNode.h" - -using namespace Swift; - -class XMLElementTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE(XMLElementTest); - CPPUNIT_TEST(testSerialize); - CPPUNIT_TEST(testSerialize_NoChildren); - CPPUNIT_TEST(testSerialize_SpecialAttributeCharacters); - CPPUNIT_TEST(testSerialize_EmptyAttributeValue); - CPPUNIT_TEST_SUITE_END(); - - public: - XMLElementTest() {} - - void testSerialize() { - XMLElement testling("foo", "http://example.com"); - testling.setAttribute("myatt", "myval"); - boost::shared_ptr<XMLElement> barElement(new XMLElement("bar")); - barElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode("Blo"))); - testling.addNode(barElement); - boost::shared_ptr<XMLElement> bazElement(new XMLElement("baz")); - bazElement->addNode(boost::shared_ptr<XMLTextNode>(new XMLTextNode("Bli"))); - testling.addNode(bazElement); - - String result = testling.serialize(); - String expectedResult = - "<foo myatt=\"myval\" xmlns=\"http://example.com\">" - "<bar>Blo</bar>" - "<baz>Bli</baz>" - "</foo>"; - - CPPUNIT_ASSERT_EQUAL(expectedResult, result); - } - - void testSerialize_NoChildren() { - XMLElement testling("foo", "http://example.com"); - - CPPUNIT_ASSERT_EQUAL(String("<foo xmlns=\"http://example.com\"/>"), testling.serialize()); - } - - void testSerialize_SpecialAttributeCharacters() { - XMLElement testling("foo"); - testling.setAttribute("myatt", "<\"'&>"); - - CPPUNIT_ASSERT_EQUAL(String("<foo myatt=\"<"'&>\"/>"), testling.serialize()); - } - - void testSerialize_EmptyAttributeValue() { - XMLElement testling("foo"); - testling.setAttribute("myatt", ""); - - CPPUNIT_ASSERT_EQUAL(String("<foo myatt=\"\"/>"), testling.serialize()); - } -}; - -CPPUNIT_TEST_SUITE_REGISTRATION(XMLElementTest); diff --git a/Swiften/Serializer/XML/XMLElement.cpp b/Swiften/Serializer/XML/XMLElement.cpp deleted file mode 100644 index 71f4d0c..0000000 --- a/Swiften/Serializer/XML/XMLElement.cpp +++ /dev/null @@ -1,49 +0,0 @@ -#include "Swiften/Serializer/XML/XMLElement.h" - -#include "Swiften/Base/foreach.h" - -namespace Swift { - -XMLElement::XMLElement(const String& tag, const String& xmlns) : - tag_(tag) { - if (!xmlns.isEmpty()) { - setAttribute("xmlns", xmlns); - } -} - -String XMLElement::serialize() { - String result; - result += "<" + tag_; - typedef std::pair<String,String> Pair; - foreach(const Pair& p, attributes_) { - result += " " + p.first + "=\"" + p.second + "\""; - } - - if (childNodes_.size() > 0) { - result += ">"; - foreach (boost::shared_ptr<XMLNode> node, childNodes_) { - result += node->serialize(); - } - result += "</" + tag_ + ">"; - } - else { - result += "/>"; - } - return result; -} - -void XMLElement::setAttribute(const String& attribute, const String& value) { - String escapedValue(value); - escapedValue.replaceAll('&', "&"); - escapedValue.replaceAll('<', "<"); - escapedValue.replaceAll('>', ">"); - escapedValue.replaceAll('\'', "'"); - escapedValue.replaceAll('"', """); - attributes_[attribute] = escapedValue; -} - -void XMLElement::addNode(boost::shared_ptr<XMLNode> node) { - childNodes_.push_back(node); -} - -} diff --git a/Swiften/Serializer/XML/XMLElement.h b/Swiften/Serializer/XML/XMLElement.h deleted file mode 100644 index f2eb8bf..0000000 --- a/Swiften/Serializer/XML/XMLElement.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef SWIFTEN_XMLElement_H -#define SWIFTEN_XMLElement_H - -#include <boost/shared_ptr.hpp> -#include <vector> -#include <map> - -#include "Swiften/Base/String.h" -#include "Swiften/Serializer/XML/XMLNode.h" - -namespace Swift { - class XMLElement : public XMLNode { - public: - XMLElement(const String& tag, const String& xmlns = ""); - - void setAttribute(const String& attribute, const String& value); - void addNode(boost::shared_ptr<XMLNode> node); - - virtual String serialize(); - - private: - String tag_; - std::map<String, String> attributes_; - std::vector< boost::shared_ptr<XMLNode> > childNodes_; - }; -} -#endif diff --git a/Swiften/Serializer/XML/XMLNode.cpp b/Swiften/Serializer/XML/XMLNode.cpp deleted file mode 100644 index 1bef64a..0000000 --- a/Swiften/Serializer/XML/XMLNode.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "Swiften/Serializer/XML/XMLNode.h" - -namespace Swift { - -XMLNode::~XMLNode() { -} - -} diff --git a/Swiften/Serializer/XML/XMLNode.h b/Swiften/Serializer/XML/XMLNode.h deleted file mode 100644 index b31c0d6..0000000 --- a/Swiften/Serializer/XML/XMLNode.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef SWIFTEN_XMLNode_H -#define SWIFTEN_XMLNode_H - -#include "Swiften/Base/String.h" - -namespace Swift { - class XMLNode { - public: - virtual ~XMLNode(); - - virtual String serialize() = 0; - }; -} - -#endif diff --git a/Swiften/Serializer/XML/XMLRawTextNode.h b/Swiften/Serializer/XML/XMLRawTextNode.h deleted file mode 100644 index e5800c3..0000000 --- a/Swiften/Serializer/XML/XMLRawTextNode.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef SWIFTEN_XMLRawTextNode_H -#define SWIFTEN_XMLRawTextNode_H - -#include "Swiften/Serializer/XML/XMLNode.h" - -namespace Swift { - class XMLRawTextNode : public XMLNode { - public: - XMLRawTextNode(const String& text) : text_(text) { - } - - String serialize() { - return text_; - } - - private: - String text_; - }; -} - -#endif diff --git a/Swiften/Serializer/XML/XMLTextNode.h b/Swiften/Serializer/XML/XMLTextNode.h deleted file mode 100644 index 87dda53..0000000 --- a/Swiften/Serializer/XML/XMLTextNode.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once - -#include "Swiften/Serializer/XML/XMLNode.h" - -namespace Swift { - class XMLTextNode : public XMLNode { - public: - XMLTextNode(const String& text) : text_(text) { - text_.replaceAll('&', "&"); // Should come first - text_.replaceAll('<', "<"); - text_.replaceAll('>', ">"); - } - - String serialize() { - return text_; - } - - private: - String text_; - }; -} |