summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-11 15:51:42 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-11 15:56:10 (GMT)
commit1d6d6588e3affc9a736b29062107ca82ad6a5644 (patch)
tree54a96dd3f652df321ed5017148811d241baa1dd8
parente1a2d258479cd915e8c30c5c996b58da3da3e55d (diff)
downloadswift-contrib-1d6d6588e3affc9a736b29062107ca82ad6a5644.zip
swift-contrib-1d6d6588e3affc9a736b29062107ca82ad6a5644.tar.bz2
Added Raw XML payload parser & serializer.
-rw-r--r--Swiften/Elements/RawXMLPayload.h22
-rw-r--r--Swiften/Elements/UnknownElement.h7
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp5
-rw-r--r--Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h6
-rw-r--r--Swiften/Parser/PayloadParsers/Makefile.inc1
-rw-r--r--Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp26
-rw-r--r--Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h22
-rw-r--r--Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h20
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/Makefile.inc3
-rw-r--r--Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp34
-rw-r--r--Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp2
-rw-r--r--Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h15
12 files changed, 154 insertions, 9 deletions
diff --git a/Swiften/Elements/RawXMLPayload.h b/Swiften/Elements/RawXMLPayload.h
new file mode 100644
index 0000000..c2ee439
--- /dev/null
+++ b/Swiften/Elements/RawXMLPayload.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "Swiften/Base/String.h"
+#include "Swiften/Elements/Payload.h"
+
+namespace Swift {
+ class RawXMLPayload : public Payload {
+ public:
+ RawXMLPayload() {}
+
+ void setRawXML(const String& data) {
+ rawXML_ = data;
+ }
+
+ const String& getRawXML() const {
+ return rawXML_;
+ }
+
+ private:
+ String rawXML_;
+ };
+}
diff --git a/Swiften/Elements/UnknownElement.h b/Swiften/Elements/UnknownElement.h
index a2ae406..3d2c219 100644
--- a/Swiften/Elements/UnknownElement.h
+++ b/Swiften/Elements/UnknownElement.h
@@ -4,10 +4,9 @@
#include "Swiften/Elements/Element.h"
namespace Swift {
- class UnknownElement : public Element
- {
- public:
- UnknownElement() {}
+ class UnknownElement : public Element {
+ public:
+ UnknownElement() {}
};
}
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
index 32a8c25..8a7f468 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
@@ -16,6 +16,7 @@
#include "Swiften/Parser/PayloadParsers/SecurityLabelsCatalogParserFactory.h"
#include "Swiften/Parser/PayloadParsers/VCardUpdateParserFactory.h"
#include "Swiften/Parser/PayloadParsers/VCardParserFactory.h"
+#include "Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h"
using namespace boost;
@@ -39,9 +40,13 @@ FullPayloadParserFactoryCollection::FullPayloadParserFactoryCollection() {
foreach(shared_ptr<PayloadParserFactory> factory, factories_) {
addFactory(factory.get());
}
+ defaultFactory_ = new RawXMLPayloadParserFactory();
+ setDefaultFactory(defaultFactory_);
}
FullPayloadParserFactoryCollection::~FullPayloadParserFactoryCollection() {
+ setDefaultFactory(NULL);
+ delete defaultFactory_;
foreach(shared_ptr<PayloadParserFactory> factory, factories_) {
removeFactory(factory.get());
}
diff --git a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h
index 3c383ec..82e5a56 100644
--- a/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h
+++ b/Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.h
@@ -1,5 +1,4 @@
-#ifndef SWIFTEN_FULLPAYLOADPARSERFACTORYCOLLECTION_H
-#define SWIFTEN_FULLPAYLOADPARSERFACTORYCOLLECTION_H
+#pragma once
#include <boost/shared_ptr.hpp>
#include <vector>
@@ -15,7 +14,6 @@ namespace Swift {
private:
std::vector< boost::shared_ptr<PayloadParserFactory> > factories_;
+ PayloadParserFactory* defaultFactory_;
};
}
-
-#endif
diff --git a/Swiften/Parser/PayloadParsers/Makefile.inc b/Swiften/Parser/PayloadParsers/Makefile.inc
index b6e9954..55017e9 100644
--- a/Swiften/Parser/PayloadParsers/Makefile.inc
+++ b/Swiften/Parser/PayloadParsers/Makefile.inc
@@ -12,6 +12,7 @@ SWIFTEN_SOURCES += \
Swiften/Parser/PayloadParsers/ResourceBindParser.cpp \
Swiften/Parser/PayloadParsers/VCardUpdateParser.cpp \
Swiften/Parser/PayloadParsers/VCardParser.cpp \
+ Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp \
Swiften/Parser/PayloadParsers/FullPayloadParserFactoryCollection.cpp
include Swiften/Parser/PayloadParsers/UnitTest/Makefile.inc
diff --git a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp
new file mode 100644
index 0000000..c49af3e
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.cpp
@@ -0,0 +1,26 @@
+#include "Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h"
+#include "Swiften/Parser/SerializingParser.h"
+
+namespace Swift {
+
+RawXMLPayloadParser::RawXMLPayloadParser() : level_(0) {
+}
+
+void RawXMLPayloadParser::handleStartElement(const String& element, const String& ns, const AttributeMap& attributes) {
+ ++level_;
+ serializingParser_.handleStartElement(element, ns, attributes);
+}
+
+void RawXMLPayloadParser::handleEndElement(const String& element, const String& ns) {
+ serializingParser_.handleEndElement(element, ns);
+ --level_;
+ if (level_ == 0) {
+ getPayloadInternal()->setRawXML(serializingParser_.getResult());
+ }
+}
+
+void RawXMLPayloadParser::handleCharacterData(const String& data) {
+ serializingParser_.handleCharacterData(data);
+}
+
+}
diff --git a/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h
new file mode 100644
index 0000000..f636486
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h
@@ -0,0 +1,22 @@
+#pragma once
+
+#include "Swiften/Elements/RawXMLPayload.h"
+#include "Swiften/Parser/GenericPayloadParser.h"
+#include "Swiften/Parser/SerializingParser.h"
+
+namespace Swift {
+ class SerializingParser;
+
+ class RawXMLPayloadParser : public GenericPayloadParser<RawXMLPayload> {
+ public:
+ RawXMLPayloadParser();
+
+ virtual void handleStartElement(const String& element, const String&, const AttributeMap& attributes);
+ virtual void handleEndElement(const String& element, const String&);
+ virtual void handleCharacterData(const String& data);
+
+ private:
+ int level_;
+ SerializingParser serializingParser_;
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h b/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h
new file mode 100644
index 0000000..46b1183
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/RawXMLPayloadParserFactory.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "Swiften/Parser/PayloadParserFactory.h"
+#include "Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h"
+#include "Swiften/Base/String.h"
+
+namespace Swift {
+ class RawXMLPayloadParserFactory : public PayloadParserFactory {
+ public:
+ RawXMLPayloadParserFactory() {}
+
+ virtual bool canParse(const String&, const String&, const AttributeMap&) const {
+ return true;
+ }
+
+ virtual PayloadParser* createPayloadParser() {
+ return new RawXMLPayloadParser();
+ }
+ };
+}
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/Makefile.inc b/Swiften/Parser/PayloadParsers/UnitTest/Makefile.inc
index 26f7b3c..d7d419e 100644
--- a/Swiften/Parser/PayloadParsers/UnitTest/Makefile.inc
+++ b/Swiften/Parser/PayloadParsers/UnitTest/Makefile.inc
@@ -11,4 +11,5 @@ UNITTEST_SOURCES += \
Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelParserTest.cpp \
Swiften/Parser/PayloadParsers/UnitTest/SecurityLabelsCatalogParserTest.cpp \
Swiften/Parser/PayloadParsers/UnitTest/VCardUpdateParserTest.cpp \
- Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp
+ Swiften/Parser/PayloadParsers/UnitTest/VCardParserTest.cpp \
+ Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp
diff --git a/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp b/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp
new file mode 100644
index 0000000..5a2be8d
--- /dev/null
+++ b/Swiften/Parser/PayloadParsers/UnitTest/RawXMLPayloadParserTest.cpp
@@ -0,0 +1,34 @@
+#include <cppunit/extensions/HelperMacros.h>
+#include <cppunit/extensions/TestFactoryRegistry.h>
+
+#include "Swiften/Parser/PayloadParsers/RawXMLPayloadParser.h"
+#include "Swiften/Parser/PayloadParsers/UnitTest/PayloadParserTester.h"
+
+using namespace Swift;
+
+class RawXMLPayloadParserTest : public CppUnit::TestFixture
+{
+ CPPUNIT_TEST_SUITE(RawXMLPayloadParserTest);
+ CPPUNIT_TEST(testParse);
+ CPPUNIT_TEST_SUITE_END();
+
+ public:
+ RawXMLPayloadParserTest() {}
+
+ void testParse() {
+ RawXMLPayloadParser testling;
+ PayloadParserTester parser(&testling);
+
+ String xml =
+ "<foo foo-attr=\"foo-val\" xmlns=\"foo-ns\">"
+ "<bar bar-attr=\"bar-val\" xmlns=\"bar-ns\"/>"
+ "<baz baz-attr=\"baz-val\" xmlns=\"baz-ns\"/>"
+ "</foo>";
+ CPPUNIT_ASSERT(parser.parse(xml));
+
+ RawXMLPayload* payload = dynamic_cast<RawXMLPayload*>(testling.getPayload().get());
+ CPPUNIT_ASSERT_EQUAL(xml, payload->getRawXML());
+ }
+};
+
+CPPUNIT_TEST_SUITE_REGISTRATION(RawXMLPayloadParserTest);
diff --git a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
index 0f66b35..6a24008 100644
--- a/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
+++ b/Swiften/Serializer/PayloadSerializers/FullPayloadSerializerCollection.cpp
@@ -17,6 +17,7 @@
#include "Swiften/Serializer/PayloadSerializers/SecurityLabelsCatalogSerializer.h"
#include "Swiften/Serializer/PayloadSerializers/VCardSerializer.h"
#include "Swiften/Serializer/PayloadSerializers/VCardUpdateSerializer.h"
+#include "Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h"
namespace Swift {
@@ -37,6 +38,7 @@ FullPayloadSerializerCollection::FullPayloadSerializerCollection() {
serializers_.push_back(new SecurityLabelsCatalogSerializer());
serializers_.push_back(new VCardSerializer());
serializers_.push_back(new VCardUpdateSerializer());
+ serializers_.push_back(new RawXMLPayloadSerializer());
foreach(PayloadSerializer* serializer, serializers_) {
addSerializer(serializer);
}
diff --git a/Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h b/Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h
new file mode 100644
index 0000000..f980174
--- /dev/null
+++ b/Swiften/Serializer/PayloadSerializers/RawXMLPayloadSerializer.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include "Swiften/Serializer/GenericPayloadSerializer.h"
+#include "Swiften/Elements/RawXMLPayload.h"
+
+namespace Swift {
+ class RawXMLPayloadSerializer : public GenericPayloadSerializer<RawXMLPayload> {
+ public:
+ RawXMLPayloadSerializer() : GenericPayloadSerializer<RawXMLPayload>() {}
+
+ virtual String serializePayload(boost::shared_ptr<RawXMLPayload> p) const {
+ return p->getRawXML();
+ }
+ };
+}