Changeset - 7c90087b1774
include/Swiften/Elements/PubSubItem.cpp
Show inline comments
 
@@ -5,10 +5,10 @@
 
 */
 

	
 
#include <Swiften/Elements/PubSubItem.h>
 

	
 
namespace Swift {
 

	
 
PubSubItem::PubSubItem(const std::string &body) : body_(body) {
 
PubSubItem::PubSubItem() {
 
}
 

	
 
}
include/Swiften/Elements/PubSubItem.h
Show inline comments
 
@@ -11,25 +11,54 @@
 
#include <string>
 
#include <Swiften/Elements/Payload.h>
 

	
 
namespace Swift {
 
	class PubSubItem : public Payload {
 
		public:
 
			PubSubItem(const std::string &body = "");
 
			PubSubItem();
 

	
 
			const std::string& getData() const { return body_; }
 
			void addPayload(boost::shared_ptr<Payload> payload) {
 
				payloads.push_back(payload);
 
			}
 

	
 
			const std::vector<boost::shared_ptr<Payload> > getPayloads() const {
 
				return payloads;
 
			}
 
			
 
			template<typename T>
 
			const std::vector<boost::shared_ptr<T> > getPayloads() const {
 
				std::vector<boost::shared_ptr<T> > matched_payloads;
 
				for (std::vector<boost::shared_ptr<Payload> >::const_iterator i = payloads.begin(); i != payloads.end(); ++i) {
 
					boost::shared_ptr<T> result = boost::dynamic_pointer_cast<T>(*i);
 
					if (result) {
 
						matched_payloads.push_back(result);
 
					}
 
				}
 
				
 
				return matched_payloads;
 
				
 
			}
 

	
 
			void setData(const std::string& body) { 
 
				body_ = body;
 
			template<typename T>
 
			const boost::shared_ptr<T> getPayload() const {
 
				boost::shared_ptr<T> result;
 
				for (std::vector<boost::shared_ptr<Payload> >::const_iterator i = payloads.begin(); i != payloads.end(); ++i) {
 
					result = boost::dynamic_pointer_cast<T>(*i);
 
					if (result) {
 
						return result;
 
					}
 
				}
 
				
 
				return result;
 
			}
 

	
 
			const std::string& getId() const { return id; }
 

	
 
			void setId(const std::string& id) { 
 
				this->id = id;
 
			}
 

	
 
		private:
 
			std::string body_;
 
			std::vector<boost::shared_ptr<Payload> > payloads;
 
			std::string id;
 
	};
 
}
include/Swiften/Elements/PubSubPayload.h
Show inline comments
 
@@ -13,16 +13,20 @@
 

	
 
namespace Swift {
 
	class PubSubPayload : public Payload {
 
		public:
 
			PubSubPayload();
 

	
 
			void addPayload(boost::shared_ptr<Payload> payload) {
 
				payloads.push_back(payload);
 
			}
 

	
 
			const std::vector<boost::shared_ptr<Payload> > getPayloads() const {
 
				return payloads;
 
			}
 
			
 

	
 
			template<typename T>
 
			const std::vector<boost::shared_ptr<T> > getPayloads() const {
 
				std::vector<boost::shared_ptr<T> > matched_payloads;
 
				for (std::vector<boost::shared_ptr<Payload> >::const_iterator i = payloads.begin(); i != payloads.end(); ++i) {
 
					boost::shared_ptr<T> result = boost::dynamic_pointer_cast<T>(*i);
 
					if (result) {
include/Swiften/Elements/PubSubPublishPayload.h
Show inline comments
 
@@ -25,19 +25,19 @@ namespace Swift {
 
			}
 

	
 
			const std::string &getNode() const {
 
				return node;
 
			}
 

	
 
			void addItem(const boost::shared_ptr<PubSubItem> &item) {
 
			void addItem(const boost::shared_ptr<Payload> &item) {
 
				items.push_back(item);
 
			}
 

	
 
			const std::vector<boost::shared_ptr<PubSubItem> > &getItems() const {
 
			const std::vector<boost::shared_ptr<Payload> > &getItems() const {
 
				return items;
 
			}
 

	
 
		private:
 
			std::string node;
 
			std::vector<boost::shared_ptr<PubSubItem> > items;
 
			std::vector<boost::shared_ptr<Payload> > items;
 
	};
 
}
include/Swiften/Elements/PubSubSubscribePayload.h
Show inline comments
 
@@ -12,13 +12,13 @@
 
#include <Swiften/Elements/Payload.h>
 
#include <Swiften/JID/JID.h>
 

	
 
namespace Swift {
 
	class PubSubSubscribePayload : public Payload {
 
		public:
 
			PubSubSubscribePayload(const JID &jid, const std::string &node = "");
 
			PubSubSubscribePayload(const JID &jid = JID(), const std::string &node = "");
 

	
 
			void setJID(const JID &jid) {
 
				this->jid = jid;
 
			}
 

	
 
			const JID &getJID() const {
include/Swiften/Elements/PubSubSubscriptionPayload.h
Show inline comments
 
@@ -14,13 +14,13 @@
 

	
 
namespace Swift {
 
	class PubSubSubscriptionPayload : public Payload {
 
		public:
 
			enum Type { None, Pending, Subscribed, Unconfigured };
 

	
 
			PubSubSubscriptionPayload(const JID &jid, const std::string &node = "");
 
			PubSubSubscriptionPayload(const JID &jid = JID(), const std::string &node = "");
 

	
 
			void setJID(const JID &jid) {
 
				this->jid = jid;
 
			}
 

	
 
			const JID &getJID() const {
include/Swiften/Parser/PayloadParsers/PubSubItemParser.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2012 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Parser/PayloadParsers/PubSubItemParser.h>
 

	
 
#include <boost/lexical_cast.hpp>
 

	
 
#include <Swiften/Parser/PayloadParserFactoryCollection.h>
 
#include <Swiften/Parser/PayloadParserFactory.h>
 
#include <Swiften/Base/foreach.h>
 
#include <Swiften/Elements/MUCOccupant.h>
 
#include <Swiften/Parser/Tree/TreeReparser.h>
 

	
 
namespace Swift {
 

	
 
void PubSubItemParser::handleTree(ParserElement::ref root) {
 
	std::string id = root->getAttributes().getAttribute("id");
 
	if (!id.empty()) {
 
		getPayloadInternal()->setId(id);
 
	}
 

	
 
	foreach (ParserElement::ref child, root->getAllChildren()) {
 
		getPayloadInternal()->addPayload(TreeReparser::parseTree(child, factories));
 
	}
 
}
 

	
 
}
include/Swiften/Parser/PayloadParsers/PubSubItemParser.h
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2012 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#pragma once
 

	
 
#include <boost/optional.hpp>
 

	
 
#include <Swiften/Elements/PubSubItem.h>
 
#include <Swiften/Parser/GenericPayloadTreeParser.h>
 
#include <Swiften/Parser/PayloadParsers/MUCItemParser.h>
 

	
 
namespace Swift {
 
	class PayloadParserFactoryCollection;
 
	class PubSubItemParser : public GenericPayloadTreeParser<PubSubItem> {
 
		public:
 
			PubSubItemParser(PayloadParserFactoryCollection* collection) : factories(collection) {}
 
			virtual void handleTree(ParserElement::ref root);
 
		private:
 
			PayloadParserFactoryCollection* factories;
 
	};
 
}
include/Swiften/Parser/PayloadParsers/PubSubPayloadParser.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2012 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Parser/PayloadParsers/PubSubPayloadParser.h>
 

	
 
#include <boost/lexical_cast.hpp>
 

	
 
#include <Swiften/Parser/PayloadParserFactoryCollection.h>
 
#include <Swiften/Parser/PayloadParserFactory.h>
 
#include <Swiften/Base/foreach.h>
 
#include <Swiften/Elements/MUCOccupant.h>
 
#include <Swiften/Parser/Tree/TreeReparser.h>
 

	
 
namespace Swift {
 

	
 
void PubSubPayloadParser::handleTree(ParserElement::ref root) {
 
	foreach (ParserElement::ref child, root->getAllChildren()) {
 
		getPayloadInternal()->addPayload(TreeReparser::parseTree(child, factories));
 
	}
 
}
 

	
 
}
include/Swiften/Parser/PayloadParsers/PubSubPayloadParser.h
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2012 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#pragma once
 

	
 
#include <boost/optional.hpp>
 

	
 
#include <Swiften/Elements/PubSubPayload.h>
 
#include <Swiften/Parser/GenericPayloadTreeParser.h>
 
#include <Swiften/Parser/PayloadParsers/MUCItemParser.h>
 

	
 
namespace Swift {
 
	class PayloadParserFactoryCollection;
 
	class PubSubPayloadParser : public GenericPayloadTreeParser<PubSubPayload> {
 
		public:
 
			PubSubPayloadParser(PayloadParserFactoryCollection* collection) : factories(collection) {}
 
			virtual void handleTree(ParserElement::ref root);
 
		private:
 
			PayloadParserFactoryCollection* factories;
 
	};
 
}
include/Swiften/Parser/PayloadParsers/PubSubPublishPayloadParser.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2012 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Parser/PayloadParsers/PubSubPublishPayloadParser.h>
 

	
 
#include <boost/lexical_cast.hpp>
 

	
 
#include <Swiften/Parser/PayloadParserFactoryCollection.h>
 
#include <Swiften/Parser/PayloadParserFactory.h>
 
#include <Swiften/Base/foreach.h>
 
#include <Swiften/Elements/MUCOccupant.h>
 
#include <Swiften/Parser/Tree/TreeReparser.h>
 

	
 
namespace Swift {
 

	
 
void PubSubPublishPayloadParser::handleTree(ParserElement::ref root) {
 
	std::string node = root->getAttributes().getAttribute("node");
 
	if (!node.empty()) {
 
		getPayloadInternal()->setNode(node);
 
	}
 

	
 
	foreach (ParserElement::ref child, root->getAllChildren()) {
 
		getPayloadInternal()->addItem(TreeReparser::parseTree(child, factories));
 
	}
 
}
 

	
 
}
include/Swiften/Parser/PayloadParsers/PubSubPublishPayloadParser.h
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2012 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#pragma once
 

	
 
#include <boost/optional.hpp>
 

	
 
#include <Swiften/Elements/PubSubPublishPayload.h>
 
#include <Swiften/Parser/GenericPayloadTreeParser.h>
 
#include <Swiften/Parser/PayloadParsers/MUCItemParser.h>
 

	
 
namespace Swift {
 
	class PayloadParserFactoryCollection;
 
	class PubSubPublishPayloadParser : public GenericPayloadTreeParser<PubSubPublishPayload> {
 
		public:
 
			PubSubPublishPayloadParser(PayloadParserFactoryCollection* collection) : factories(collection) {}
 
			virtual void handleTree(ParserElement::ref root);
 
		private:
 
			PayloadParserFactoryCollection* factories;
 
	};
 
}
include/Swiften/Parser/PayloadParsers/PubSubSubscribePayloadParser.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2012 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Parser/PayloadParsers/PubSubSubscribePayloadParser.h>
 

	
 
#include <boost/lexical_cast.hpp>
 

	
 
#include <Swiften/Parser/PayloadParserFactoryCollection.h>
 
#include <Swiften/Parser/PayloadParserFactory.h>
 
#include <Swiften/Base/foreach.h>
 
#include <Swiften/Elements/MUCOccupant.h>
 
#include <Swiften/Parser/Tree/TreeReparser.h>
 

	
 
namespace Swift {
 

	
 
void PubSubSubscribePayloadParser::handleTree(ParserElement::ref root) {
 
	std::string node = root->getAttributes().getAttribute("node");
 
	if (!node.empty()) {
 
		getPayloadInternal()->setNode(node);
 
	}
 

	
 
	std::string jid = root->getAttributes().getAttribute("jid");
 
	if (!jid.empty()) {
 
		getPayloadInternal()->setJID(jid);
 
	}
 

	
 
}
 

	
 
}
include/Swiften/Parser/PayloadParsers/PubSubSubscribePayloadParser.h
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2012 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#pragma once
 

	
 
#include <boost/optional.hpp>
 

	
 
#include <Swiften/Elements/PubSubSubscribePayload.h>
 
#include <Swiften/Parser/GenericPayloadTreeParser.h>
 
#include <Swiften/Parser/PayloadParsers/MUCItemParser.h>
 

	
 
namespace Swift {
 
	class PayloadParserFactoryCollection;
 
	class PubSubSubscribePayloadParser : public GenericPayloadTreeParser<PubSubSubscribePayload> {
 
		public:
 
			PubSubSubscribePayloadParser(PayloadParserFactoryCollection* collection) : factories(collection) {}
 
			virtual void handleTree(ParserElement::ref root);
 
		private:
 
			PayloadParserFactoryCollection* factories;
 
	};
 
}
include/Swiften/Parser/PayloadParsers/PubSubSubscriptionPayloadParser.cpp
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2012 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#include <Swiften/Parser/PayloadParsers/PubSubSubscriptionPayloadParser.h>
 

	
 
#include <boost/lexical_cast.hpp>
 

	
 
#include <Swiften/Parser/PayloadParserFactoryCollection.h>
 
#include <Swiften/Parser/PayloadParserFactory.h>
 
#include <Swiften/Base/foreach.h>
 
#include <Swiften/Elements/MUCOccupant.h>
 
#include <Swiften/Parser/Tree/TreeReparser.h>
 

	
 
namespace Swift {
 

	
 
void PubSubSubscriptionPayloadParser::handleTree(ParserElement::ref root) {
 
	std::string node = root->getAttributes().getAttribute("node");
 
	if (!node.empty()) {
 
		getPayloadInternal()->setNode(node);
 
	}
 

	
 
	std::string jid = root->getAttributes().getAttribute("jid");
 
	if (!jid.empty()) {
 
		getPayloadInternal()->setJID(jid);
 
	}
 

	
 
	std::string id = root->getAttributes().getAttribute("subid");
 
	if (!id.empty()) {
 
		getPayloadInternal()->setId(id);
 
	}
 

	
 
	std::string type = root->getAttributes().getAttribute("subscription");
 
	if (type == "none") {
 
		getPayloadInternal()->setType(PubSubSubscriptionPayload::None);
 
	}
 
	else if (type == "subscribed") {
 
		getPayloadInternal()->setType(PubSubSubscriptionPayload::Subscribed);
 
	}
 
	else if (type == "pending") {
 
		getPayloadInternal()->setType(PubSubSubscriptionPayload::Pending);
 
	}
 
	else if (type == "unconfigured") {
 
		getPayloadInternal()->setType(PubSubSubscriptionPayload::Unconfigured);
 
	}
 

	
 
}
 

	
 
}
include/Swiften/Parser/PayloadParsers/PubSubSubscriptionPayloadParser.h
Show inline comments
 
new file 100644
 
/*
 
 * Copyright (c) 2012 Jan Kaluza
 
 * Licensed under the Simplified BSD license.
 
 * See Documentation/Licenses/BSD-simplified.txt for more information.
 
 */
 

	
 
#pragma once
 

	
 
#include <boost/optional.hpp>
 

	
 
#include <Swiften/Elements/PubSubSubscriptionPayload.h>
 
#include <Swiften/Parser/GenericPayloadTreeParser.h>
 
#include <Swiften/Parser/PayloadParsers/MUCItemParser.h>
 

	
 
namespace Swift {
 
	class PayloadParserFactoryCollection;
 
	class PubSubSubscriptionPayloadParser : public GenericPayloadTreeParser<PubSubSubscriptionPayload> {
 
		public:
 
			PubSubSubscriptionPayloadParser(PayloadParserFactoryCollection* collection) : factories(collection) {}
 
			virtual void handleTree(ParserElement::ref root);
 
		private:
 
			PayloadParserFactoryCollection* factories;
 
	};
 
}
include/Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.cpp
Show inline comments
 
@@ -6,26 +6,33 @@
 

	
 
#include <Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.h>
 
#include <Swiften/Base/foreach.h>
 
#include <Swiften/Serializer/XML/XMLRawTextNode.h>
 
#include <Swiften/Serializer/XML/XMLTextNode.h>
 
#include <Swiften/Serializer/XML/XMLElement.h>
 
#include <Swiften/Serializer/PayloadSerializerCollection.h>
 

	
 
namespace Swift {
 

	
 
PubSubItemSerializer::PubSubItemSerializer() : GenericPayloadSerializer<PubSubItem>() {
 
PubSubItemSerializer::PubSubItemSerializer(PayloadSerializerCollection *serializers) : 
 
	GenericPayloadSerializer<PubSubItem>(), serializers(serializers) {
 
}
 

	
 
std::string PubSubItemSerializer::serializePayload(boost::shared_ptr<PubSubItem> payload)  const {
 
	XMLElement item("item");
 
	if (!payload->getId().empty()) {
 
		item.setAttribute("id", payload->getId());
 
	}
 

	
 
	boost::shared_ptr<XMLElement> body(new XMLElement("body", "http://www.w3.org/1999/xhtml"));
 
	body->addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(payload->getData())));
 
	item.addNode(body);
 
	if (!payload->getPayloads().empty()) {		
 
		foreach(boost::shared_ptr<Payload> subPayload, payload->getPayloads()) {
 
			PayloadSerializer* serializer = serializers->getPayloadSerializer(subPayload);
 
			if (serializer) {
 
				item.addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(serializer->serialize(subPayload))));
 
			}
 
		}
 
	}
 

	
 
	return item.serialize();
 
}
 

	
 
}
include/Swiften/Serializer/PayloadSerializers/PubSubItemSerializer.h
Show inline comments
 
@@ -7,13 +7,16 @@
 
#pragma once
 

	
 
#include <Swiften/Serializer/GenericPayloadSerializer.h>
 
#include <Swiften/Elements/PubSubItem.h>
 

	
 
namespace Swift {
 
	class PayloadSerializerCollection;
 
	class PubSubItemSerializer : public GenericPayloadSerializer<PubSubItem> {
 
		public:
 
			PubSubItemSerializer();
 
			PubSubItemSerializer(PayloadSerializerCollection *serializers);
 

	
 
			virtual std::string serializePayload(boost::shared_ptr<PubSubItem> item)  const;
 
		private:
 
			PayloadSerializerCollection *serializers;
 
	};
 
}
include/Swiften/Serializer/PayloadSerializers/PubSubPublishPayloadSerializer.cpp
Show inline comments
 
@@ -23,13 +23,13 @@ std::string PubSubPublishPayloadSerializer::serializePayload(boost::shared_ptr<P
 

	
 
	if (!payload->getNode().empty()) {
 
		publish.setAttribute("node", payload->getNode());
 
	}
 

	
 
	if (!payload->getItems().empty()) {		
 
		foreach(boost::shared_ptr<PubSubItem> subPayload, payload->getItems()) {
 
		foreach(boost::shared_ptr<Payload> subPayload, payload->getItems()) {
 
			PayloadSerializer* serializer = serializers->getPayloadSerializer(subPayload);
 
			if (serializer) {
 
				publish.addNode(boost::shared_ptr<XMLRawTextNode>(new XMLRawTextNode(serializer->serialize(subPayload))));
 
			}
 
		}
 
	}
0 comments (0 inline, 0 general)