From a511087b1f57f1f6372374f41d0b4b7ebeef9930 Mon Sep 17 00:00:00 2001 From: Richard Maudsley Date: Tue, 4 Feb 2014 09:49:24 +0000 Subject: PubSub parsers and serializers, plus manager and test code. Change-Id: Ie8ca77ba8dbcd83926d46307ad0e73d804ff7422 diff --git a/.gitignore b/.gitignore index d1c3d14..3ca142c 100644 --- a/.gitignore +++ b/.gitignore @@ -12,4 +12,5 @@ isode/configure test-results/ third-party/ *.patch -.DS_Store \ No newline at end of file +.DS_Store +/bin diff --git a/src/com/isode/stroke/client/Client.java b/src/com/isode/stroke/client/Client.java index a4ef619..4f5d6c7 100644 --- a/src/com/isode/stroke/client/Client.java +++ b/src/com/isode/stroke/client/Client.java @@ -14,6 +14,8 @@ import com.isode.stroke.muc.MUCRegistry; import com.isode.stroke.network.NetworkFactories; import com.isode.stroke.presence.DirectedPresenceSender; import com.isode.stroke.presence.StanzaChannelPresenceSender; +import com.isode.stroke.pubsub.PubSubManager; +import com.isode.stroke.pubsub.PubSubManagerImpl; import com.isode.stroke.queries.responders.SoftwareVersionResponder; /** @@ -30,6 +32,7 @@ public class Client extends CoreClient { private final DirectedPresenceSender directedPresenceSender; //NOPMD, this is not better as a local variable private final StanzaChannelPresenceSender stanzaChannelPresenceSender; //NOPMD, this is not better as a local variable private final SoftwareVersionResponder softwareVersionResponder; + private final PubSubManager pubSubManager; /** * Constructor. @@ -57,6 +60,8 @@ public class Client extends CoreClient { softwareVersionResponder = new SoftwareVersionResponder(getIQRouter()); softwareVersionResponder.start(); + + pubSubManager = new PubSubManagerImpl(getStanzaChannel(), getIQRouter()); } /** @@ -75,6 +80,14 @@ public class Client extends CoreClient { return mucRegistry; } + /** + * Get the manager for publish-subscribe + * @return PubSub manager, not null + */ + public PubSubManager getPubSubManager() { + return pubSubManager; + } + /** * Sets the software version of the client. * diff --git a/src/com/isode/stroke/elements/ContainerPayload.java b/src/com/isode/stroke/elements/ContainerPayload.java new file mode 100644 index 0000000..16134d0 --- /dev/null +++ b/src/com/isode/stroke/elements/ContainerPayload.java @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +public class ContainerPayload extends Payload { + public ContainerPayload() { + } + + public ContainerPayload(T payload) { + payload_ = payload; + } + + public void setPayload(T payload) { + payload_ = payload; + } + + public T getPayload() { + return payload_; + } + + T payload_; +} diff --git a/src/com/isode/stroke/elements/PubSub.java b/src/com/isode/stroke/elements/PubSub.java new file mode 100644 index 0000000..8a317bd --- /dev/null +++ b/src/com/isode/stroke/elements/PubSub.java @@ -0,0 +1,14 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +public class PubSub extends ContainerPayload { + +} diff --git a/src/com/isode/stroke/elements/PubSubAffiliation.java b/src/com/isode/stroke/elements/PubSubAffiliation.java new file mode 100644 index 0000000..f6f74de --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubAffiliation.java @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.Payload; + +public class PubSubAffiliation extends Payload { +public enum Type +{ + None, + Member, + Outcast, + Owner, + Publisher, + PublishOnly +} + +public PubSubAffiliation() { +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +public Type getType() { + return type_; +} + +public void setType(Type type) { + type_ = type; +} + +String node_; +Type type_; + +} diff --git a/src/com/isode/stroke/elements/PubSubAffiliations.java b/src/com/isode/stroke/elements/PubSubAffiliations.java new file mode 100644 index 0000000..883f078 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubAffiliations.java @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import java.util.ArrayList; +import com.isode.stroke.elements.PubSubPayload; + +public class PubSubAffiliations extends PubSubPayload { + +public PubSubAffiliations() { +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +public ArrayList getAffiliations() { + return affiliations_; +} + +public void setAffiliations(ArrayList affiliations) { + affiliations_ = affiliations; +} + +public void addAffiliation(PubSubAffiliation value) { + affiliations_.add(value); +} + +String node_; +ArrayList affiliations_ = new ArrayList(); + +} diff --git a/src/com/isode/stroke/elements/PubSubConfigure.java b/src/com/isode/stroke/elements/PubSubConfigure.java new file mode 100644 index 0000000..2b54374 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubConfigure.java @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.Form; +import com.isode.stroke.elements.Payload; + +public class PubSubConfigure extends Payload { + +public PubSubConfigure() { +} + +public Form getData() { + return data_; +} + +public void setData(Form data) { + data_ = data; +} + +Form data_; + +} diff --git a/src/com/isode/stroke/elements/PubSubCreate.java b/src/com/isode/stroke/elements/PubSubCreate.java new file mode 100644 index 0000000..e1ac6c0 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubCreate.java @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.PubSubPayload; + +public class PubSubCreate extends PubSubPayload { + +public PubSubCreate() { +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +public PubSubConfigure getConfigure() { + return configure_; +} + +public void setConfigure(PubSubConfigure configure) { + configure_ = configure; +} + +String node_; +PubSubConfigure configure_; + +} diff --git a/src/com/isode/stroke/elements/PubSubDefault.java b/src/com/isode/stroke/elements/PubSubDefault.java new file mode 100644 index 0000000..f5b075a --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubDefault.java @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.PubSubPayload; + +public class PubSubDefault extends PubSubPayload { +public enum Type +{ + None, + Collection, + Leaf +} + +public PubSubDefault() { +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +public Type getType() { + return type_; +} + +public void setType(Type type) { + type_ = type; +} + +String node_; +Type type_; + +} diff --git a/src/com/isode/stroke/elements/PubSubError.java b/src/com/isode/stroke/elements/PubSubError.java new file mode 100644 index 0000000..cd6aadf --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubError.java @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2014, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2014, Remko Tronçon. + * All rights reserved. + */ + +package com.isode.stroke.elements; + +public class PubSubError extends Payload { + public enum Type { + UnknownType, + ClosedNode, + ConfigurationRequired, + InvalidJID, + InvalidOptions, + InvalidPayload, + InvalidSubscriptionID, + ItemForbidden, + ItemRequired, + JIDRequired, + MaximumItemsExceeded, + MaximumNodesExceeded, + NodeIDRequired, + NotInRosterGroup, + NotSubscribed, + PayloadTooBig, + PayloadRequired, + PendingSubscription, + PresenceSubscriptionRequired, + SubscriptionIDRequired, + TooManySubscriptions, + Unsupported, + UnsupportedAccessModel + }; + + public enum UnsupportedFeatureType { + UnknownUnsupportedFeatureType, + AccessAuthorize, + AccessOpen, + AccessPresence, + AccessRoster, + AccessWhitelist, + AutoCreate, + AutoSubscribe, + Collections, + ConfigNode, + CreateAndConfigure, + CreateNodes, + DeleteItems, + DeleteNodes, + FilteredNotifications, + GetPending, + InstantNodes, + ItemIDs, + LastPublished, + LeasedSubscription, + ManageSubscriptions, + MemberAffiliation, + MetaData, + ModifyAffiliations, + MultiCollection, + MultiSubscribe, + OutcastAffiliation, + PersistentItems, + PresenceNotifications, + PresenceSubscribe, + Publish, + PublishOptions, + PublishOnlyAffiliation, + PublisherAffiliation, + PurgeNodes, + RetractItems, + RetrieveAffiliations, + RetrieveDefault, + RetrieveItems, + RetrieveSubscriptions, + Subscribe, + SubscriptionOptions, + SubscriptionNotifications + }; + + public PubSubError(Type type) { + type_ = Type.UnknownType; + unsupportedType_ = UnsupportedFeatureType.UnknownUnsupportedFeatureType; + } + + public Type getType() { + return type_; + } + + public void setType(Type type) { + type_ = type; + } + + public UnsupportedFeatureType getUnsupportedFeatureType() { + return unsupportedType_; + } + + public void setUnsupportedFeatureType(UnsupportedFeatureType unsupportedType) { + unsupportedType_ = unsupportedType; + } + + Type type_; + UnsupportedFeatureType unsupportedType_; +} diff --git a/src/com/isode/stroke/elements/PubSubEventAssociate.java b/src/com/isode/stroke/elements/PubSubEventAssociate.java new file mode 100644 index 0000000..0ba4204 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubEventAssociate.java @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.Payload; + +public class PubSubEventAssociate extends Payload { + +public PubSubEventAssociate() { +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +String node_; + +} diff --git a/src/com/isode/stroke/elements/PubSubEventCollection.java b/src/com/isode/stroke/elements/PubSubEventCollection.java new file mode 100644 index 0000000..95a7119 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubEventCollection.java @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.PubSubEventPayload; + +public class PubSubEventCollection extends PubSubEventPayload { + +public PubSubEventCollection() { +} + +public PubSubEventAssociate getAssociate() { + return associate_; +} + +public void setAssociate(PubSubEventAssociate associate) { + associate_ = associate; +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +public PubSubEventDisassociate getDisassociate() { + return disassociate_; +} + +public void setDisassociate(PubSubEventDisassociate disassociate) { + disassociate_ = disassociate; +} + +PubSubEventAssociate associate_; +String node_; +PubSubEventDisassociate disassociate_; + +} diff --git a/src/com/isode/stroke/elements/PubSubEventConfiguration.java b/src/com/isode/stroke/elements/PubSubEventConfiguration.java new file mode 100644 index 0000000..0d13daa --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubEventConfiguration.java @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.Form; +import com.isode.stroke.elements.PubSubEventPayload; + +public class PubSubEventConfiguration extends PubSubEventPayload { + +public PubSubEventConfiguration() { +} + +public Form getData() { + return data_; +} + +public void setData(Form data) { + data_ = data; +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +Form data_; +String node_; + +} diff --git a/src/com/isode/stroke/elements/PubSubEventDelete.java b/src/com/isode/stroke/elements/PubSubEventDelete.java new file mode 100644 index 0000000..5c6418d --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubEventDelete.java @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.PubSubEventPayload; + +public class PubSubEventDelete extends PubSubEventPayload { + +public PubSubEventDelete() { +} + +public PubSubEventRedirect getRedirects() { + return redirects_; +} + +public void setRedirects(PubSubEventRedirect redirects) { + redirects_ = redirects; +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +PubSubEventRedirect redirects_; +String node_; + +} diff --git a/src/com/isode/stroke/elements/PubSubEventDisassociate.java b/src/com/isode/stroke/elements/PubSubEventDisassociate.java new file mode 100644 index 0000000..d6fcb97 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubEventDisassociate.java @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.Payload; + +public class PubSubEventDisassociate extends Payload { + +public PubSubEventDisassociate() { +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +String node_; + +} diff --git a/src/com/isode/stroke/elements/PubSubEventItem.java b/src/com/isode/stroke/elements/PubSubEventItem.java new file mode 100644 index 0000000..2086106 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubEventItem.java @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import java.util.ArrayList; +import com.isode.stroke.elements.Payload; + +public class PubSubEventItem extends Payload { + +public PubSubEventItem() { +} + +public String getPublisher() { + return publisher_; +} + +public void setPublisher(String publisher) { + publisher_ = publisher; +} + +public ArrayList getData() { + return data_; +} + +public void setData(ArrayList data) { + data_ = data; +} + +public void addData(Payload value) { + data_.add(value); +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +public String getID() { + return id_; +} + +public void setID(String id) { + id_ = id; +} + +String publisher_; +ArrayList data_ = new ArrayList(); +String node_; +String id_; + +} diff --git a/src/com/isode/stroke/elements/PubSubEventItems.java b/src/com/isode/stroke/elements/PubSubEventItems.java new file mode 100644 index 0000000..f4865ff --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubEventItems.java @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import java.util.ArrayList; +import com.isode.stroke.elements.PubSubEventPayload; + +public class PubSubEventItems extends PubSubEventPayload { + +public PubSubEventItems() { +} + +public ArrayList getItems() { + return items_; +} + +public void setItems(ArrayList items) { + items_ = items; +} + +public void addItem(PubSubEventItem value) { + items_.add(value); +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +public ArrayList getRetracts() { + return retracts_; +} + +public void setRetracts(ArrayList retracts) { + retracts_ = retracts; +} + +public void addRetract(PubSubEventRetract value) { + retracts_.add(value); +} + +ArrayList items_ = new ArrayList(); +String node_; +ArrayList retracts_ = new ArrayList(); + +} diff --git a/src/com/isode/stroke/elements/PubSubEventPayload.java b/src/com/isode/stroke/elements/PubSubEventPayload.java new file mode 100644 index 0000000..d101c6c --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubEventPayload.java @@ -0,0 +1,14 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +public class PubSubEventPayload extends Payload { + +} diff --git a/src/com/isode/stroke/elements/PubSubEventPurge.java b/src/com/isode/stroke/elements/PubSubEventPurge.java new file mode 100644 index 0000000..451ce09 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubEventPurge.java @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.PubSubEventPayload; + +public class PubSubEventPurge extends PubSubEventPayload { + +public PubSubEventPurge() { +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +String node_; + +} diff --git a/src/com/isode/stroke/elements/PubSubEventRedirect.java b/src/com/isode/stroke/elements/PubSubEventRedirect.java new file mode 100644 index 0000000..5f99b19 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubEventRedirect.java @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.Payload; + +public class PubSubEventRedirect extends Payload { + +public PubSubEventRedirect() { +} + +public String getURI() { + return uri_; +} + +public void setURI(String uri) { + uri_ = uri; +} + +String uri_; + +} diff --git a/src/com/isode/stroke/elements/PubSubEventRetract.java b/src/com/isode/stroke/elements/PubSubEventRetract.java new file mode 100644 index 0000000..4eba5ca --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubEventRetract.java @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.Payload; + +public class PubSubEventRetract extends Payload { + +public PubSubEventRetract() { +} + +public String getID() { + return id_; +} + +public void setID(String id) { + id_ = id; +} + +String id_; + +} diff --git a/src/com/isode/stroke/elements/PubSubEventSubscription.java b/src/com/isode/stroke/elements/PubSubEventSubscription.java new file mode 100644 index 0000000..7864a65 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubEventSubscription.java @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.jid.JID; +import java.util.Date; +import com.isode.stroke.elements.PubSubEventPayload; + +public class PubSubEventSubscription extends PubSubEventPayload { +public enum SubscriptionType +{ + None, + Pending, + Subscribed, + Unconfigured +} + +public PubSubEventSubscription() { +} + +public SubscriptionType getSubscription() { + return subscription_; +} + +public void setSubscription(SubscriptionType subscription) { + subscription_ = subscription; +} + +public String getSubscriptionID() { + return subscriptionID_; +} + +public void setSubscriptionID(String subscriptionID) { + subscriptionID_ = subscriptionID; +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +public JID getJID() { + return jid_; +} + +public void setJID(JID jid) { + jid_ = jid; +} + +public Date getExpiry() { + return expiry_; +} + +public void setExpiry(Date expiry) { + expiry_ = expiry; +} + +SubscriptionType subscription_; +String subscriptionID_; +String node_; +JID jid_; +Date expiry_; + +} diff --git a/src/com/isode/stroke/elements/PubSubItem.java b/src/com/isode/stroke/elements/PubSubItem.java new file mode 100644 index 0000000..91d0fe1 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubItem.java @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import java.util.ArrayList; +import com.isode.stroke.elements.Payload; + +public class PubSubItem extends Payload { + +public PubSubItem() { +} + +public ArrayList getData() { + return data_; +} + +public void setData(ArrayList data) { + data_ = data; +} + +public void addData(Payload value) { + data_.add(value); +} + +public String getID() { + return id_; +} + +public void setID(String id) { + id_ = id; +} + +ArrayList data_ = new ArrayList(); +String id_; + +} diff --git a/src/com/isode/stroke/elements/PubSubItems.java b/src/com/isode/stroke/elements/PubSubItems.java new file mode 100644 index 0000000..ae675e4 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubItems.java @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import java.util.ArrayList; +import com.isode.stroke.elements.PubSubPayload; + +public class PubSubItems extends PubSubPayload { + +public PubSubItems() { +} + +public Long getMaximumItems() { + return maximumItems_; +} + +public void setMaximumItems(Long maximumItems) { + maximumItems_ = maximumItems; +} + +public ArrayList getItems() { + return items_; +} + +public void setItems(ArrayList items) { + items_ = items; +} + +public void addItem(PubSubItem value) { + items_.add(value); +} + +public String getSubscriptionID() { + return subscriptionID_; +} + +public void setSubscriptionID(String subscriptionID) { + subscriptionID_ = subscriptionID; +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +Long maximumItems_; +ArrayList items_ = new ArrayList(); +String subscriptionID_; +String node_; + +} diff --git a/src/com/isode/stroke/elements/PubSubOptions.java b/src/com/isode/stroke/elements/PubSubOptions.java new file mode 100644 index 0000000..085baa7 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubOptions.java @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.Form; +import com.isode.stroke.jid.JID; +import com.isode.stroke.elements.PubSubPayload; + +public class PubSubOptions extends PubSubPayload { + +public PubSubOptions() { +} + +public Form getData() { + return data_; +} + +public void setData(Form data) { + data_ = data; +} + +public String getSubscriptionID() { + return subscriptionID_; +} + +public void setSubscriptionID(String subscriptionID) { + subscriptionID_ = subscriptionID; +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +public JID getJID() { + return jid_; +} + +public void setJID(JID jid) { + jid_ = jid; +} + +Form data_; +String subscriptionID_; +String node_; +JID jid_; + +} diff --git a/src/com/isode/stroke/elements/PubSubOwnerAffiliation.java b/src/com/isode/stroke/elements/PubSubOwnerAffiliation.java new file mode 100644 index 0000000..d08bd3d --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubOwnerAffiliation.java @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.jid.JID; +import com.isode.stroke.elements.Payload; + +public class PubSubOwnerAffiliation extends Payload { +public enum Type +{ + None, + Member, + Outcast, + Owner, + Publisher, + PublishOnly +} + +public PubSubOwnerAffiliation() { +} + +public JID getJID() { + return jid_; +} + +public void setJID(JID jid) { + jid_ = jid; +} + +public Type getType() { + return type_; +} + +public void setType(Type type) { + type_ = type; +} + +JID jid_; +Type type_; + +} diff --git a/src/com/isode/stroke/elements/PubSubOwnerAffiliations.java b/src/com/isode/stroke/elements/PubSubOwnerAffiliations.java new file mode 100644 index 0000000..25973f8 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubOwnerAffiliations.java @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import java.util.ArrayList; +import com.isode.stroke.elements.PubSubOwnerPayload; + +public class PubSubOwnerAffiliations extends PubSubOwnerPayload { + +public PubSubOwnerAffiliations() { +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +public ArrayList getAffiliations() { + return affiliations_; +} + +public void setAffiliations(ArrayList affiliations) { + affiliations_ = affiliations; +} + +public void addAffiliation(PubSubOwnerAffiliation value) { + affiliations_.add(value); +} + +String node_; +ArrayList affiliations_ = new ArrayList(); + +} diff --git a/src/com/isode/stroke/elements/PubSubOwnerConfigure.java b/src/com/isode/stroke/elements/PubSubOwnerConfigure.java new file mode 100644 index 0000000..2807039 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubOwnerConfigure.java @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.Form; +import com.isode.stroke.elements.PubSubOwnerPayload; + +public class PubSubOwnerConfigure extends PubSubOwnerPayload { + +public PubSubOwnerConfigure() { +} + +public Form getData() { + return data_; +} + +public void setData(Form data) { + data_ = data; +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +Form data_; +String node_; + +} diff --git a/src/com/isode/stroke/elements/PubSubOwnerDefault.java b/src/com/isode/stroke/elements/PubSubOwnerDefault.java new file mode 100644 index 0000000..5f9c179 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubOwnerDefault.java @@ -0,0 +1,30 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.Form; +import com.isode.stroke.elements.PubSubOwnerPayload; + +public class PubSubOwnerDefault extends PubSubOwnerPayload { + +public PubSubOwnerDefault() { +} + +public Form getData() { + return data_; +} + +public void setData(Form data) { + data_ = data; +} + +Form data_; + +} diff --git a/src/com/isode/stroke/elements/PubSubOwnerDelete.java b/src/com/isode/stroke/elements/PubSubOwnerDelete.java new file mode 100644 index 0000000..a791fad --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubOwnerDelete.java @@ -0,0 +1,38 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.PubSubOwnerPayload; + +public class PubSubOwnerDelete extends PubSubOwnerPayload { + +public PubSubOwnerDelete() { +} + +public PubSubOwnerRedirect getRedirect() { + return redirect_; +} + +public void setRedirect(PubSubOwnerRedirect redirect) { + redirect_ = redirect; +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +PubSubOwnerRedirect redirect_; +String node_; + +} diff --git a/src/com/isode/stroke/elements/PubSubOwnerPayload.java b/src/com/isode/stroke/elements/PubSubOwnerPayload.java new file mode 100644 index 0000000..50d3775 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubOwnerPayload.java @@ -0,0 +1,14 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +public class PubSubOwnerPayload extends Payload { + +} diff --git a/src/com/isode/stroke/elements/PubSubOwnerPubSub.java b/src/com/isode/stroke/elements/PubSubOwnerPubSub.java new file mode 100644 index 0000000..63fd592 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubOwnerPubSub.java @@ -0,0 +1,14 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +public class PubSubOwnerPubSub extends ContainerPayload { + +} diff --git a/src/com/isode/stroke/elements/PubSubOwnerPurge.java b/src/com/isode/stroke/elements/PubSubOwnerPurge.java new file mode 100644 index 0000000..0a9abc7 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubOwnerPurge.java @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.PubSubOwnerPayload; + +public class PubSubOwnerPurge extends PubSubOwnerPayload { + +public PubSubOwnerPurge() { +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +String node_; + +} diff --git a/src/com/isode/stroke/elements/PubSubOwnerRedirect.java b/src/com/isode/stroke/elements/PubSubOwnerRedirect.java new file mode 100644 index 0000000..c5bda3c --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubOwnerRedirect.java @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.Payload; + +public class PubSubOwnerRedirect extends Payload { + +public PubSubOwnerRedirect() { +} + +public String getURI() { + return uri_; +} + +public void setURI(String uri) { + uri_ = uri; +} + +String uri_; + +} diff --git a/src/com/isode/stroke/elements/PubSubOwnerSubscription.java b/src/com/isode/stroke/elements/PubSubOwnerSubscription.java new file mode 100644 index 0000000..2845ffc --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubOwnerSubscription.java @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.jid.JID; +import com.isode.stroke.elements.Payload; + +public class PubSubOwnerSubscription extends Payload { +public enum SubscriptionType +{ + None, + Pending, + Subscribed, + Unconfigured +} + +public PubSubOwnerSubscription() { +} + +public SubscriptionType getSubscription() { + return subscription_; +} + +public void setSubscription(SubscriptionType subscription) { + subscription_ = subscription; +} + +public JID getJID() { + return jid_; +} + +public void setJID(JID jid) { + jid_ = jid; +} + +SubscriptionType subscription_; +JID jid_; + +} diff --git a/src/com/isode/stroke/elements/PubSubOwnerSubscriptions.java b/src/com/isode/stroke/elements/PubSubOwnerSubscriptions.java new file mode 100644 index 0000000..bd84a2d --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubOwnerSubscriptions.java @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import java.util.ArrayList; +import com.isode.stroke.elements.PubSubOwnerPayload; + +public class PubSubOwnerSubscriptions extends PubSubOwnerPayload { + +public PubSubOwnerSubscriptions() { +} + +public ArrayList getSubscriptions() { + return subscriptions_; +} + +public void setSubscriptions(ArrayList subscriptions) { + subscriptions_ = subscriptions; +} + +public void addSubscription(PubSubOwnerSubscription value) { + subscriptions_.add(value); +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +ArrayList subscriptions_ = new ArrayList(); +String node_; + +} diff --git a/src/com/isode/stroke/elements/PubSubPayload.java b/src/com/isode/stroke/elements/PubSubPayload.java new file mode 100644 index 0000000..14d36b5 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubPayload.java @@ -0,0 +1,14 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +public class PubSubPayload extends Payload { + +} diff --git a/src/com/isode/stroke/elements/PubSubPublish.java b/src/com/isode/stroke/elements/PubSubPublish.java new file mode 100644 index 0000000..987ba83 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubPublish.java @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import java.util.ArrayList; +import com.isode.stroke.elements.PubSubPayload; + +public class PubSubPublish extends PubSubPayload { + +public PubSubPublish() { +} + +public ArrayList getItems() { + return items_; +} + +public void setItems(ArrayList items) { + items_ = items; +} + +public void addItem(PubSubItem value) { + items_.add(value); +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +ArrayList items_ = new ArrayList(); +String node_; + +} diff --git a/src/com/isode/stroke/elements/PubSubRetract.java b/src/com/isode/stroke/elements/PubSubRetract.java new file mode 100644 index 0000000..d8349ea --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubRetract.java @@ -0,0 +1,52 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import java.util.ArrayList; +import com.isode.stroke.elements.PubSubPayload; + +public class PubSubRetract extends PubSubPayload { + +public PubSubRetract() { +} + +public ArrayList getItems() { + return items_; +} + +public void setItems(ArrayList items) { + items_ = items; +} + +public void addItem(PubSubItem value) { + items_.add(value); +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +public boolean isNotify() { + return notify_; +} + +public void setNotify(boolean notify) { + notify_ = notify; +} + +ArrayList items_ = new ArrayList(); +String node_; +boolean notify_; + +} diff --git a/src/com/isode/stroke/elements/PubSubSubscribe.java b/src/com/isode/stroke/elements/PubSubSubscribe.java new file mode 100644 index 0000000..d822bd5 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubSubscribe.java @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.jid.JID; +import com.isode.stroke.elements.PubSubPayload; + +public class PubSubSubscribe extends PubSubPayload { + +public PubSubSubscribe() { +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +public JID getJID() { + return jid_; +} + +public void setJID(JID jid) { + jid_ = jid; +} + +public PubSubOptions getOptions() { + return options_; +} + +public void setOptions(PubSubOptions options) { + options_ = options; +} + +String node_; +JID jid_; +PubSubOptions options_; + +} diff --git a/src/com/isode/stroke/elements/PubSubSubscribeOptions.java b/src/com/isode/stroke/elements/PubSubSubscribeOptions.java new file mode 100644 index 0000000..54fd72e --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubSubscribeOptions.java @@ -0,0 +1,29 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.elements.Payload; + +public class PubSubSubscribeOptions extends Payload { + +public PubSubSubscribeOptions() { +} + +public boolean isRequired() { + return required_; +} + +public void setRequired(boolean required) { + required_ = required; +} + +boolean required_; + +} diff --git a/src/com/isode/stroke/elements/PubSubSubscription.java b/src/com/isode/stroke/elements/PubSubSubscription.java new file mode 100644 index 0000000..78d9c17 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubSubscription.java @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.jid.JID; +import com.isode.stroke.elements.PubSubPayload; + +public class PubSubSubscription extends PubSubPayload { +public enum SubscriptionType +{ + None, + Pending, + Subscribed, + Unconfigured +} + +public PubSubSubscription() { +} + +public SubscriptionType getSubscription() { + return subscription_; +} + +public void setSubscription(SubscriptionType subscription) { + subscription_ = subscription; +} + +public String getSubscriptionID() { + return subscriptionID_; +} + +public void setSubscriptionID(String subscriptionID) { + subscriptionID_ = subscriptionID; +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +public JID getJID() { + return jid_; +} + +public void setJID(JID jid) { + jid_ = jid; +} + +public PubSubSubscribeOptions getOptions() { + return options_; +} + +public void setOptions(PubSubSubscribeOptions options) { + options_ = options; +} + +SubscriptionType subscription_; +String subscriptionID_; +String node_; +JID jid_; +PubSubSubscribeOptions options_; + +} diff --git a/src/com/isode/stroke/elements/PubSubSubscriptions.java b/src/com/isode/stroke/elements/PubSubSubscriptions.java new file mode 100644 index 0000000..23bb223 --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubSubscriptions.java @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import java.util.ArrayList; +import com.isode.stroke.elements.PubSubPayload; + +public class PubSubSubscriptions extends PubSubPayload { + +public PubSubSubscriptions() { +} + +public ArrayList getSubscriptions() { + return subscriptions_; +} + +public void setSubscriptions(ArrayList subscriptions) { + subscriptions_ = subscriptions; +} + +public void addSubscription(PubSubSubscription value) { + subscriptions_.add(value); +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +ArrayList subscriptions_ = new ArrayList(); +String node_; + +} diff --git a/src/com/isode/stroke/elements/PubSubUnsubscribe.java b/src/com/isode/stroke/elements/PubSubUnsubscribe.java new file mode 100644 index 0000000..f8d1fae --- /dev/null +++ b/src/com/isode/stroke/elements/PubSubUnsubscribe.java @@ -0,0 +1,48 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.jid.JID; +import com.isode.stroke.elements.PubSubPayload; + +public class PubSubUnsubscribe extends PubSubPayload { + +public PubSubUnsubscribe() { +} + +public String getSubscriptionID() { + return subscriptionID_; +} + +public void setSubscriptionID(String subscriptionID) { + subscriptionID_ = subscriptionID; +} + +public String getNode() { + return node_; +} + +public void setNode(String node) { + node_ = node; +} + +public JID getJID() { + return jid_; +} + +public void setJID(JID jid) { + jid_ = jid; +} + +String subscriptionID_; +String node_; +JID jid_; + +} diff --git a/src/com/isode/stroke/parser/GenericPayloadParserFactory2.java b/src/com/isode/stroke/parser/GenericPayloadParserFactory2.java new file mode 100644 index 0000000..c7bb9d0 --- /dev/null +++ b/src/com/isode/stroke/parser/GenericPayloadParserFactory2.java @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser; + +import java.lang.reflect.InvocationTargetException; + +public class GenericPayloadParserFactory2 implements PayloadParserFactory { + + /** + * Construct a parser factory that can parse the given top-level tag in the given namespace. + */ + public GenericPayloadParserFactory2(String tag, String xmlns, PayloadParserFactoryCollection parsers, final Class payloadClass) { + class_ = payloadClass; + tag_ = tag; + xmlns_ = xmlns; + parsers_ = parsers; + } + + public boolean canParse(String element, String ns, AttributeMap attributes) { + return (tag_.isEmpty() ? true : element == tag_) && (xmlns_.isEmpty() ? true : xmlns_ == ns); + } + + public PayloadParser createPayloadParser() { + try { + return (PayloadParser)class_.getConstructor(PayloadParserFactoryCollection.class).newInstance(parsers_); + } catch (InstantiationException e) { + + } catch (IllegalAccessException e) { + + } catch (IllegalArgumentException e) { + + } catch (InvocationTargetException e) { + + } catch (NoSuchMethodException e) { + + } catch (SecurityException e) { + + } + return null; + } + + String tag_; + String xmlns_; + PayloadParserFactoryCollection parsers_; + Class class_; +} diff --git a/src/com/isode/stroke/parser/PubSubOwnerPubSubParser.java b/src/com/isode/stroke/parser/PubSubOwnerPubSubParser.java new file mode 100644 index 0000000..ac0c4fe --- /dev/null +++ b/src/com/isode/stroke/parser/PubSubOwnerPubSubParser.java @@ -0,0 +1,95 @@ +/* + * Copyright (c) 2014, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2014, Remko Tronçon. + * All rights reserved. + */ + +package com.isode.stroke.parser; + +import com.isode.stroke.elements.PubSubOwnerPayload; +import com.isode.stroke.elements.PubSubOwnerPubSub; +import com.isode.stroke.parser.payloadparsers.PubSubOwnerAffiliationsParser; +import com.isode.stroke.parser.payloadparsers.PubSubOwnerConfigureParser; +import com.isode.stroke.parser.payloadparsers.PubSubOwnerDefaultParser; +import com.isode.stroke.parser.payloadparsers.PubSubOwnerDeleteParser; +import com.isode.stroke.parser.payloadparsers.PubSubOwnerPurgeParser; +import com.isode.stroke.parser.payloadparsers.PubSubOwnerSubscriptionsParser; + +public class PubSubOwnerPubSubParser extends + GenericPayloadParser { + + public PubSubOwnerPubSubParser(PayloadParserFactoryCollection parsers) { + super(new PubSubOwnerPubSub()); + parsers_ = parsers; + level_ = 0; + } + + public void handleStartElement(String element, String ns, + AttributeMap attributes) { + if (level_ == 1) { + if (element == "configure" + && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser_ = new PubSubOwnerConfigureParser(parsers_); + } + if (element == "subscriptions" + && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser_ = new PubSubOwnerSubscriptionsParser( + parsers_); + } + if (element == "default" + && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser_ = new PubSubOwnerDefaultParser(parsers_); + } + if (element == "purge" + && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser_ = new PubSubOwnerPurgeParser(parsers_); + } + if (element == "affiliations" + && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser_ = new PubSubOwnerAffiliationsParser( + parsers_); + } + if (element == "delete" + && ns == "http://jabber.org/protocol/pubsub#owner") { + currentPayloadParser_ = new PubSubOwnerDeleteParser(parsers_); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; + } + + public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + + if (level_ == 1) { + if (currentPayloadParser_ != null) { + getPayloadInternal().setPayload( + (PubSubOwnerPayload) currentPayloadParser_ + .getPayload()); + } + currentPayloadParser_ = null; + } + } + } + + public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } + } + + PayloadParserFactoryCollection parsers_; + int level_; + PayloadParser currentPayloadParser_; + +} diff --git a/src/com/isode/stroke/parser/StanzaParser.java b/src/com/isode/stroke/parser/StanzaParser.java index 2dfb502..cb7647d 100644 --- a/src/com/isode/stroke/parser/StanzaParser.java +++ b/src/com/isode/stroke/parser/StanzaParser.java @@ -8,7 +8,6 @@ */ package com.isode.stroke.parser; -import com.isode.stroke.elements.Element; import com.isode.stroke.elements.Payload; import com.isode.stroke.elements.Stanza; import com.isode.stroke.jid.JID; diff --git a/src/com/isode/stroke/parser/XMPPParser.java b/src/com/isode/stroke/parser/XMPPParser.java index 0e9b202..c2c25e9 100644 --- a/src/com/isode/stroke/parser/XMPPParser.java +++ b/src/com/isode/stroke/parser/XMPPParser.java @@ -11,23 +11,23 @@ package com.isode.stroke.parser; import com.isode.stroke.elements.ProtocolHeader; import java.util.logging.Logger; - public class XMPPParser implements XMLParserClient { - - private final XMLParser xmlParser_ ; + + private final XMLParser xmlParser_; private final XMPPParserClient client_; private final PayloadParserFactoryCollection payloadParserFactories_; private int currentDepth_ = 0; private ElementParser currentElementParser_ = null; private boolean parseErrorOccurred_ = false; private Logger logger_ = Logger.getLogger(this.getClass().getName()); - - public XMPPParser(XMPPParserClient parserClient, PayloadParserFactoryCollection payloadParserFactories) { + + public XMPPParser(XMPPParserClient parserClient, + PayloadParserFactoryCollection payloadParserFactories) { client_ = parserClient; payloadParserFactories_ = payloadParserFactories; xmlParser_ = PlatformXMLParserFactory.createXMLParser(this); } - + public boolean parse(String data) { parseErrorOccurred_ = false; boolean xmlParseResult = false; @@ -38,20 +38,20 @@ public class XMPPParser implements XMLParserClient { logger_.warning("Data " + data + " caused:\n" + e.getMessage()); } if (parseErrorOccurred_ || !xmlParseResult) { - logger_.warning(String.format("When parsing, %b and %b", parseErrorOccurred_, xmlParseResult)); - if(data !=null) { - logger_.warning("xml that caused failure: " + data); + logger_.warning(String.format("When parsing, %b and %b", + parseErrorOccurred_, xmlParseResult)); + if (data != null) { + logger_.warning("xml that caused failure: " + data); } } return xmlParseResult && !parseErrorOccurred_; } - - public void handleStartElement( - String element, - String ns, + + public void handleStartElement(String element, String ns, AttributeMap attributes) { if (!inStream()) { - if (element.equals("stream") && ns.equals("http://etherx.jabber.org/streams")) { + if (element.equals("stream") + && ns.equals("http://etherx.jabber.org/streams")) { ProtocolHeader header = new ProtocolHeader(); header.setFrom(attributes.getAttribute("from")); header.setTo(attributes.getAttribute("to")); @@ -70,7 +70,7 @@ public class XMPPParser implements XMLParserClient { } ++currentDepth_; } - + public void handleEndElement(String element, String ns) { assert (inStream()); if (inElement()) { @@ -87,89 +87,74 @@ public class XMPPParser implements XMLParserClient { client_.handleStreamEnd(); } } - + public void handleCharacterData(String data) { if (currentElementParser_ != null) { currentElementParser_.handleCharacterData(data); } } - + private boolean inStream() { return currentDepth_ > 0; } - + private boolean inElement() { return currentDepth_ > 1; } - + private ElementParser createElementParser(String element, String xmlns) { if (element.equals("presence")) { return new PresenceParser(payloadParserFactories_); - } - else if (element.equals("iq")) { + } else if (element.equals("iq")) { return new IQParser(payloadParserFactories_); - } - else if (element.equals("message")) { + } else if (element.equals("message")) { return new MessageParser(payloadParserFactories_); - } - else if (element.equals("features") && xmlns.equals("http://etherx.jabber.org/streams")) { + } else if (element.equals("features") + && xmlns.equals("http://etherx.jabber.org/streams")) { return new StreamFeaturesParser(); - } - else if (element.equals("auth")) { + } else if (element.equals("auth")) { return new AuthRequestParser(); - } - else if (element.equals("success")) { + } else if (element.equals("success")) { return new AuthSuccessParser(); - } - else if (element.equals("failure") && xmlns.equals("urn:ietf:params:xml:ns:xmpp-sasl")) { + } else if (element.equals("failure") + && xmlns.equals("urn:ietf:params:xml:ns:xmpp-sasl")) { return new AuthFailureParser(); - } - else if (element.equals("challenge") && xmlns.equals("urn:ietf:params:xml:ns:xmpp-sasl")) { + } else if (element.equals("challenge") + && xmlns.equals("urn:ietf:params:xml:ns:xmpp-sasl")) { return new AuthChallengeParser(); - } - else if (element.equals("response") && xmlns.equals("urn:ietf:params:xml:ns:xmpp-sasl")) { + } else if (element.equals("response") + && xmlns.equals("urn:ietf:params:xml:ns:xmpp-sasl")) { return new AuthResponseParser(); - } - else if (element.equals("starttls")) { + } else if (element.equals("starttls")) { return new StartTLSParser(); - } - else if (element.equals("failure") && xmlns.equals("urn:ietf:params:xml:ns:xmpp-tls")) { + } else if (element.equals("failure") + && xmlns.equals("urn:ietf:params:xml:ns:xmpp-tls")) { return new StartTLSFailureParser(); - } - else if (element.equals("compress")) { + } else if (element.equals("compress")) { return new CompressParser(); - } - else if (element.equals("compressed")) { + } else if (element.equals("compressed")) { return new CompressedParser(); - } - else if (element.equals("failure") && xmlns.equals("http://jabber.org/protocol/compress")) { + } else if (element.equals("failure") + && xmlns.equals("http://jabber.org/protocol/compress")) { return new CompressFailureParser(); - } - else if (element.equals("proceed")) { + } else if (element.equals("proceed")) { return new TLSProceedParser(); - } - else if (element.equals("enable") && xmlns.equals("urn:xmpp:sm:2")) { + } else if (element.equals("enable") && xmlns.equals("urn:xmpp:sm:2")) { return new EnableStreamManagementParser(); - } - else if (element.equals("enabled") && xmlns.equals("urn:xmpp:sm:2")) { + } else if (element.equals("enabled") && xmlns.equals("urn:xmpp:sm:2")) { return new StreamManagementEnabledParser(); - } - else if (element.equals("failed") && xmlns.equals("urn:xmpp:sm:2")) { + } else if (element.equals("failed") && xmlns.equals("urn:xmpp:sm:2")) { return new StreamManagementFailedParser(); - } - else if (element.equals("resume") && xmlns.equals("urn:xmpp:sm:2")) { + } else if (element.equals("resume") && xmlns.equals("urn:xmpp:sm:2")) { return new StreamResumeParser(); - } - else if (element.equals("resumed") && xmlns.equals("urn:xmpp:sm:2")) { + } else if (element.equals("resumed") && xmlns.equals("urn:xmpp:sm:2")) { return new StreamResumedParser(); - } - else if (element.equals("a") && xmlns.equals("urn:xmpp:sm:2")) { + } else if (element.equals("a") && xmlns.equals("urn:xmpp:sm:2")) { return new StanzaAckParser(); - } - else if (element.equals("r") && xmlns.equals("urn:xmpp:sm:2")) { + } else if (element.equals("r") && xmlns.equals("urn:xmpp:sm:2")) { return new StanzaAckRequestParser(); } return new UnknownElementParser(); - + } } diff --git a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java index 1abce76..cf41338 100644 --- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java +++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java @@ -9,8 +9,10 @@ package com.isode.stroke.parser.payloadparsers; import com.isode.stroke.parser.GenericPayloadParserFactory; +import com.isode.stroke.parser.GenericPayloadParserFactory2; import com.isode.stroke.parser.PayloadParserFactory; import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.parser.PubSubOwnerPubSubParser; public class FullPayloadParserFactoryCollection extends PayloadParserFactoryCollection { public FullPayloadParserFactoryCollection() { @@ -57,7 +59,12 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl addFactory(new GenericPayloadParserFactory("destroy", "http://jabber.org/protocol/muc#owner",MUCDestroyPayloadParser.class)); - //addFactory(new NicknameParserFactory()); + addFactory(new GenericPayloadParserFactory2("pubsub", "http://jabber.org/protocol/pubsub", this, PubSubParser.class)); + addFactory(new GenericPayloadParserFactory2("pubsub", "http://jabber.org/protocol/pubsub#owner", this, PubSubOwnerPubSubParser.class)); + addFactory(new GenericPayloadParserFactory2("event", "http://jabber.org/protocol/pubsub#event", this, PubSubEventParser.class)); + addFactory(new PubSubErrorParserFactory()); + + //addFactory(new NicknameParserFactory()); PayloadParserFactory defaultFactory = new RawXMLPayloadParserFactory(); setDefaultFactory(defaultFactory); diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubAffiliationParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubAffiliationParser.java new file mode 100644 index 0000000..4037f16 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubAffiliationParser.java @@ -0,0 +1,85 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubAffiliation; + +public class PubSubAffiliationParser extends GenericPayloadParser { +public PubSubAffiliationParser(PayloadParserFactoryCollection parsers) { + super(new PubSubAffiliation()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + attributeValue = attributes.getAttribute("affiliation"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setType(parseType(attributeValue)); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +private static PubSubAffiliation.Type parseType(String value) { + if (value.equals("none")) { + return PubSubAffiliation.Type.None; + } else if (value.equals("member")) { + return PubSubAffiliation.Type.Member; + } else if (value.equals("outcast")) { + return PubSubAffiliation.Type.Outcast; + } else if (value.equals("owner")) { + return PubSubAffiliation.Type.Owner; + } else if (value.equals("publisher")) { + return PubSubAffiliation.Type.Publisher; + } else if (value.equals("publish-only")) { + return PubSubAffiliation.Type.PublishOnly; + } else { + return null; + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubAffiliationsParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubAffiliationsParser.java new file mode 100644 index 0000000..23cfb3a --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubAffiliationsParser.java @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubAffiliation; +import com.isode.stroke.elements.PubSubAffiliations; + +public class PubSubAffiliationsParser extends GenericPayloadParser { +public PubSubAffiliationsParser(PayloadParserFactoryCollection parsers) { + super(new PubSubAffiliations()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ == 1) { + if (element.equals("affiliation") && ns.equals("http://jabber.org/protocol/pubsub")) { + currentPayloadParser_ = new PubSubAffiliationParser(parsers_); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("affiliation") && ns.equals("http://jabber.org/protocol/pubsub")) { + getPayloadInternal().addAffiliation((PubSubAffiliation)currentPayloadParser_.getPayload()); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubConfigureParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubConfigureParser.java new file mode 100644 index 0000000..bceda09 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubConfigureParser.java @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.Form; +import com.isode.stroke.parser.payloadparsers.FormParser; +import com.isode.stroke.elements.PubSubConfigure; + +public class PubSubConfigureParser extends GenericPayloadParser { +public PubSubConfigureParser(PayloadParserFactoryCollection parsers) { + super(new PubSubConfigure()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 1) { + if (element.equals("x") && ns.equals("jabber:x:data")) { + currentPayloadParser_ = new FormParser(); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("x") && ns.equals("jabber:x:data")) { + getPayloadInternal().setData((Form)(currentPayloadParser_.getPayload())); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubCreateParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubCreateParser.java new file mode 100644 index 0000000..8c56dc6 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubCreateParser.java @@ -0,0 +1,64 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubConfigure; +import com.isode.stroke.elements.PubSubCreate; + +public class PubSubCreateParser extends GenericPayloadParser { +public PubSubCreateParser(PayloadParserFactoryCollection parsers) { + super(new PubSubCreate()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubDefaultParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubDefaultParser.java new file mode 100644 index 0000000..643383c --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubDefaultParser.java @@ -0,0 +1,79 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubDefault; + +public class PubSubDefaultParser extends GenericPayloadParser { +public PubSubDefaultParser(PayloadParserFactoryCollection parsers) { + super(new PubSubDefault()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + attributeValue = attributes.getAttribute("type"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setType(parseType(attributeValue)); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +private static PubSubDefault.Type parseType(String value) { + if (value.equals("none")) { + return PubSubDefault.Type.None; + } else if (value.equals("collection")) { + return PubSubDefault.Type.Collection; + } else if (value.equals("leaf")) { + return PubSubDefault.Type.Leaf; + } else { + return null; + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubErrorParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubErrorParser.java new file mode 100644 index 0000000..e0b5ed0 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubErrorParser.java @@ -0,0 +1,126 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import java.util.HashMap; + +import com.isode.stroke.elements.PubSubError; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; + +public class PubSubErrorParser extends GenericPayloadParser { + +public PubSubErrorParser() +{ + super(new PubSubError(PubSubError.Type.UnknownType)); + + typeParser_.put("closed-node", PubSubError.Type.ClosedNode); + typeParser_.put("configuration-required", PubSubError.Type.ConfigurationRequired); + typeParser_.put("invalid-jid", PubSubError.Type.InvalidJID); + typeParser_.put("invalid-options", PubSubError.Type.InvalidOptions); + typeParser_.put("invalid-payload", PubSubError.Type.InvalidPayload); + typeParser_.put("invalid-subid", PubSubError.Type.InvalidSubscriptionID); + typeParser_.put("item-forbidden", PubSubError.Type.ItemForbidden); + typeParser_.put("item-required", PubSubError.Type.ItemRequired); + typeParser_.put("jid-required", PubSubError.Type.JIDRequired); + typeParser_.put("max-items-exceeded", PubSubError.Type.MaximumItemsExceeded); + typeParser_.put("max-nodes-exceeded", PubSubError.Type.MaximumNodesExceeded); + typeParser_.put("nodeid-required", PubSubError.Type.NodeIDRequired); + typeParser_.put("not-in-roster-group", PubSubError.Type.NotInRosterGroup); + typeParser_.put("not-subscribed", PubSubError.Type.NotSubscribed); + typeParser_.put("payload-too-big", PubSubError.Type.PayloadTooBig); + typeParser_.put("payload-required", PubSubError.Type.PayloadRequired); + typeParser_.put("pending-subscription", PubSubError.Type.PendingSubscription); + typeParser_.put("presence-subscription-required", PubSubError.Type.PresenceSubscriptionRequired); + typeParser_.put("subid-required", PubSubError.Type.SubscriptionIDRequired); + typeParser_.put("too-many-subscriptions", PubSubError.Type.TooManySubscriptions); + typeParser_.put("unsupported", PubSubError.Type.Unsupported); + typeParser_.put("unsupported-access-model", PubSubError.Type.UnsupportedAccessModel); + + unsupportedTypeParser_.put("access-authorize", PubSubError.UnsupportedFeatureType.AccessAuthorize); + unsupportedTypeParser_.put("access-open", PubSubError.UnsupportedFeatureType.AccessOpen); + unsupportedTypeParser_.put("access-presence", PubSubError.UnsupportedFeatureType.AccessPresence); + unsupportedTypeParser_.put("access-roster", PubSubError.UnsupportedFeatureType.AccessRoster); + unsupportedTypeParser_.put("access-whitelist", PubSubError.UnsupportedFeatureType.AccessWhitelist); + unsupportedTypeParser_.put("auto-create", PubSubError.UnsupportedFeatureType.AutoCreate); + unsupportedTypeParser_.put("auto-subscribe", PubSubError.UnsupportedFeatureType.AutoSubscribe); + unsupportedTypeParser_.put("collections", PubSubError.UnsupportedFeatureType.Collections); + unsupportedTypeParser_.put("config-node", PubSubError.UnsupportedFeatureType.ConfigNode); + unsupportedTypeParser_.put("create-and-configure", PubSubError.UnsupportedFeatureType.CreateAndConfigure); + unsupportedTypeParser_.put("create-nodes", PubSubError.UnsupportedFeatureType.CreateNodes); + unsupportedTypeParser_.put("delete-items", PubSubError.UnsupportedFeatureType.DeleteItems); + unsupportedTypeParser_.put("delete-nodes", PubSubError.UnsupportedFeatureType.DeleteNodes); + unsupportedTypeParser_.put("filtered-notifications", PubSubError.UnsupportedFeatureType.FilteredNotifications); + unsupportedTypeParser_.put("get-pending", PubSubError.UnsupportedFeatureType.GetPending); + unsupportedTypeParser_.put("instant-nodes", PubSubError.UnsupportedFeatureType.InstantNodes); + unsupportedTypeParser_.put("item-ids", PubSubError.UnsupportedFeatureType.ItemIDs); + unsupportedTypeParser_.put("last-published", PubSubError.UnsupportedFeatureType.LastPublished); + unsupportedTypeParser_.put("leased-subscription", PubSubError.UnsupportedFeatureType.LeasedSubscription); + unsupportedTypeParser_.put("manage-subscriptions", PubSubError.UnsupportedFeatureType.ManageSubscriptions); + unsupportedTypeParser_.put("member-affiliation", PubSubError.UnsupportedFeatureType.MemberAffiliation); + unsupportedTypeParser_.put("meta-data", PubSubError.UnsupportedFeatureType.MetaData); + unsupportedTypeParser_.put("modify-affiliations", PubSubError.UnsupportedFeatureType.ModifyAffiliations); + unsupportedTypeParser_.put("multi-collection", PubSubError.UnsupportedFeatureType.MultiCollection); + unsupportedTypeParser_.put("multi-subscribe", PubSubError.UnsupportedFeatureType.MultiSubscribe); + unsupportedTypeParser_.put("outcast-affiliation", PubSubError.UnsupportedFeatureType.OutcastAffiliation); + unsupportedTypeParser_.put("persistent-items", PubSubError.UnsupportedFeatureType.PersistentItems); + unsupportedTypeParser_.put("presence-notifications", PubSubError.UnsupportedFeatureType.PresenceNotifications); + unsupportedTypeParser_.put("presence-subscribe", PubSubError.UnsupportedFeatureType.PresenceSubscribe); + unsupportedTypeParser_.put("publish", PubSubError.UnsupportedFeatureType.Publish); + unsupportedTypeParser_.put("publish-options", PubSubError.UnsupportedFeatureType.PublishOptions); + unsupportedTypeParser_.put("publish-only-affiliation", PubSubError.UnsupportedFeatureType.PublishOnlyAffiliation); + unsupportedTypeParser_.put("publisher-affiliation", PubSubError.UnsupportedFeatureType.PublisherAffiliation); + unsupportedTypeParser_.put("purge-nodes", PubSubError.UnsupportedFeatureType.PurgeNodes); + unsupportedTypeParser_.put("retract-items", PubSubError.UnsupportedFeatureType.RetractItems); + unsupportedTypeParser_.put("retrieve-affiliations", PubSubError.UnsupportedFeatureType.RetrieveAffiliations); + unsupportedTypeParser_.put("retrieve-default", PubSubError.UnsupportedFeatureType.RetrieveDefault); + unsupportedTypeParser_.put("retrieve-items", PubSubError.UnsupportedFeatureType.RetrieveItems); + unsupportedTypeParser_.put("retrieve-subscriptions", PubSubError.UnsupportedFeatureType.RetrieveSubscriptions); + unsupportedTypeParser_.put("subscribe", PubSubError.UnsupportedFeatureType.Subscribe); + unsupportedTypeParser_.put("subscription-options", PubSubError.UnsupportedFeatureType.SubscriptionOptions); + unsupportedTypeParser_.put("subscription-notifications", PubSubError.UnsupportedFeatureType.SubscriptionNotifications); +} + +@Override +public void handleStartElement(String element, String ns, AttributeMap attributes) +{ + if (level_ == 1) { + PubSubError.Type type = typeParser_.get(element); + if (type != null) { + getPayloadInternal().setType(type); + if (type.equals(PubSubError.Type.Unsupported)) { + String feature = attributes.getAttributeValue("feature"); + if (feature != null) { + PubSubError.UnsupportedFeatureType unsupportedType = unsupportedTypeParser_.get(feature); + if (unsupportedType != null) { + getPayloadInternal().setUnsupportedFeatureType(unsupportedType); + } + } + } + } + } + ++level_; +} + +@Override +public void handleEndElement(String element, String ns) +{ + --level_; +} + +@Override +public void handleCharacterData(String data) +{ +} + +int level_; +HashMap typeParser_ = new HashMap(); +HashMap unsupportedTypeParser_ = new HashMap(); +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubErrorParserFactory.java b/src/com/isode/stroke/parser/payloadparsers/PubSubErrorParserFactory.java new file mode 100644 index 0000000..78c07ed --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubErrorParserFactory.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2014, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2014, Remko Tronçon. + * All rights reserved. + */ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactory; + +public class PubSubErrorParserFactory implements PayloadParserFactory { + + @Override + public boolean canParse(String element, String ns, AttributeMap attributes) { + return ns.equals("http://jabber.org/protocol/pubsub#errors"); + } + + @Override + public PayloadParser createPayloadParser() { + return new PubSubErrorParser(); + } + +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubEvent.java b/src/com/isode/stroke/parser/payloadparsers/PubSubEvent.java new file mode 100644 index 0000000..6fb9e17 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubEvent.java @@ -0,0 +1,17 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.elements.ContainerPayload; +import com.isode.stroke.elements.PubSubEventPayload; + +public class PubSubEvent extends ContainerPayload { + +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubEventAssociateParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubEventAssociateParser.java new file mode 100644 index 0000000..900e2e6 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubEventAssociateParser.java @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubEventAssociate; + +public class PubSubEventAssociateParser extends GenericPayloadParser { +public PubSubEventAssociateParser(PayloadParserFactoryCollection parsers) { + super(new PubSubEventAssociate()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubEventCollectionParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubEventCollectionParser.java new file mode 100644 index 0000000..467ab5b --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubEventCollectionParser.java @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubEventAssociate; +import com.isode.stroke.elements.PubSubEventDisassociate; +import com.isode.stroke.elements.PubSubEventCollection; + +public class PubSubEventCollectionParser extends GenericPayloadParser { +public PubSubEventCollectionParser(PayloadParserFactoryCollection parsers) { + super(new PubSubEventCollection()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ == 1) { + if (element.equals("associate") && ns.equals("http://jabber.org/protocol/pubsub#event")) { + currentPayloadParser_ = new PubSubEventAssociateParser(parsers_); + } + if (element.equals("disassociate") && ns.equals("http://jabber.org/protocol/pubsub#event")) { + currentPayloadParser_ = new PubSubEventDisassociateParser(parsers_); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("associate") && ns.equals("http://jabber.org/protocol/pubsub#event")) { + getPayloadInternal().setAssociate((PubSubEventAssociate)(currentPayloadParser_.getPayload())); + } + if (element.equals("disassociate") && ns.equals("http://jabber.org/protocol/pubsub#event")) { + getPayloadInternal().setDisassociate((PubSubEventDisassociate)(currentPayloadParser_.getPayload())); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubEventConfigurationParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubEventConfigurationParser.java new file mode 100644 index 0000000..7848328 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubEventConfigurationParser.java @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.Form; +import com.isode.stroke.parser.payloadparsers.FormParser; +import com.isode.stroke.elements.PubSubEventConfiguration; + +public class PubSubEventConfigurationParser extends GenericPayloadParser { +public PubSubEventConfigurationParser(PayloadParserFactoryCollection parsers) { + super(new PubSubEventConfiguration()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ == 1) { + if (element.equals("x") && ns.equals("jabber:x:data")) { + currentPayloadParser_ = new FormParser(); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("x") && ns.equals("jabber:x:data")) { + getPayloadInternal().setData((Form)(currentPayloadParser_.getPayload())); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubEventDeleteParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubEventDeleteParser.java new file mode 100644 index 0000000..1663e36 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubEventDeleteParser.java @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubEventRedirect; +import com.isode.stroke.elements.PubSubEventDelete; + +public class PubSubEventDeleteParser extends GenericPayloadParser { +public PubSubEventDeleteParser(PayloadParserFactoryCollection parsers) { + super(new PubSubEventDelete()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ == 1) { + if (element.equals("redirect") && ns.equals("http://jabber.org/protocol/pubsub#event")) { + currentPayloadParser_ = new PubSubEventRedirectParser(parsers_); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("redirect") && ns.equals("http://jabber.org/protocol/pubsub#event")) { + getPayloadInternal().setRedirects((PubSubEventRedirect)(currentPayloadParser_.getPayload())); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubEventDisassociateParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubEventDisassociateParser.java new file mode 100644 index 0000000..90f510f --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubEventDisassociateParser.java @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubEventDisassociate; + +public class PubSubEventDisassociateParser extends GenericPayloadParser { +public PubSubEventDisassociateParser(PayloadParserFactoryCollection parsers) { + super(new PubSubEventDisassociate()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubEventItemParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubEventItemParser.java new file mode 100644 index 0000000..508f836 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubEventItemParser.java @@ -0,0 +1,81 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.parser.PayloadParserFactory; +import com.isode.stroke.elements.PubSubEventItem; + +public class PubSubEventItemParser extends GenericPayloadParser { +public PubSubEventItemParser(PayloadParserFactoryCollection parsers) { + super(new PubSubEventItem()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("publisher"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setPublisher(attributeValue); + } + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + attributeValue = attributes.getAttribute("id"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setID(attributeValue); + } + } + + if (level_ == 1) { + PayloadParserFactory factory; + factory = parsers_.getPayloadParserFactory(element, ns, attributes); + if (factory != null) { + currentPayloadParser_ = factory.createPayloadParser(); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + getPayloadInternal().addData(currentPayloadParser_.getPayload()); + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubEventItemsParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubEventItemsParser.java new file mode 100644 index 0000000..e5d9e47 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubEventItemsParser.java @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubEventItem; +import com.isode.stroke.elements.PubSubEventRetract; +import com.isode.stroke.elements.PubSubEventItems; + +public class PubSubEventItemsParser extends GenericPayloadParser { +public PubSubEventItemsParser(PayloadParserFactoryCollection parsers) { + super(new PubSubEventItems()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ == 1) { + if (element.equals("item") && ns.equals("http://jabber.org/protocol/pubsub#event")) { + currentPayloadParser_ = new PubSubEventItemParser(parsers_); + } + if (element.equals("retract") && ns.equals("http://jabber.org/protocol/pubsub#event")) { + currentPayloadParser_ = new PubSubEventRetractParser(parsers_); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("item") && ns.equals("http://jabber.org/protocol/pubsub#event")) { + getPayloadInternal().addItem((PubSubEventItem)currentPayloadParser_.getPayload()); + } + if (element.equals("retract") && ns.equals("http://jabber.org/protocol/pubsub#event")) { + getPayloadInternal().addRetract((PubSubEventRetract)currentPayloadParser_.getPayload()); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubEventParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubEventParser.java new file mode 100644 index 0000000..d7bdbe6 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubEventParser.java @@ -0,0 +1,81 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.elements.PubSubEventPayload; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; + +public class PubSubEventParser extends GenericPayloadParser { + +public PubSubEventParser(PayloadParserFactoryCollection parser) { + super(new PubSubEvent()); + parsers_ = parser; +} + +@Override +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 1) { + if (element == "items" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser_ = new PubSubEventItemsParser(parsers_); + } + if (element == "collection" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser_ = new PubSubEventCollectionParser(parsers_); + } + if (element == "purge" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser_ = new PubSubEventPurgeParser(parsers_); + } + if (element == "configuration" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser_ = new PubSubEventConfigurationParser(parsers_); + } + if (element == "delete" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser_ = new PubSubEventDeleteParser(parsers_); + } + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub#event") { + currentPayloadParser_ = new PubSubEventSubscriptionParser(parsers_); + } + } + + if (level_>=1 && currentPayloadParser_!=null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +@Override +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + + if (level_ == 1) { + if (currentPayloadParser_ != null) { + getPayloadInternal().setPayload((PubSubEventPayload)currentPayloadParser_.getPayload()); + } + currentPayloadParser_ = null; + } + } +} + +@Override +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_!=null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubEventPurgeParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubEventPurgeParser.java new file mode 100644 index 0000000..fd4e525 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubEventPurgeParser.java @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubEventPurge; + +public class PubSubEventPurgeParser extends GenericPayloadParser { +public PubSubEventPurgeParser(PayloadParserFactoryCollection parsers) { + super(new PubSubEventPurge()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubEventRedirectParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubEventRedirectParser.java new file mode 100644 index 0000000..3e157d5 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubEventRedirectParser.java @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubEventRedirect; + +public class PubSubEventRedirectParser extends GenericPayloadParser { +public PubSubEventRedirectParser(PayloadParserFactoryCollection parsers) { + super(new PubSubEventRedirect()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("uri"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setURI(attributeValue); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubEventRetractParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubEventRetractParser.java new file mode 100644 index 0000000..5e43e2e --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubEventRetractParser.java @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubEventRetract; + +public class PubSubEventRetractParser extends GenericPayloadParser { +public PubSubEventRetractParser(PayloadParserFactoryCollection parsers) { + super(new PubSubEventRetract()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("id"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setID(attributeValue); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubEventSubscriptionParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubEventSubscriptionParser.java new file mode 100644 index 0000000..eb01301 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubEventSubscriptionParser.java @@ -0,0 +1,107 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.jid.JID; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import com.isode.stroke.elements.PubSubEventSubscription; + +public class PubSubEventSubscriptionParser extends GenericPayloadParser { +public PubSubEventSubscriptionParser(PayloadParserFactoryCollection parsers) { + super(new PubSubEventSubscription()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("subscription"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setSubscription(parseSubscriptionType(attributeValue)); + } + attributeValue = attributes.getAttribute("subid"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setSubscriptionID(attributeValue); + } + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + attributeValue = attributes.getAttribute("jid"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setJID(JID.fromString(attributeValue)); + } + attributeValue = attributes.getAttribute("expiry"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setExpiry(stringToDate(attributeValue)); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +private static PubSubEventSubscription.SubscriptionType parseSubscriptionType(String value) { + if (value.equals("none")) { + return PubSubEventSubscription.SubscriptionType.None; + } else if (value.equals("pending")) { + return PubSubEventSubscription.SubscriptionType.Pending; + } else if (value.equals("subscribed")) { + return PubSubEventSubscription.SubscriptionType.Subscribed; + } else if (value.equals("unconfigured")) { + return PubSubEventSubscription.SubscriptionType.Unconfigured; + } else { + return null; + } +} + +private static Date stringToDate(String date) { + String format = "YYYY-MM-ddThh:mm:ssZ"; + SimpleDateFormat parser = new SimpleDateFormat(format); + try { + return parser.parse(date); + } catch (ParseException e) { + return null; + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubItemParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubItemParser.java new file mode 100644 index 0000000..8eae0a5 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubItemParser.java @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.parser.PayloadParserFactory; +import com.isode.stroke.elements.PubSubItem; + +public class PubSubItemParser extends GenericPayloadParser { +public PubSubItemParser(PayloadParserFactoryCollection parsers) { + super(new PubSubItem()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("id"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setID(attributeValue); + } + } + + if (level_ == 1) { + PayloadParserFactory factory; + factory = parsers_.getPayloadParserFactory(element, ns, attributes); + if (factory != null) { + currentPayloadParser_ = factory.createPayloadParser(); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + getPayloadInternal().addData(currentPayloadParser_.getPayload()); + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubItemsParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubItemsParser.java new file mode 100644 index 0000000..b69e9b6 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubItemsParser.java @@ -0,0 +1,81 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubItem; +import com.isode.stroke.elements.PubSubItems; + +public class PubSubItemsParser extends GenericPayloadParser { +public PubSubItemsParser(PayloadParserFactoryCollection parsers) { + super(new PubSubItems()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("max_items"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setMaximumItems(Long.parseLong(attributeValue)); + } + attributeValue = attributes.getAttribute("subid"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setSubscriptionID(attributeValue); + } + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ == 1) { + if (element.equals("item") && ns.equals("http://jabber.org/protocol/pubsub")) { + currentPayloadParser_ = new PubSubItemParser(parsers_); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("item") && ns.equals("http://jabber.org/protocol/pubsub")) { + getPayloadInternal().addItem((PubSubItem)currentPayloadParser_.getPayload()); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubOptionsParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubOptionsParser.java new file mode 100644 index 0000000..97fbd7a --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubOptionsParser.java @@ -0,0 +1,83 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.Form; +import com.isode.stroke.parser.payloadparsers.FormParser; +import com.isode.stroke.jid.JID; +import com.isode.stroke.elements.PubSubOptions; + +public class PubSubOptionsParser extends GenericPayloadParser { +public PubSubOptionsParser(PayloadParserFactoryCollection parsers) { + super(new PubSubOptions()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("subid"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setSubscriptionID(attributeValue); + } + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + attributeValue = attributes.getAttribute("jid"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setJID(JID.fromString(attributeValue)); + } + } + + if (level_ == 1) { + if (element.equals("x") && ns.equals("jabber:x:data")) { + currentPayloadParser_ = new FormParser(); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("x") && ns.equals("jabber:x:data")) { + getPayloadInternal().setData((Form)(currentPayloadParser_.getPayload())); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerAffiliationParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerAffiliationParser.java new file mode 100644 index 0000000..2ca3659 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerAffiliationParser.java @@ -0,0 +1,86 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.jid.JID; +import com.isode.stroke.elements.PubSubOwnerAffiliation; + +public class PubSubOwnerAffiliationParser extends GenericPayloadParser { +public PubSubOwnerAffiliationParser(PayloadParserFactoryCollection parsers) { + super(new PubSubOwnerAffiliation()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("jid"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setJID(JID.fromString(attributeValue)); + } + attributeValue = attributes.getAttribute("affiliation"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setType(parseType(attributeValue)); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +private static PubSubOwnerAffiliation.Type parseType(String value) { + if (value.equals("none")) { + return PubSubOwnerAffiliation.Type.None; + } else if (value.equals("member")) { + return PubSubOwnerAffiliation.Type.Member; + } else if (value.equals("outcast")) { + return PubSubOwnerAffiliation.Type.Outcast; + } else if (value.equals("owner")) { + return PubSubOwnerAffiliation.Type.Owner; + } else if (value.equals("publisher")) { + return PubSubOwnerAffiliation.Type.Publisher; + } else if (value.equals("publish-only")) { + return PubSubOwnerAffiliation.Type.PublishOnly; + } else { + return null; + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerAffiliationsParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerAffiliationsParser.java new file mode 100644 index 0000000..843a834 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerAffiliationsParser.java @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubOwnerAffiliation; +import com.isode.stroke.elements.PubSubOwnerAffiliations; + +public class PubSubOwnerAffiliationsParser extends GenericPayloadParser { +public PubSubOwnerAffiliationsParser(PayloadParserFactoryCollection parsers) { + super(new PubSubOwnerAffiliations()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ == 1) { + if (element.equals("affiliation") && ns.equals("http://jabber.org/protocol/pubsub#owner")) { + currentPayloadParser_ = new PubSubOwnerAffiliationParser(parsers_); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("affiliation") && ns.equals("http://jabber.org/protocol/pubsub#owner")) { + getPayloadInternal().addAffiliation((PubSubOwnerAffiliation)currentPayloadParser_.getPayload()); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerConfigureParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerConfigureParser.java new file mode 100644 index 0000000..66b111c --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerConfigureParser.java @@ -0,0 +1,74 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.Form; +import com.isode.stroke.parser.payloadparsers.FormParser; +import com.isode.stroke.elements.PubSubOwnerConfigure; + +public class PubSubOwnerConfigureParser extends GenericPayloadParser { +public PubSubOwnerConfigureParser(PayloadParserFactoryCollection parsers) { + super(new PubSubOwnerConfigure()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ == 1) { + if (element.equals("x") && ns.equals("jabber:x:data")) { + currentPayloadParser_ = new FormParser(); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("x") && ns.equals("jabber:x:data")) { + getPayloadInternal().setData((Form)(currentPayloadParser_.getPayload())); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerDefaultParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerDefaultParser.java new file mode 100644 index 0000000..ca9ea5e --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerDefaultParser.java @@ -0,0 +1,66 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.Form; +import com.isode.stroke.parser.payloadparsers.FormParser; +import com.isode.stroke.elements.PubSubOwnerDefault; + +public class PubSubOwnerDefaultParser extends GenericPayloadParser { +public PubSubOwnerDefaultParser(PayloadParserFactoryCollection parsers) { + super(new PubSubOwnerDefault()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 1) { + if (element.equals("x") && ns.equals("jabber:x:data")) { + currentPayloadParser_ = new FormParser(); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("x") && ns.equals("jabber:x:data")) { + getPayloadInternal().setData((Form)(currentPayloadParser_.getPayload())); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerDeleteParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerDeleteParser.java new file mode 100644 index 0000000..37c4bc7 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerDeleteParser.java @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubOwnerRedirect; +import com.isode.stroke.elements.PubSubOwnerDelete; + +public class PubSubOwnerDeleteParser extends GenericPayloadParser { +public PubSubOwnerDeleteParser(PayloadParserFactoryCollection parsers) { + super(new PubSubOwnerDelete()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ == 1) { + if (element.equals("redirect") && ns.equals("http://jabber.org/protocol/pubsub#owner")) { + currentPayloadParser_ = new PubSubOwnerRedirectParser(parsers_); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("redirect") && ns.equals("http://jabber.org/protocol/pubsub#owner")) { + getPayloadInternal().setRedirect((PubSubOwnerRedirect)(currentPayloadParser_.getPayload())); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerPurgeParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerPurgeParser.java new file mode 100644 index 0000000..0ac6e22 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerPurgeParser.java @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubOwnerPurge; + +public class PubSubOwnerPurgeParser extends GenericPayloadParser { +public PubSubOwnerPurgeParser(PayloadParserFactoryCollection parsers) { + super(new PubSubOwnerPurge()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerRedirectParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerRedirectParser.java new file mode 100644 index 0000000..5a8f5fe --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerRedirectParser.java @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubOwnerRedirect; + +public class PubSubOwnerRedirectParser extends GenericPayloadParser { +public PubSubOwnerRedirectParser(PayloadParserFactoryCollection parsers) { + super(new PubSubOwnerRedirect()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("uri"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setURI(attributeValue); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerSubscriptionParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerSubscriptionParser.java new file mode 100644 index 0000000..90d1f3b --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerSubscriptionParser.java @@ -0,0 +1,82 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.jid.JID; +import com.isode.stroke.elements.PubSubOwnerSubscription; + +public class PubSubOwnerSubscriptionParser extends GenericPayloadParser { +public PubSubOwnerSubscriptionParser(PayloadParserFactoryCollection parsers) { + super(new PubSubOwnerSubscription()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("subscription"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setSubscription(parseSubscriptionType(attributeValue)); + } + attributeValue = attributes.getAttribute("jid"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setJID(JID.fromString(attributeValue)); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +private static PubSubOwnerSubscription.SubscriptionType parseSubscriptionType(String value) { + if (value.equals("none")) { + return PubSubOwnerSubscription.SubscriptionType.None; + } else if (value.equals("pending")) { + return PubSubOwnerSubscription.SubscriptionType.Pending; + } else if (value.equals("subscribed")) { + return PubSubOwnerSubscription.SubscriptionType.Subscribed; + } else if (value.equals("unconfigured")) { + return PubSubOwnerSubscription.SubscriptionType.Unconfigured; + } else { + return null; + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerSubscriptionsParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerSubscriptionsParser.java new file mode 100644 index 0000000..f4f8508 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubOwnerSubscriptionsParser.java @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubOwnerSubscription; +import com.isode.stroke.elements.PubSubOwnerSubscriptions; + +public class PubSubOwnerSubscriptionsParser extends GenericPayloadParser { +public PubSubOwnerSubscriptionsParser(PayloadParserFactoryCollection parsers) { + super(new PubSubOwnerSubscriptions()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ == 1) { + if (element.equals("subscription") && ns.equals("http://jabber.org/protocol/pubsub#owner")) { + currentPayloadParser_ = new PubSubOwnerSubscriptionParser(parsers_); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("subscription") && ns.equals("http://jabber.org/protocol/pubsub#owner")) { + getPayloadInternal().addSubscription((PubSubOwnerSubscription)currentPayloadParser_.getPayload()); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubParser.java new file mode 100644 index 0000000..134d654 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubParser.java @@ -0,0 +1,129 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.elements.PubSub; +import com.isode.stroke.elements.PubSubConfigure; +import com.isode.stroke.elements.PubSubCreate; +import com.isode.stroke.elements.PubSubOptions; +import com.isode.stroke.elements.PubSubPayload; +import com.isode.stroke.elements.PubSubSubscribe; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; + +public class PubSubParser extends GenericPayloadParser { + + public PubSubParser(PayloadParserFactoryCollection parsers) { + super(new PubSub()); + parsers_ = parsers; + level_ = 0; + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 1) { + if (element == "items" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser_ = new PubSubItemsParser(parsers_); + } + if (element == "create" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser_ = new PubSubCreateParser(parsers_); + } + if (element == "publish" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser_ = new PubSubPublishParser(parsers_); + } + if (element == "affiliations" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser_ = new PubSubAffiliationsParser(parsers_); + } + if (element == "retract" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser_ = new PubSubRetractParser(parsers_); + } + if (element == "options" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser_ = new PubSubOptionsParser(parsers_); + } + if (element == "configure" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser_ = new PubSubConfigureParser(parsers_); + } + if (element == "default" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser_ = new PubSubDefaultParser(parsers_); + } + if (element == "subscriptions" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser_ = new PubSubSubscriptionsParser(parsers_); + } + if (element == "subscribe" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser_ = new PubSubSubscribeParser(parsers_); + } + if (element == "unsubscribe" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser_ = new PubSubUnsubscribeParser(parsers_); + } + if (element == "subscription" && ns == "http://jabber.org/protocol/pubsub") { + currentPayloadParser_ = new PubSubSubscriptionParser(parsers_); + } + } + + if (level_>=1 && currentPayloadParser_!=null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; + } + + public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_!=null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + + if (level_ == 1) { + if (currentPayloadParser_ != null) { + if (element == "options" && ns == "http://jabber.org/protocol/pubsub") { + optionsPayload_ = (PubSubOptions)currentPayloadParser_.getPayload(); + } + else if (element == "configure" && ns == "http://jabber.org/protocol/pubsub") { + configurePayload_ = (PubSubConfigure)currentPayloadParser_.getPayload(); + } + else { + getPayloadInternal().setPayload((PubSubPayload)currentPayloadParser_.getPayload()); + } + } + currentPayloadParser_ = null; + } + + if (level_ == 0) { + PubSubCreate create = (PubSubCreate)getPayloadInternal().getPayload(); + if (create != null) { + if (configurePayload_ != null) { + create.setConfigure(configurePayload_); + } + } + PubSubSubscribe subscribe = (PubSubSubscribe)getPayloadInternal().getPayload(); + if (subscribe != null) { + if (optionsPayload_ != null) { + subscribe.setOptions(optionsPayload_); + } + } + } + } + } + + public void handleCharacterData(String data) { + if (level_>1 && currentPayloadParser_!=null) { + currentPayloadParser_.handleCharacterData(data); + } + } + + + PayloadParserFactoryCollection parsers_; + int level_; + PayloadParser currentPayloadParser_; + PubSubConfigure configurePayload_; + PubSubOptions optionsPayload_; + +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubPublishParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubPublishParser.java new file mode 100644 index 0000000..4fe9af5 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubPublishParser.java @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubItem; +import com.isode.stroke.elements.PubSubPublish; + +public class PubSubPublishParser extends GenericPayloadParser { +public PubSubPublishParser(PayloadParserFactoryCollection parsers) { + super(new PubSubPublish()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ == 1) { + if (element.equals("item") && ns.equals("http://jabber.org/protocol/pubsub")) { + currentPayloadParser_ = new PubSubItemParser(parsers_); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("item") && ns.equals("http://jabber.org/protocol/pubsub")) { + getPayloadInternal().addItem((PubSubItem)currentPayloadParser_.getPayload()); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubRetractParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubRetractParser.java new file mode 100644 index 0000000..5e38361 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubRetractParser.java @@ -0,0 +1,77 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubItem; +import com.isode.stroke.elements.PubSubRetract; + +public class PubSubRetractParser extends GenericPayloadParser { +public PubSubRetractParser(PayloadParserFactoryCollection parsers) { + super(new PubSubRetract()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + attributeValue = attributes.getAttribute("notify"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNotify(attributeValue.equals("true") ? true : false); + } + } + + if (level_ == 1) { + if (element.equals("item") && ns.equals("http://jabber.org/protocol/pubsub")) { + currentPayloadParser_ = new PubSubItemParser(parsers_); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("item") && ns.equals("http://jabber.org/protocol/pubsub")) { + getPayloadInternal().addItem((PubSubItem)currentPayloadParser_.getPayload()); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubSubscribeOptionsParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubSubscribeOptionsParser.java new file mode 100644 index 0000000..14e3412 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubSubscribeOptionsParser.java @@ -0,0 +1,58 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubSubscribeOptions; + +public class PubSubSubscribeOptionsParser extends GenericPayloadParser { +public PubSubSubscribeOptionsParser(PayloadParserFactoryCollection parsers) { + super(new PubSubSubscribeOptions()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("required")) { + getPayloadInternal().setRequired(true); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubSubscribeParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubSubscribeParser.java new file mode 100644 index 0000000..dbc8449 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubSubscribeParser.java @@ -0,0 +1,69 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.jid.JID; +import com.isode.stroke.elements.PubSubOptions; +import com.isode.stroke.elements.PubSubSubscribe; + +public class PubSubSubscribeParser extends GenericPayloadParser { +public PubSubSubscribeParser(PayloadParserFactoryCollection parsers) { + super(new PubSubSubscribe()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + attributeValue = attributes.getAttribute("jid"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setJID(JID.fromString(attributeValue)); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubSubscriptionParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubSubscriptionParser.java new file mode 100644 index 0000000..5d11f2e --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubSubscriptionParser.java @@ -0,0 +1,100 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.jid.JID; +import com.isode.stroke.elements.PubSubSubscribeOptions; +import com.isode.stroke.elements.PubSubSubscription; + +public class PubSubSubscriptionParser extends GenericPayloadParser { +public PubSubSubscriptionParser(PayloadParserFactoryCollection parsers) { + super(new PubSubSubscription()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("subscription"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setSubscription(parseSubscriptionType(attributeValue)); + } + attributeValue = attributes.getAttribute("subid"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setSubscriptionID(attributeValue); + } + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + attributeValue = attributes.getAttribute("jid"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setJID(JID.fromString(attributeValue)); + } + } + + if (level_ == 1) { + if (element.equals("subscribe-options") && ns.equals("http://jabber.org/protocol/pubsub")) { + currentPayloadParser_ = new PubSubSubscribeOptionsParser(parsers_); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("subscribe-options") && ns.equals("http://jabber.org/protocol/pubsub")) { + getPayloadInternal().setOptions((PubSubSubscribeOptions)(currentPayloadParser_.getPayload())); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +private static PubSubSubscription.SubscriptionType parseSubscriptionType(String value) { + if (value.equals("none")) { + return PubSubSubscription.SubscriptionType.None; + } else if (value.equals("pending")) { + return PubSubSubscription.SubscriptionType.Pending; + } else if (value.equals("subscribed")) { + return PubSubSubscription.SubscriptionType.Subscribed; + } else if (value.equals("unconfigured")) { + return PubSubSubscription.SubscriptionType.Unconfigured; + } else { + return null; + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubSubscriptionsParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubSubscriptionsParser.java new file mode 100644 index 0000000..f8c3a5c --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubSubscriptionsParser.java @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.elements.PubSubSubscription; +import com.isode.stroke.elements.PubSubSubscriptions; + +public class PubSubSubscriptionsParser extends GenericPayloadParser { +public PubSubSubscriptionsParser(PayloadParserFactoryCollection parsers) { + super(new PubSubSubscriptions()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + } + + if (level_ == 1) { + if (element.equals("subscription") && ns.equals("http://jabber.org/protocol/pubsub")) { + currentPayloadParser_ = new PubSubSubscriptionParser(parsers_); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + if (element.equals("subscription") && ns.equals("http://jabber.org/protocol/pubsub")) { + getPayloadInternal().addSubscription((PubSubSubscription)currentPayloadParser_.getPayload()); + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/PubSubUnsubscribeParser.java b/src/com/isode/stroke/parser/payloadparsers/PubSubUnsubscribeParser.java new file mode 100644 index 0000000..7ef44af --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PubSubUnsubscribeParser.java @@ -0,0 +1,72 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.jid.JID; +import com.isode.stroke.elements.PubSubUnsubscribe; + +public class PubSubUnsubscribeParser extends GenericPayloadParser { +public PubSubUnsubscribeParser(PayloadParserFactoryCollection parsers) { + super(new PubSubUnsubscribe()); + + parsers_ = parsers; + level_ = 0; +} + +public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue; + attributeValue = attributes.getAttribute("subid"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setSubscriptionID(attributeValue); + } + attributeValue = attributes.getAttribute("node"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setNode(attributeValue); + } + attributeValue = attributes.getAttribute("jid"); + if (!attributeValue.isEmpty()) { + getPayloadInternal().setJID(JID.fromString(attributeValue)); + } + } + + if (level_ >= 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleStartElement(element, ns, attributes); + } + ++level_; +} + +public void handleEndElement(String element, String ns) { + --level_; + if (currentPayloadParser_ != null) { + if (level_ >= 1) { + currentPayloadParser_.handleEndElement(element, ns); + } + if (level_ != 1) { + return; + } + currentPayloadParser_ = null; + } +} + +public void handleCharacterData(String data) { + if (level_ > 1 && currentPayloadParser_ != null) { + currentPayloadParser_.handleCharacterData(data); + } +} + +PayloadParserFactoryCollection parsers_; +int level_; +PayloadParser currentPayloadParser_; +} diff --git a/src/com/isode/stroke/pubsub/PubSubManager.java b/src/com/isode/stroke/pubsub/PubSubManager.java new file mode 100644 index 0000000..cd0f2a7 --- /dev/null +++ b/src/com/isode/stroke/pubsub/PubSubManager.java @@ -0,0 +1,18 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.pubsub; + +import com.isode.stroke.elements.PubSubEventPayload; +import com.isode.stroke.jid.JID; +import com.isode.stroke.signals.Signal2; + +public class PubSubManager { +public Signal2 onEvent = new Signal2(); +} diff --git a/src/com/isode/stroke/pubsub/PubSubManagerImpl.java b/src/com/isode/stroke/pubsub/PubSubManagerImpl.java new file mode 100644 index 0000000..ab1e8c6 --- /dev/null +++ b/src/com/isode/stroke/pubsub/PubSubManagerImpl.java @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.pubsub; + +import com.isode.stroke.client.StanzaChannel; +import com.isode.stroke.elements.Message; +import com.isode.stroke.parser.payloadparsers.PubSubEvent; +import com.isode.stroke.queries.IQRouter; +import com.isode.stroke.signals.Slot1; + +public class PubSubManagerImpl extends PubSubManager { + + public PubSubManagerImpl(StanzaChannel stanzaChannel, IQRouter router) { + stanzaChannel_ = stanzaChannel; + router_ = router; + + stanzaChannel.onMessageReceived.connect(new Slot1() { + public void call(Message message) { + PubSubEvent event = (PubSubEvent)message.getPayload(new PubSubEvent()); + if (event != null) { + onEvent.emit(message.getFrom(), event.getPayload()); + } + } + }); + } + + StanzaChannel stanzaChannel_; + IQRouter router_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java index d8a7a7d..f846d85 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java +++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java @@ -56,6 +56,11 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection //addSerializer(new NicknameSerializer()); addSerializer(new SearchPayloadSerializer()); addSerializer(new LastSerializer()); + + addSerializer(new PubSubSerializer(this)); + addSerializer(new PubSubEventSerializer(this)); + addSerializer(new PubSubOwnerPubSubSerializer(this)); + addSerializer(new PubSubErrorSerializer()); } } diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubAffiliationSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubAffiliationSerializer.java new file mode 100644 index 0000000..df26b3a --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubAffiliationSerializer.java @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubAffiliation; + +public class PubSubAffiliationSerializer extends GenericPayloadSerializer { +public PubSubAffiliationSerializer(PayloadSerializerCollection serializers) { + super(PubSubAffiliation.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubAffiliation payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("affiliation", "http://jabber.org/protocol/pubsub"); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + element.setAttribute("affiliation", serializeType(payload.getType())); + + return element.serialize(); +} + +private static String serializeType(PubSubAffiliation.Type value) { + switch (value) { + case None: return "none"; + case Member: return "member"; + case Outcast: return "outcast"; + case Owner: return "owner"; + case Publisher: return "publisher"; + case PublishOnly: return "publish-only"; + } + return "undefined-type"; +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubAffiliationsSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubAffiliationsSerializer.java new file mode 100644 index 0000000..bceac02 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubAffiliationsSerializer.java @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubAffiliation; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubAffiliations; + +public class PubSubAffiliationsSerializer extends GenericPayloadSerializer { +public PubSubAffiliationsSerializer(PayloadSerializerCollection serializers) { + super(PubSubAffiliations.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubAffiliations payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("affiliations", "http://jabber.org/protocol/pubsub"); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + for (PubSubAffiliation item : payload.getAffiliations()) { + element.addNode(new XMLRawTextNode((new PubSubAffiliationSerializer(serializers_)).serialize(item))); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubConfigureSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubConfigureSerializer.java new file mode 100644 index 0000000..6f5dd10 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubConfigureSerializer.java @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.payloadserializers.FormSerializer; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubConfigure; + +public class PubSubConfigureSerializer extends GenericPayloadSerializer { +public PubSubConfigureSerializer(PayloadSerializerCollection serializers) { + super(PubSubConfigure.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubConfigure payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("configure", "http://jabber.org/protocol/pubsub"); + + element.addNode(new XMLRawTextNode((new FormSerializer()).serialize(payload.getData()))); + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubCreateSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubCreateSerializer.java new file mode 100644 index 0000000..45b4128 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubCreateSerializer.java @@ -0,0 +1,40 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubConfigure; +import com.isode.stroke.elements.PubSubCreate; + +public class PubSubCreateSerializer extends GenericPayloadSerializer { +public PubSubCreateSerializer(PayloadSerializerCollection serializers) { + super(PubSubCreate.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubCreate payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("create", "http://jabber.org/protocol/pubsub"); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubDefaultSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubDefaultSerializer.java new file mode 100644 index 0000000..88efb53 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubDefaultSerializer.java @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubDefault; + +public class PubSubDefaultSerializer extends GenericPayloadSerializer { +public PubSubDefaultSerializer(PayloadSerializerCollection serializers) { + super(PubSubDefault.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubDefault payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("default", "http://jabber.org/protocol/pubsub"); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + element.setAttribute("type", serializeType(payload.getType())); + + return element.serialize(); +} + +private static String serializeType(PubSubDefault.Type value) { + switch (value) { + case None: return "none"; + case Collection: return "collection"; + case Leaf: return "leaf"; + } + return "undefined-type"; +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubErrorSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubErrorSerializer.java new file mode 100644 index 0000000..d4f765f --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubErrorSerializer.java @@ -0,0 +1,112 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.elements.PubSubError; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.xml.XMLElement; + +public class PubSubErrorSerializer extends GenericPayloadSerializer { +public PubSubErrorSerializer() { + super(PubSubError.class); +} + +@Override +public String serializePayload(PubSubError payload) { + if (payload.getType().equals(PubSubError.Type.UnknownType)) { + return ""; + } + XMLElement element = new XMLElement(serializeType(payload.getType()), "http://jabber.org/protocol/pubsub#errors"); + if (payload.getType().equals(PubSubError.Type.Unsupported)) { + if (!payload.getUnsupportedFeatureType().equals(PubSubError.UnsupportedFeatureType.UnknownUnsupportedFeatureType)) { + element.setAttribute("feature", serializeUnsupportedFeatureType(payload.getUnsupportedFeatureType())); + } + } + return element.serialize(); +} + +static String serializeType(PubSubError.Type value) { + switch (value) { + case UnknownType: return ""; + case ClosedNode: return "closed-node"; + case ConfigurationRequired: return "configuration-required"; + case InvalidJID: return "invalid-jid"; + case InvalidOptions: return "invalid-options"; + case InvalidPayload: return "invalid-payload"; + case InvalidSubscriptionID: return "invalid-subid"; + case ItemForbidden: return "item-forbidden"; + case ItemRequired: return "item-required"; + case JIDRequired: return "jid-required"; + case MaximumItemsExceeded: return "max-items-exceeded"; + case MaximumNodesExceeded: return "max-nodes-exceeded"; + case NodeIDRequired: return "nodeid-required"; + case NotInRosterGroup: return "not-in-roster-group"; + case NotSubscribed: return "not-subscribed"; + case PayloadTooBig: return "payload-too-big"; + case PayloadRequired: return "payload-required"; + case PendingSubscription: return "pending-subscription"; + case PresenceSubscriptionRequired: return "presence-subscription-required"; + case SubscriptionIDRequired: return "subid-required"; + case TooManySubscriptions: return "too-many-subscriptions"; + case Unsupported: return "unsupported"; + case UnsupportedAccessModel: return "unsupported-access-model"; + default: return null; + } +} + +static String serializeUnsupportedFeatureType(PubSubError.UnsupportedFeatureType value) { + switch (value) { + case UnknownUnsupportedFeatureType: assert(false); return ""; + case AccessAuthorize: return "access-authorize"; + case AccessOpen: return "access-open"; + case AccessPresence: return "access-presence"; + case AccessRoster: return "access-roster"; + case AccessWhitelist: return "access-whitelist"; + case AutoCreate: return "auto-create"; + case AutoSubscribe: return "auto-subscribe"; + case Collections: return "collections"; + case ConfigNode: return "config-node"; + case CreateAndConfigure: return "create-and-configure"; + case CreateNodes: return "create-nodes"; + case DeleteItems: return "delete-items"; + case DeleteNodes: return "delete-nodes"; + case FilteredNotifications: return "filtered-notifications"; + case GetPending: return "get-pending"; + case InstantNodes: return "instant-nodes"; + case ItemIDs: return "item-ids"; + case LastPublished: return "last-published"; + case LeasedSubscription: return "leased-subscription"; + case ManageSubscriptions: return "manage-subscriptions"; + case MemberAffiliation: return "member-affiliation"; + case MetaData: return "meta-data"; + case ModifyAffiliations: return "modify-affiliations"; + case MultiCollection: return "multi-collection"; + case MultiSubscribe: return "multi-subscribe"; + case OutcastAffiliation: return "outcast-affiliation"; + case PersistentItems: return "persistent-items"; + case PresenceNotifications: return "presence-notifications"; + case PresenceSubscribe: return "presence-subscribe"; + case Publish: return "publish"; + case PublishOptions: return "publish-options"; + case PublishOnlyAffiliation: return "publish-only-affiliation"; + case PublisherAffiliation: return "publisher-affiliation"; + case PurgeNodes: return "purge-nodes"; + case RetractItems: return "retract-items"; + case RetrieveAffiliations: return "retrieve-affiliations"; + case RetrieveDefault: return "retrieve-default"; + case RetrieveItems: return "retrieve-items"; + case RetrieveSubscriptions: return "retrieve-subscriptions"; + case Subscribe: return "subscribe"; + case SubscriptionOptions: return "subscription-options"; + case SubscriptionNotifications: return "subscription-notifications"; + default: return null; + } +} +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubEventAssociateSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventAssociateSerializer.java new file mode 100644 index 0000000..83b769b --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventAssociateSerializer.java @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubEventAssociate; + +public class PubSubEventAssociateSerializer extends GenericPayloadSerializer { +public PubSubEventAssociateSerializer(PayloadSerializerCollection serializers) { + super(PubSubEventAssociate.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubEventAssociate payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("associate", "http://jabber.org/protocol/pubsub#event"); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubEventCollectionSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventCollectionSerializer.java new file mode 100644 index 0000000..194d9bb --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventCollectionSerializer.java @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubEventAssociate; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubEventDisassociate; +import com.isode.stroke.elements.PubSubEventCollection; + +public class PubSubEventCollectionSerializer extends GenericPayloadSerializer { +public PubSubEventCollectionSerializer(PayloadSerializerCollection serializers) { + super(PubSubEventCollection.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubEventCollection payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("collection", "http://jabber.org/protocol/pubsub#event"); + + element.addNode(new XMLRawTextNode((new PubSubEventAssociateSerializer(serializers_)).serialize(payload.getAssociate()))); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + element.addNode(new XMLRawTextNode((new PubSubEventDisassociateSerializer(serializers_)).serialize(payload.getDisassociate()))); + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubEventConfigurationSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventConfigurationSerializer.java new file mode 100644 index 0000000..0876853 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventConfigurationSerializer.java @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.payloadserializers.FormSerializer; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubEventConfiguration; + +public class PubSubEventConfigurationSerializer extends GenericPayloadSerializer { +public PubSubEventConfigurationSerializer(PayloadSerializerCollection serializers) { + super(PubSubEventConfiguration.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubEventConfiguration payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("configuration", "http://jabber.org/protocol/pubsub#event"); + + element.addNode(new XMLRawTextNode((new FormSerializer()).serialize(payload.getData()))); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubEventDeleteSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventDeleteSerializer.java new file mode 100644 index 0000000..1c54016 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventDeleteSerializer.java @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubEventRedirect; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubEventDelete; + +public class PubSubEventDeleteSerializer extends GenericPayloadSerializer { +public PubSubEventDeleteSerializer(PayloadSerializerCollection serializers) { + super(PubSubEventDelete.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubEventDelete payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("delete", "http://jabber.org/protocol/pubsub#event"); + + element.addNode(new XMLRawTextNode((new PubSubEventRedirectSerializer(serializers_)).serialize(payload.getRedirects()))); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubEventDisassociateSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventDisassociateSerializer.java new file mode 100644 index 0000000..34cb3d0 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventDisassociateSerializer.java @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubEventDisassociate; + +public class PubSubEventDisassociateSerializer extends GenericPayloadSerializer { +public PubSubEventDisassociateSerializer(PayloadSerializerCollection serializers) { + super(PubSubEventDisassociate.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubEventDisassociate payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("disassociate", "http://jabber.org/protocol/pubsub#event"); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubEventItemSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventItemSerializer.java new file mode 100644 index 0000000..939f268 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventItemSerializer.java @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.Payload; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubEventItem; + +public class PubSubEventItemSerializer extends GenericPayloadSerializer { +public PubSubEventItemSerializer(PayloadSerializerCollection serializers) { + super(PubSubEventItem.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubEventItem payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("item", "http://jabber.org/protocol/pubsub#event"); + + if(payload.getPublisher() != null) { + element.setAttribute("publisher", payload.getPublisher()); + } + + for (Payload item : payload.getData()) { + element.addNode(new XMLRawTextNode(serializers_.getPayloadSerializer(item).serialize(item))); + } + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + if(payload.getID() != null) { + element.setAttribute("id", payload.getID()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubEventItemsSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventItemsSerializer.java new file mode 100644 index 0000000..9b49e59 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventItemsSerializer.java @@ -0,0 +1,50 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubEventItem; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubEventRetract; +import com.isode.stroke.elements.PubSubEventItems; + +public class PubSubEventItemsSerializer extends GenericPayloadSerializer { +public PubSubEventItemsSerializer(PayloadSerializerCollection serializers) { + super(PubSubEventItems.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubEventItems payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("items", "http://jabber.org/protocol/pubsub#event"); + + for (PubSubEventItem item : payload.getItems()) { + element.addNode(new XMLRawTextNode((new PubSubEventItemSerializer(serializers_)).serialize(item))); + } + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + for (PubSubEventRetract item : payload.getRetracts()) { + element.addNode(new XMLRawTextNode((new PubSubEventRetractSerializer(serializers_)).serialize(item))); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubEventPurgeSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventPurgeSerializer.java new file mode 100644 index 0000000..224f6f0 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventPurgeSerializer.java @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubEventPurge; + +public class PubSubEventPurgeSerializer extends GenericPayloadSerializer { +public PubSubEventPurgeSerializer(PayloadSerializerCollection serializers) { + super(PubSubEventPurge.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubEventPurge payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("purge", "http://jabber.org/protocol/pubsub#event"); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubEventRedirectSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventRedirectSerializer.java new file mode 100644 index 0000000..53d105c --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventRedirectSerializer.java @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubEventRedirect; + +public class PubSubEventRedirectSerializer extends GenericPayloadSerializer { +public PubSubEventRedirectSerializer(PayloadSerializerCollection serializers) { + super(PubSubEventRedirect.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubEventRedirect payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("redirect", "http://jabber.org/protocol/pubsub#event"); + + if(payload.getURI() != null) { + element.setAttribute("uri", payload.getURI()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubEventRetractSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventRetractSerializer.java new file mode 100644 index 0000000..dbb6bae --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventRetractSerializer.java @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubEventRetract; + +public class PubSubEventRetractSerializer extends GenericPayloadSerializer { +public PubSubEventRetractSerializer(PayloadSerializerCollection serializers) { + super(PubSubEventRetract.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubEventRetract payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("retract", "http://jabber.org/protocol/pubsub#event"); + + if(payload.getID() != null) { + element.setAttribute("id", payload.getID()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubEventSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventSerializer.java new file mode 100644 index 0000000..e7e09a3 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventSerializer.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2014, Isode Limited, London, England. + * All rights reserved. + */ +/* + * Copyright (c) 2014, Remko Tronçon. + * All rights reserved. + */ + +package com.isode.stroke.serializer.payloadserializers; + +import java.util.ArrayList; + +import com.isode.stroke.elements.PubSubEventPayload; +import com.isode.stroke.parser.payloadparsers.PubSubEvent; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.xml.XMLRawTextNode; + +public class PubSubEventSerializer extends GenericPayloadSerializer { + public PubSubEventSerializer(PayloadSerializerCollection serializer) { + super(PubSubEvent.class); + } + + protected String serializePayload(PubSubEvent payload) { + if (payload == null) { + return ""; + } + XMLElement element = new XMLElement("event", "http://jabber.org/protocol/pubsub#event"); + PubSubEventPayload p = payload.getPayload(); + + for (PayloadSerializer serializer : pubsubSerializers_) { + if (serializer.canSerialize(p)) { + element.addNode(new XMLRawTextNode(serializer.serialize(p))); + } + } + return element.serialize(); + } + + PayloadSerializerCollection serializers_; + ArrayList pubsubSerializers_ = new ArrayList(); +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubEventSubscriptionSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventSubscriptionSerializer.java new file mode 100644 index 0000000..d34bfb1 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubEventSubscriptionSerializer.java @@ -0,0 +1,75 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; +import com.isode.stroke.elements.PubSubEventSubscription; + +public class PubSubEventSubscriptionSerializer extends GenericPayloadSerializer { +public PubSubEventSubscriptionSerializer(PayloadSerializerCollection serializers) { + super(PubSubEventSubscription.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubEventSubscription payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("subscription", "http://jabber.org/protocol/pubsub#event"); + + element.setAttribute("subscription", serializeSubscriptionType(payload.getSubscription())); + + if(payload.getSubscriptionID() != null) { + element.setAttribute("subid", payload.getSubscriptionID()); + } + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + if(payload.getJID() != null) { + element.setAttribute("jid", payload.getJID().toString()); + } + + if(payload.getExpiry() != null) { + element.setAttribute("expiry", dateToString(payload.getExpiry())); + } + + return element.serialize(); +} + +private static String serializeSubscriptionType(PubSubEventSubscription.SubscriptionType value) { + switch (value) { + case None: return "none"; + case Pending: return "pending"; + case Subscribed: return "subscribed"; + case Unconfigured: return "unconfigured"; + } + return "undefined-subscriptiontype"; +} + +private static String dateToString(Date date) { + SimpleDateFormat dfm = new SimpleDateFormat("YYYY-MM-dd"); + SimpleDateFormat tfm = new SimpleDateFormat("hh:mm:ss"); + dfm.setTimeZone(TimeZone.getTimeZone("UTC")); + tfm.setTimeZone(TimeZone.getTimeZone("UTC")); + String sinceDateString = dfm.format(date) + "T" + tfm.format(date) + "Z"; + return sinceDateString; +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubItemSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubItemSerializer.java new file mode 100644 index 0000000..dc34489 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubItemSerializer.java @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.Payload; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubItem; + +public class PubSubItemSerializer extends GenericPayloadSerializer { +public PubSubItemSerializer(PayloadSerializerCollection serializers) { + super(PubSubItem.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubItem payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("item", "http://jabber.org/protocol/pubsub"); + + for (Payload item : payload.getData()) { + element.addNode(new XMLRawTextNode(serializers_.getPayloadSerializer(item).serialize(item))); + } + + if(payload.getID() != null) { + element.setAttribute("id", payload.getID()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubItemsSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubItemsSerializer.java new file mode 100644 index 0000000..6739e44 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubItemsSerializer.java @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubItem; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubItems; + +public class PubSubItemsSerializer extends GenericPayloadSerializer { +public PubSubItemsSerializer(PayloadSerializerCollection serializers) { + super(PubSubItems.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubItems payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("items", "http://jabber.org/protocol/pubsub"); + + if(payload.getMaximumItems() != null) { + element.setAttribute("max_items", payload.getMaximumItems().toString()); + } + + for (PubSubItem item : payload.getItems()) { + element.addNode(new XMLRawTextNode((new PubSubItemSerializer(serializers_)).serialize(item))); + } + + if(payload.getSubscriptionID() != null) { + element.setAttribute("subid", payload.getSubscriptionID()); + } + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubOptionsSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubOptionsSerializer.java new file mode 100644 index 0000000..2f3cb54 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubOptionsSerializer.java @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.payloadserializers.FormSerializer; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubOptions; + +public class PubSubOptionsSerializer extends GenericPayloadSerializer { +public PubSubOptionsSerializer(PayloadSerializerCollection serializers) { + super(PubSubOptions.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubOptions payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("options", "http://jabber.org/protocol/pubsub"); + + element.addNode(new XMLRawTextNode((new FormSerializer()).serialize(payload.getData()))); + + if(payload.getSubscriptionID() != null) { + element.setAttribute("subid", payload.getSubscriptionID()); + } + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + if(payload.getJID() != null) { + element.setAttribute("jid", payload.getJID().toString()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerAffiliationSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerAffiliationSerializer.java new file mode 100644 index 0000000..144a469 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerAffiliationSerializer.java @@ -0,0 +1,53 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubOwnerAffiliation; + +public class PubSubOwnerAffiliationSerializer extends GenericPayloadSerializer { +public PubSubOwnerAffiliationSerializer(PayloadSerializerCollection serializers) { + super(PubSubOwnerAffiliation.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubOwnerAffiliation payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("affiliation", "http://jabber.org/protocol/pubsub#owner"); + + if(payload.getJID() != null) { + element.setAttribute("jid", payload.getJID().toString()); + } + + element.setAttribute("affiliation", serializeType(payload.getType())); + + return element.serialize(); +} + +private static String serializeType(PubSubOwnerAffiliation.Type value) { + switch (value) { + case None: return "none"; + case Member: return "member"; + case Outcast: return "outcast"; + case Owner: return "owner"; + case Publisher: return "publisher"; + case PublishOnly: return "publish-only"; + } + return "undefined-type"; +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerAffiliationsSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerAffiliationsSerializer.java new file mode 100644 index 0000000..5c9898f --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerAffiliationsSerializer.java @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubOwnerAffiliation; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubOwnerAffiliations; + +public class PubSubOwnerAffiliationsSerializer extends GenericPayloadSerializer { +public PubSubOwnerAffiliationsSerializer(PayloadSerializerCollection serializers) { + super(PubSubOwnerAffiliations.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubOwnerAffiliations payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("affiliations", "http://jabber.org/protocol/pubsub#owner"); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + for (PubSubOwnerAffiliation item : payload.getAffiliations()) { + element.addNode(new XMLRawTextNode((new PubSubOwnerAffiliationSerializer(serializers_)).serialize(item))); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerConfigureSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerConfigureSerializer.java new file mode 100644 index 0000000..bcf03e3 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerConfigureSerializer.java @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.payloadserializers.FormSerializer; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubOwnerConfigure; + +public class PubSubOwnerConfigureSerializer extends GenericPayloadSerializer { +public PubSubOwnerConfigureSerializer(PayloadSerializerCollection serializers) { + super(PubSubOwnerConfigure.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubOwnerConfigure payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("configure", "http://jabber.org/protocol/pubsub#owner"); + + element.addNode(new XMLRawTextNode((new FormSerializer()).serialize(payload.getData()))); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerDefaultSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerDefaultSerializer.java new file mode 100644 index 0000000..3b3fe98 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerDefaultSerializer.java @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.payloadserializers.FormSerializer; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubOwnerDefault; + +public class PubSubOwnerDefaultSerializer extends GenericPayloadSerializer { +public PubSubOwnerDefaultSerializer(PayloadSerializerCollection serializers) { + super(PubSubOwnerDefault.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubOwnerDefault payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("default", "http://jabber.org/protocol/pubsub#owner"); + + element.addNode(new XMLRawTextNode((new FormSerializer()).serialize(payload.getData()))); + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerDeleteSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerDeleteSerializer.java new file mode 100644 index 0000000..6518f56 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerDeleteSerializer.java @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubOwnerRedirect; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubOwnerDelete; + +public class PubSubOwnerDeleteSerializer extends GenericPayloadSerializer { +public PubSubOwnerDeleteSerializer(PayloadSerializerCollection serializers) { + super(PubSubOwnerDelete.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubOwnerDelete payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("delete", "http://jabber.org/protocol/pubsub#owner"); + + element.addNode(new XMLRawTextNode((new PubSubOwnerRedirectSerializer(serializers_)).serialize(payload.getRedirect()))); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerPubSubSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerPubSubSerializer.java new file mode 100644 index 0000000..6a72af0 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerPubSubSerializer.java @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import java.util.ArrayList; + +import com.isode.stroke.elements.PubSubOwnerPayload; +import com.isode.stroke.elements.PubSubOwnerPubSub; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.xml.XMLRawTextNode; + +public class PubSubOwnerPubSubSerializer extends GenericPayloadSerializer { + +public PubSubOwnerPubSubSerializer(PayloadSerializerCollection serializers) +{ + super(PubSubOwnerPubSub.class); + + serializers_ = serializers; + + pubsubSerializers_.add(new PubSubOwnerConfigureSerializer(serializers)); + pubsubSerializers_.add(new PubSubOwnerSubscriptionsSerializer(serializers)); + pubsubSerializers_.add(new PubSubOwnerDefaultSerializer(serializers)); + pubsubSerializers_.add(new PubSubOwnerPurgeSerializer(serializers)); + pubsubSerializers_.add(new PubSubOwnerAffiliationsSerializer(serializers)); + pubsubSerializers_.add(new PubSubOwnerDeleteSerializer(serializers)); +} + +protected String serializePayload(PubSubOwnerPubSub payload) +{ + if (payload == null) { + return ""; + } + XMLElement element = new XMLElement("pubsub", "http://jabber.org/protocol/pubsub#owner"); + PubSubOwnerPayload p = payload.getPayload(); + for (PayloadSerializer serializer : pubsubSerializers_) { + if (serializer.canSerialize(p)) { + element.addNode(new XMLRawTextNode(serializer.serialize(p))); + } + } + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +ArrayList pubsubSerializers_ = new ArrayList(); + +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerPurgeSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerPurgeSerializer.java new file mode 100644 index 0000000..59d3d39 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerPurgeSerializer.java @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubOwnerPurge; + +public class PubSubOwnerPurgeSerializer extends GenericPayloadSerializer { +public PubSubOwnerPurgeSerializer(PayloadSerializerCollection serializers) { + super(PubSubOwnerPurge.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubOwnerPurge payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("purge", "http://jabber.org/protocol/pubsub#owner"); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerRedirectSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerRedirectSerializer.java new file mode 100644 index 0000000..a1ad660 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerRedirectSerializer.java @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubOwnerRedirect; + +public class PubSubOwnerRedirectSerializer extends GenericPayloadSerializer { +public PubSubOwnerRedirectSerializer(PayloadSerializerCollection serializers) { + super(PubSubOwnerRedirect.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubOwnerRedirect payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("redirect", "http://jabber.org/protocol/pubsub#owner"); + + if(payload.getURI() != null) { + element.setAttribute("uri", payload.getURI()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerSubscriptionSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerSubscriptionSerializer.java new file mode 100644 index 0000000..81cbec8 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerSubscriptionSerializer.java @@ -0,0 +1,51 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubOwnerSubscription; + +public class PubSubOwnerSubscriptionSerializer extends GenericPayloadSerializer { +public PubSubOwnerSubscriptionSerializer(PayloadSerializerCollection serializers) { + super(PubSubOwnerSubscription.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubOwnerSubscription payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("subscription", "http://jabber.org/protocol/pubsub#owner"); + + element.setAttribute("subscription", serializeSubscriptionType(payload.getSubscription())); + + if(payload.getJID() != null) { + element.setAttribute("jid", payload.getJID().toString()); + } + + return element.serialize(); +} + +private static String serializeSubscriptionType(PubSubOwnerSubscription.SubscriptionType value) { + switch (value) { + case None: return "none"; + case Pending: return "pending"; + case Subscribed: return "subscribed"; + case Unconfigured: return "unconfigured"; + } + return "undefined-subscriptiontype"; +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerSubscriptionsSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerSubscriptionsSerializer.java new file mode 100644 index 0000000..c66a1b0 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubOwnerSubscriptionsSerializer.java @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubOwnerSubscription; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubOwnerSubscriptions; + +public class PubSubOwnerSubscriptionsSerializer extends GenericPayloadSerializer { +public PubSubOwnerSubscriptionsSerializer(PayloadSerializerCollection serializers) { + super(PubSubOwnerSubscriptions.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubOwnerSubscriptions payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("subscriptions", "http://jabber.org/protocol/pubsub#owner"); + + for (PubSubOwnerSubscription item : payload.getSubscriptions()) { + element.addNode(new XMLRawTextNode((new PubSubOwnerSubscriptionSerializer(serializers_)).serialize(item))); + } + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubPublishSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubPublishSerializer.java new file mode 100644 index 0000000..ec71839 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubPublishSerializer.java @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubItem; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubPublish; + +public class PubSubPublishSerializer extends GenericPayloadSerializer { +public PubSubPublishSerializer(PayloadSerializerCollection serializers) { + super(PubSubPublish.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubPublish payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("publish", "http://jabber.org/protocol/pubsub"); + + for (PubSubItem item : payload.getItems()) { + element.addNode(new XMLRawTextNode((new PubSubItemSerializer(serializers_)).serialize(item))); + } + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubRetractSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubRetractSerializer.java new file mode 100644 index 0000000..87f18ce --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubRetractSerializer.java @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubItem; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubRetract; + +public class PubSubRetractSerializer extends GenericPayloadSerializer { +public PubSubRetractSerializer(PayloadSerializerCollection serializers) { + super(PubSubRetract.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubRetract payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("retract", "http://jabber.org/protocol/pubsub"); + + for (PubSubItem item : payload.getItems()) { + element.addNode(new XMLRawTextNode((new PubSubItemSerializer(serializers_)).serialize(item))); + } + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + element.setAttribute("notify", payload.isNotify() ? "true" : "false"); + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubSerializer.java new file mode 100644 index 0000000..232baa7 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubSerializer.java @@ -0,0 +1,73 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import java.util.ArrayList; + +import com.isode.stroke.elements.PubSub; +import com.isode.stroke.elements.PubSubCreate; +import com.isode.stroke.elements.PubSubPayload; +import com.isode.stroke.elements.PubSubSubscribe; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.xml.XMLRawTextNode; + +public class PubSubSerializer extends GenericPayloadSerializer { + +public PubSubSerializer(PayloadSerializerCollection serializers) { + super(PubSub.class); + + serializers_ = serializers; + + pubsubSerializers_.add(new PubSubItemsSerializer(serializers)); + pubsubSerializers_.add(new PubSubCreateSerializer(serializers)); + pubsubSerializers_.add(new PubSubPublishSerializer(serializers)); + pubsubSerializers_.add(new PubSubOptionsSerializer(serializers)); + pubsubSerializers_.add(new PubSubAffiliationsSerializer(serializers)); + pubsubSerializers_.add(new PubSubRetractSerializer(serializers)); + pubsubSerializers_.add(new PubSubDefaultSerializer(serializers)); + pubsubSerializers_.add(new PubSubSubscriptionsSerializer(serializers)); + pubsubSerializers_.add(new PubSubSubscribeSerializer(serializers)); + pubsubSerializers_.add(new PubSubUnsubscribeSerializer(serializers)); + pubsubSerializers_.add(new PubSubSubscriptionSerializer(serializers)); +} + +@Override +protected String serializePayload(PubSub payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("pubsub", "http://jabber.org/protocol/pubsub"); + PubSubPayload p = payload.getPayload(); + + for (PayloadSerializer serializer : pubsubSerializers_) { + if (serializer.canSerialize(p)) { + element.addNode(new XMLRawTextNode(serializer.serialize(p))); + PubSubCreate create = null; + if(p instanceof PubSubCreate) { + create = (PubSubCreate)p; + element.addNode(new XMLRawTextNode((new PubSubConfigureSerializer(serializers_)).serialize(create.getConfigure()))); + } + PubSubSubscribe subscribe = null; + if (p instanceof PubSubSubscribe) { + subscribe = (PubSubSubscribe)p; + element.addNode(new XMLRawTextNode((new PubSubConfigureSerializer(serializers_)).serialize(subscribe.getOptions()))); + } + } + } + return element.serialize(); +} + +ArrayList pubsubSerializers_ = new ArrayList(); +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubSubscribeOptionsSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubSubscribeOptionsSerializer.java new file mode 100644 index 0000000..40c0298 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubSubscribeOptionsSerializer.java @@ -0,0 +1,39 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubSubscribeOptions; + +public class PubSubSubscribeOptionsSerializer extends GenericPayloadSerializer { +public PubSubSubscribeOptionsSerializer(PayloadSerializerCollection serializers) { + super(PubSubSubscribeOptions.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubSubscribeOptions payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("subscribe-options", "http://jabber.org/protocol/pubsub"); + + if (payload.isRequired()) { + element.addNode(new XMLElement("required", "")); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubSubscribeSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubSubscribeSerializer.java new file mode 100644 index 0000000..9a886b9 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubSubscribeSerializer.java @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubOptions; +import com.isode.stroke.elements.PubSubSubscribe; + +public class PubSubSubscribeSerializer extends GenericPayloadSerializer { +public PubSubSubscribeSerializer(PayloadSerializerCollection serializers) { + super(PubSubSubscribe.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubSubscribe payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("subscribe", "http://jabber.org/protocol/pubsub"); + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + if(payload.getJID() != null) { + element.setAttribute("jid", payload.getJID().toString()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubSubscriptionSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubSubscriptionSerializer.java new file mode 100644 index 0000000..41e6f9d --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubSubscriptionSerializer.java @@ -0,0 +1,63 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubSubscribeOptions; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubSubscription; + +public class PubSubSubscriptionSerializer extends GenericPayloadSerializer { +public PubSubSubscriptionSerializer(PayloadSerializerCollection serializers) { + super(PubSubSubscription.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubSubscription payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("subscription", "http://jabber.org/protocol/pubsub"); + + element.setAttribute("subscription", serializeSubscriptionType(payload.getSubscription())); + + if(payload.getSubscriptionID() != null) { + element.setAttribute("subid", payload.getSubscriptionID()); + } + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + if(payload.getJID() != null) { + element.setAttribute("jid", payload.getJID().toString()); + } + + element.addNode(new XMLRawTextNode((new PubSubSubscribeOptionsSerializer(serializers_)).serialize(payload.getOptions()))); + + return element.serialize(); +} + +private static String serializeSubscriptionType(PubSubSubscription.SubscriptionType value) { + switch (value) { + case None: return "none"; + case Pending: return "pending"; + case Subscribed: return "subscribed"; + case Unconfigured: return "unconfigured"; + } + return "undefined-subscriptiontype"; +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubSubscriptionsSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubSubscriptionsSerializer.java new file mode 100644 index 0000000..2092caa --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubSubscriptionsSerializer.java @@ -0,0 +1,45 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubSubscription; +import com.isode.stroke.serializer.xml.XMLRawTextNode; +import com.isode.stroke.elements.PubSubSubscriptions; + +public class PubSubSubscriptionsSerializer extends GenericPayloadSerializer { +public PubSubSubscriptionsSerializer(PayloadSerializerCollection serializers) { + super(PubSubSubscriptions.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubSubscriptions payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("subscriptions", "http://jabber.org/protocol/pubsub"); + + for (PubSubSubscription item : payload.getSubscriptions()) { + element.addNode(new XMLRawTextNode((new PubSubSubscriptionSerializer(serializers_)).serialize(item))); + } + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/PubSubUnsubscribeSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PubSubUnsubscribeSerializer.java new file mode 100644 index 0000000..f0a8bb0 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PubSubUnsubscribeSerializer.java @@ -0,0 +1,47 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.elements.PubSubUnsubscribe; + +public class PubSubUnsubscribeSerializer extends GenericPayloadSerializer { +public PubSubUnsubscribeSerializer(PayloadSerializerCollection serializers) { + super(PubSubUnsubscribe.class); + + serializers_ = serializers; +} + +protected String serializePayload(PubSubUnsubscribe payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("unsubscribe", "http://jabber.org/protocol/pubsub"); + + if(payload.getSubscriptionID() != null) { + element.setAttribute("subid", payload.getSubscriptionID()); + } + + if(payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } + + if(payload.getJID() != null) { + element.setAttribute("jid", payload.getJID().toString()); + } + + return element.serialize(); +} + +PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/RawXMLPayloadSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/RawXMLPayloadSerializer.java index 70c405b..a52ab98 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/RawXMLPayloadSerializer.java +++ b/src/com/isode/stroke/serializer/payloadserializers/RawXMLPayloadSerializer.java @@ -14,7 +14,7 @@ import com.isode.stroke.serializer.GenericPayloadSerializer; class RawXMLPayloadSerializer extends GenericPayloadSerializer { public RawXMLPayloadSerializer() { - super(RawXMLPayloadSerializer.class); + super(RawXMLPayload.class); } @Override diff --git a/test/com/isode/stroke/pubsub/Client.java b/test/com/isode/stroke/pubsub/Client.java new file mode 100644 index 0000000..712db00 --- /dev/null +++ b/test/com/isode/stroke/pubsub/Client.java @@ -0,0 +1,107 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.pubsub; +import com.isode.stroke.client.ClientError; +import com.isode.stroke.client.ClientOptions; +import com.isode.stroke.jid.JID; +import com.isode.stroke.network.JavaNetworkFactories; +import com.isode.stroke.queries.IQRouter; +import com.isode.stroke.signals.Slot; +import com.isode.stroke.signals.Slot1; + +public class Client { + + static boolean debugInfo = false; + static boolean debugInfoXml = false; + + public Client(String name, JID jid, String password, JavaNetworkFactories networkFactories, final Slot connectCallback) { + name_ = name; + connecting_ = true; + connected_ = false; + disconnecting_ = false; + + client_ = new com.isode.stroke.client.Client(jid, password, networkFactories); + + client_.onConnected.connect(new Slot() { + public void call() { + if (debugInfo) { + System.out.println("[" + name_ + "] onConnected."); + } + connecting_ = false; + connected_ = true; + connectCallback.call(); + } + }); + + client_.onDisconnected.connect(new Slot1() { + public void call(ClientError error) { + if (debugInfo) { + System.out.println("[" + name_ + "] onDisconnected."); + } + connected_ = false; + } + }); + + client_.onDataRead.connect(new Slot1() { + public void call(String xml) { + if (!connecting_ && !disconnecting_) { + if (debugInfoXml) { + System.out.println("[" + name_ + "] Client.Read:"); + System.out.println(xml + "\n"); + } + } + } + }); + + client_.onDataWritten.connect(new Slot1() { + public void call(String xml) { + if (!connecting_ && !disconnecting_) { + if (debugInfoXml) { + System.out.println("[" + name_ + "] Client.Write:"); + System.out.println(xml + "\n"); + } + } + } + }); + + client_.connect(new ClientOptions()); + } + + void disconnect() { + disconnecting_ = true; + client_.disconnect(); + } + + boolean isConnected() { + return connected_; + } + + boolean isConnecting() { + return connecting_; + } + + JID getJID() { + return client_.getJID(); + } + + IQRouter getIQRouter() { + return client_.getIQRouter(); + } + + PubSubManager getPubSubManager() { + return client_.getPubSubManager(); + } + + com.isode.stroke.client.Client client_; + String name_; + boolean connected_; + boolean connecting_; + boolean disconnecting_; +} diff --git a/test/com/isode/stroke/pubsub/PubSubTools.java b/test/com/isode/stroke/pubsub/PubSubTools.java new file mode 100644 index 0000000..17d0896 --- /dev/null +++ b/test/com/isode/stroke/pubsub/PubSubTools.java @@ -0,0 +1,350 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.pubsub; + +import com.isode.stroke.elements.DiscoInfo; +import com.isode.stroke.elements.DiscoItems; +import com.isode.stroke.elements.ErrorPayload; +import com.isode.stroke.elements.Form; +import com.isode.stroke.elements.FormField; +import com.isode.stroke.elements.FormField.BooleanFormField; +import com.isode.stroke.elements.FormField.ListSingleFormField; +import com.isode.stroke.elements.IQ; +import com.isode.stroke.elements.Payload; +import com.isode.stroke.elements.PubSub; +import com.isode.stroke.elements.PubSubCreate; +import com.isode.stroke.elements.PubSubItem; +import com.isode.stroke.elements.PubSubItems; +import com.isode.stroke.elements.PubSubOwnerAffiliation; +import com.isode.stroke.elements.PubSubOwnerAffiliations; +import com.isode.stroke.elements.PubSubOwnerConfigure; +import com.isode.stroke.elements.PubSubOwnerDefault; +import com.isode.stroke.elements.PubSubOwnerDelete; +import com.isode.stroke.elements.PubSubOwnerPubSub; +import com.isode.stroke.elements.PubSubOwnerPurge; +import com.isode.stroke.elements.PubSubOwnerRedirect; +import com.isode.stroke.elements.PubSubOwnerSubscriptions; +import com.isode.stroke.elements.PubSubPublish; +import com.isode.stroke.elements.PubSubRetract; +import com.isode.stroke.elements.PubSubSubscribe; +import com.isode.stroke.elements.PubSubSubscriptions; +import com.isode.stroke.elements.FormField.TextSingleFormField; +import com.isode.stroke.elements.PubSubUnsubscribe; +import com.isode.stroke.jid.JID; +import com.isode.stroke.queries.GenericRequest; +import com.isode.stroke.signals.Slot2; + +public class PubSubTools { + static void create(Client client, String domain, String node, Slot2 callback) { + /* create a node on a pubsub domain */ + + PubSubCreate create = new PubSubCreate(); + create.setNode(node); + + PubSub pubSub = new PubSub(); + pubSub.setPayload(create); + + GenericRequest req = new GenericRequest(IQ.Type.Set, new JID(domain), pubSub, client.getIQRouter()); + req.onResponse.connect(callback); + req.send(); + } + + static void delete(Client client, String domain, String node, String redirectUri, Slot2 callback) { + /* delete a node on a pubsub domain */ + + PubSubOwnerDelete delete = new PubSubOwnerDelete(); + delete.setNode(node); + + if (!redirectUri.isEmpty()) { + PubSubOwnerRedirect redirect = new PubSubOwnerRedirect(); + redirect.setURI(redirectUri); + delete.setRedirect(redirect); + } + + PubSubOwnerPubSub pubSub = new PubSubOwnerPubSub(); + pubSub.setPayload(delete); + + GenericRequest req = new GenericRequest(IQ.Type.Set, new JID(domain), pubSub, client.getIQRouter()); + req.onResponse.connect(callback); + req.send(); + } + + static void itemList(Client client, String domain, Slot2 callback) { + /* use disco to list the nodes on a pubsub domain */ + + DiscoItems disco = new DiscoItems(); + + GenericRequest req = new GenericRequest(IQ.Type.Get, new JID(domain), disco, client.getIQRouter()); + req.onResponse.connect(callback); + req.send(); + } + + static void featureList(Client client, String domain, Slot2 callback) { + /* use disco to list the features of the domain */ + + DiscoInfo disco = new DiscoInfo(); + + GenericRequest req = new GenericRequest(IQ.Type.Get, new JID(domain), disco, client.getIQRouter()); + req.onResponse.connect(callback); + req.send(); + } + + static void subscriptionList(Client client, String domain, String node, Slot2 callback) { + /* list subscriptions on a pubsub node */ + + PubSubSubscriptions subscriptions = new PubSubSubscriptions(); + subscriptions.setNode(node); + + PubSub pubsub = new PubSub(); + pubsub.setPayload(subscriptions); + + GenericRequest listreq = new GenericRequest(IQ.Type.Get, new JID(domain), pubsub, client.getIQRouter()); + listreq.onResponse.connect(callback); + listreq.send(); + } + + static void ownerSubscriptionlist(Client client, String domain, String node, Slot2 callback) { + /* list subscriptions on a pubsub node */ + + PubSubOwnerSubscriptions ownerSubscription = new PubSubOwnerSubscriptions(); + ownerSubscription.setNode(node); + + PubSubOwnerPubSub pubsub = new PubSubOwnerPubSub(); + pubsub.setPayload(ownerSubscription); + + GenericRequest listreq = new GenericRequest(IQ.Type.Get, new JID(domain), pubsub, client.getIQRouter()); + listreq.onResponse.connect(callback); + listreq.send(); + } + + static void subscribe(Client client, String domain, String node, Slot2 callback) { + /* subscribe to a pubsub node */ + + PubSubSubscribe subscribe = new PubSubSubscribe(); + subscribe.setJID(client.getJID()); + subscribe.setNode(node); + + PubSub pubsub = new PubSub(); + pubsub.setPayload(subscribe); + + GenericRequest subreq = new GenericRequest(IQ.Type.Set, new JID(domain), pubsub, client.getIQRouter()); + subreq.onResponse.connect(callback); + subreq.send(); + } + + static void unsubscribe(Client client, String domain, String node, Slot2 callback) { + /* ubsubscribe from a pubsub node */ + + PubSubUnsubscribe subscribe = new PubSubUnsubscribe(); + subscribe.setJID(client.getJID()); + subscribe.setNode(node); + + PubSub pubsub = new PubSub(); + pubsub.setPayload(subscribe); + + GenericRequest subreq = new GenericRequest(IQ.Type.Set, new JID(domain), pubsub, client.getIQRouter()); + subreq.onResponse.connect(callback); + subreq.send(); + } + + static void ownerConfigure(Client client, String domain, String node, Form form, Slot2 callback) { + /* set/get the current configuration for a node on a pubsub domain */ + + PubSubOwnerConfigure config = new PubSubOwnerConfigure(); + config.setNode(node); + + IQ.Type type; + if (form == null) { + type = IQ.Type.Get; /* configuration request */ + config.setData(new Form()); + } else { + type = IQ.Type.Set; /* setting the configuration */ + config.setData(form); + } + + PubSubOwnerPubSub pubSub = new PubSubOwnerPubSub(); + pubSub.setPayload(config); + + GenericRequest req = new GenericRequest(type, new JID(domain), pubSub, client.getIQRouter()); + req.onResponse.connect(callback); + req.send(); + } + + static void ownerConfigure(final Client client, final String domain, final String node, final String parameter, final String newValue, final Slot2 callback) { + /* change a parameter for a node on a pubsub domain */ + + ownerConfigure(client, domain, node, null, new Slot2() { /* make a request to get the current configuration */ + public void call(PubSubOwnerPubSub pubSub, ErrorPayload error) { + if (pubSub == null) { + callback.call(null, new ErrorPayload()); + } + PubSubOwnerConfigure config = (PubSubOwnerConfigure)pubSub.getPayload(); + Form form = config.getData(); + for (FormField field : form.getFields()) { + if (field.getName().equals(parameter)) { + if (field instanceof TextSingleFormField) { /* find and update the specified parameter */ + TextSingleFormField fieldText = (TextSingleFormField)field; + fieldText.setValue(newValue); + } else if (field instanceof ListSingleFormField) { + ListSingleFormField fieldList = (ListSingleFormField)field; + fieldList.setValue(newValue); + } else if (field instanceof BooleanFormField) { + BooleanFormField fieldBoolean = (BooleanFormField)field; + fieldBoolean.setValue(newValue.equals("1")); + } + } + } + ownerConfigure(client, domain, node, form, callback); /* request the configuration to be changed */ + } + }); + } + + static void ownerDefaultConfiguration(Client client, String domain, final Slot2 callback) { + /* retrieve the default configuration for nodes on the domain */ + + PubSubOwnerDefault ownerDefault = new PubSubOwnerDefault(); + ownerDefault.setData(new Form()); + + PubSubOwnerPubSub pubSub = new PubSubOwnerPubSub(); + pubSub.setPayload(ownerDefault); + + GenericRequest req = new GenericRequest(IQ.Type.Get, new JID(domain), pubSub, client.getIQRouter()); + req.onResponse.connect(new Slot2() { + public void call(PubSubOwnerPubSub pubSub, ErrorPayload error) { + if (pubSub!=null && pubSub.getPayload()!=null) { + PubSubOwnerDefault defaultConfig = (PubSubOwnerDefault)pubSub.getPayload(); + callback.call(defaultConfig.getData(), error); + } else { + callback.call(null, error); + } + + } + }); + req.send(); + } + + static void ownerSetAffiliations(Client client, String domain, String node, JID subscriber, PubSubOwnerAffiliation.Type type, Slot2 callback) { + /* set the affiliations for a subscriber to a node on a domain */ + + PubSubOwnerAffiliation affiliation = new PubSubOwnerAffiliation(); + affiliation.setJID(subscriber); + affiliation.setType(type); + + PubSubOwnerAffiliations affiliations = new PubSubOwnerAffiliations(); + affiliations.setNode(node); + affiliations.addAffiliation(affiliation); + + PubSubOwnerPubSub pubSub = new PubSubOwnerPubSub(); + pubSub.setPayload(affiliations); + + GenericRequest req = new GenericRequest(IQ.Type.Set, new JID(domain), pubSub, client.getIQRouter()); + req.onResponse.connect(callback); + req.send(); + } + + static void ownerGetAffiliations(Client client, String domain, String node, Slot2 callback) { + /* get the affiliations for a subscriber to a node on a domain */ + + PubSubOwnerAffiliations affiliations = new PubSubOwnerAffiliations(); + affiliations.setNode(node); + + PubSubOwnerPubSub pubSub = new PubSubOwnerPubSub(); + pubSub.setPayload(affiliations); + + GenericRequest req = new GenericRequest(IQ.Type.Get, new JID(domain), pubSub, client.getIQRouter()); + req.onResponse.connect(callback); + req.send(); + } + + static void publish(Client client, String domain, String node, String id, Payload payload, Slot2 callback) { + /* publish some data to a node */ + + PubSubItem items = new PubSubItem(); + items.addData(payload); + items.setID(id); + + PubSubPublish publish = new PubSubPublish(); + publish.addItem(items); + publish.setNode(node); + + PubSub pubSub = new PubSub(); + pubSub.setPayload(publish); + + GenericRequest req = new GenericRequest(IQ.Type.Set, new JID(domain), pubSub, client.getIQRouter()); + req.onResponse.connect(callback); + req.send(); + } + + static void retract(Client client, String domain, String node, String id, boolean notify, Slot2 callback) { + /* delete an item from a node */ + + PubSubItem item = new PubSubItem(); + item.setID(id); + + PubSubRetract retract = new PubSubRetract(); + retract.setNode(node); + retract.addItem(item); + retract.setNotify(notify); + + PubSub pubSub = new PubSub(); + pubSub.setPayload(retract); + + GenericRequest req = new GenericRequest(IQ.Type.Set, new JID(domain), pubSub, client.getIQRouter()); + req.onResponse.connect(callback); + req.send(); + } + + static void getItems(Client client, String domain, String node, long maxResults, Slot2 callback) { + /* retrieve maxResults items from a node */ + + PubSubItems items = new PubSubItems(); + items.setNode(node); + items.setMaximumItems(maxResults); + + PubSub pubSub = new PubSub(); + pubSub.setPayload(items); + + GenericRequest req = new GenericRequest(IQ.Type.Get, new JID(domain), pubSub, client.getIQRouter()); + req.onResponse.connect(callback); + req.send(); + } + + static void getItem(Client client, String domain, String node, String id, Slot2 callback) { + /* retrieve a specific item from a node */ + + PubSubItem pubSubItem = new PubSubItem(); + pubSubItem.setID(id); + + PubSubItems items = new PubSubItems(); + items.setNode(node); + items.addItem(pubSubItem); + + PubSub pubSub = new PubSub(); + pubSub.setPayload(items); + + GenericRequest req = new GenericRequest(IQ.Type.Get, new JID(domain), pubSub, client.getIQRouter()); + req.onResponse.connect(callback); + req.send(); + } + + static void purge(Client client, String domain, String node, Slot2 callback) { + /* purge all items on a node */ + + PubSubOwnerPurge purge = new PubSubOwnerPurge(); + purge.setNode(node); + + PubSubOwnerPubSub pubSub = new PubSubOwnerPubSub(); + pubSub.setPayload(purge); + + GenericRequest req = new GenericRequest(IQ.Type.Get, new JID(domain), pubSub, client.getIQRouter()); + req.onResponse.connect(callback); + req.send(); + } +} diff --git a/test/com/isode/stroke/pubsub/TestCase.java b/test/com/isode/stroke/pubsub/TestCase.java new file mode 100644 index 0000000..0dc48de --- /dev/null +++ b/test/com/isode/stroke/pubsub/TestCase.java @@ -0,0 +1,28 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.pubsub; +import com.isode.stroke.eventloop.Event; + +public class TestCase { + TestCase(String name, Event.Callback routine) { + name_ = name; + routine_ = routine; + } + + String getName() { + return name_; + } + + Event.Callback getRoutine() { + return routine_; + } + String name_; + Event.Callback routine_; +} diff --git a/test/com/isode/stroke/pubsub/TestMain.java b/test/com/isode/stroke/pubsub/TestMain.java new file mode 100644 index 0000000..2088898 --- /dev/null +++ b/test/com/isode/stroke/pubsub/TestMain.java @@ -0,0 +1,839 @@ +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ +/* +* Copyright (c) 2014, Remko Tronçon. +* All rights reserved. +*/ + +package com.isode.stroke.pubsub; + +import java.util.ArrayList; +import java.util.List; + +import com.isode.stroke.elements.DiscoInfo; +import com.isode.stroke.elements.DiscoItems; +import com.isode.stroke.elements.DiscoItems.Item; +import com.isode.stroke.elements.ErrorPayload; +import com.isode.stroke.elements.Form; +import com.isode.stroke.elements.Payload; +import com.isode.stroke.elements.PubSub; +import com.isode.stroke.elements.PubSubEventItem; +import com.isode.stroke.elements.PubSubEventItems; +import com.isode.stroke.elements.PubSubEventPayload; +import com.isode.stroke.elements.PubSubEventRetract; +import com.isode.stroke.elements.PubSubItem; +import com.isode.stroke.elements.PubSubItems; +import com.isode.stroke.elements.PubSubOwnerAffiliation; +import com.isode.stroke.elements.PubSubOwnerAffiliations; +import com.isode.stroke.elements.PubSubOwnerPubSub; +import com.isode.stroke.elements.PubSubOwnerSubscription; +import com.isode.stroke.elements.PubSubOwnerSubscriptions; +import com.isode.stroke.elements.PubSubPublish; +import com.isode.stroke.elements.PubSubSubscriptions; +import com.isode.stroke.elements.RawXMLPayload; +import com.isode.stroke.elements.SoftwareVersion; +import com.isode.stroke.eventloop.DummyEventLoop; +import com.isode.stroke.eventloop.Event; +import com.isode.stroke.jid.JID; +import com.isode.stroke.network.JavaNetworkFactories; +import com.isode.stroke.signals.Slot; +import com.isode.stroke.signals.Slot2; + +public class TestMain { + + /* begin test parameters */ + static String _server = "stan.isode.net"; + static String _pubJID = "test1@stan.isode.net"; + static String _pubPass = "password"; + static String _subJID = "test2@stan.isode.net"; + static String _subPass = "password"; + static String _pubSubDomain = "pubsub.stan.isode.net"; + static String _pubSubNode = "testnode"; + /* end test parameters */ + + static DummyEventLoop eventLoop_ = new DummyEventLoop(); + static ArrayList testRoutines_ = new ArrayList(); + static int testRoutinesIndex_; + static Client clientPub_; + static Client clientSub_; + static boolean shutdown_; + + static class ShutdownEvent implements Event.Callback { + public void run() { + shutdown_ = true; + beginNextTest(); + } + }; + + static class NodeCreate implements Event.Callback { + public void run() { + /* create a temporary pubsub node */ + PubSubTools.create(clientPub_, _pubSubDomain, _pubSubNode, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + /* we do not assert here, since failing tests can leave old nodes hanging */ + /* change the access mode to 'open' */ + PubSubTools.ownerConfigure(clientPub_, _pubSubDomain, _pubSubNode, "pubsub#access_model", "open", new Slot2() { + public void call(PubSubOwnerPubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to change node access mode to 'open'.")) { + return; + } + /* change the number of items to return to '10' */ + PubSubTools.ownerConfigure(clientPub_, _pubSubDomain, _pubSubNode, "pubsub#max_items", "10", new Slot2() { + public void call(PubSubOwnerPubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to change node 'max_items'.")) { + return; + } + /* enable retract notifications */ + PubSubTools.ownerConfigure(clientPub_, _pubSubDomain, _pubSubNode, "pubsub#notify_retract", "1", new Slot2() { + public void call(PubSubOwnerPubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to change node 'notify_retract'.")) { + return; + } + beginNextTest(); + } + }); + } + }); + } + }); + } + }); + } + }; + + static class NodeDelete implements Event.Callback { + public void run() { + PubSubTools.delete(clientPub_, _pubSubDomain, _pubSubNode, "", new Slot2() { + public void call(PubSubOwnerPubSub pubSub, ErrorPayload error) { + beginNextTest(); + } + }); + } + }; + + static boolean assertTest(boolean cond, String reason) { + if (!cond) { + System.out.println("\n-----BEGIN TEST FAILURE REPORT-----\n"); + System.out.println("Name: " + testRoutines_.get(testRoutinesIndex_-1).getName() + "\n"); + System.out.println("Reason: " + reason + "\n"); + System.out.println("-----END TEST FAILURE REPORT-----\n"); + eventLoop_.postEvent(new ShutdownEvent()); + } + return cond; + } + + static void beginNextTest() { + /* return to the main loop and kick off the next test */ + + String testName = testRoutines_.get(testRoutinesIndex_).getName(); + if (!testName.isEmpty()) { + System.out.println("Test complete: " + testName); + } + + if (testRoutinesIndex_ < testRoutines_.size()) { + TestCase nextTest = testRoutines_.get(testRoutinesIndex_); + eventLoop_.postEvent(nextTest.getRoutine()); + testRoutinesIndex_++; + } + } + + static void addTest(String name, final Event.Callback routine) { + /* create a temporary pubsub node and configure it, run the test case, then delete the item afterwards */ + + testRoutines_.add(new TestCase("", new NodeCreate())); + testRoutines_.add(new TestCase(name, routine)); + testRoutines_.add(new TestCase("", new NodeDelete())); + } + + static boolean compareItems(Payload ax, String ay, Payload bx, String by) { + /* compare two item payload's and id's for equality */ + + if (!(ax instanceof SoftwareVersion) || !(bx instanceof SoftwareVersion)) { + return false; + } + SoftwareVersion az = (SoftwareVersion)ax; + SoftwareVersion bz = (SoftwareVersion)bx; + if (!az.getName().equals(bz.getName())) { + return false; + } + if (!az.getVersion().equals(bz.getVersion())) { + return false; + } + if (!az.getOS().equals(bz.getOS())) { + return false; + } + if (!ay.equals(by)) { + return false; + } + return true; + } + + static boolean compareJID(JID a, JID b) { + return a.compare(b, JID.CompareType.WithoutResource) == 0; + } + + static void testEntityUseCases() { + //-------------------------------------------------------------------------------- + //-- 5. Entity use cases + //-------------------------------------------------------------------------------- + + addTest("5.2 List nodes", new Event.Callback() { + public void run() { + PubSubTools.itemList(clientSub_, _server, new Slot2() { + public void call(DiscoItems items, ErrorPayload error) { + if (!assertTest(items!=null, "Service discovery failed.")) { + return; + } + if (!assertTest(items.getItems().size()>0, "There are no services on this domain.")) { + return; + } + System.out.println("Services at " + _server + ":"); + boolean foundTestService = false; + for (Item item : items.getItems()) { + String jid = item.getJID().toString(); + if (!item.getName().isEmpty()) { + System.out.println("\t" + jid + " (" + item.getName() + ")"); + } else { + System.out.println("\t" + jid); + } + if (jid.equals(_pubSubDomain)) { + foundTestService = true; + } + } + System.out.println(""); + if (!assertTest(foundTestService, "The service could not be found.")) { + return; + } + beginNextTest(); + } + }); + } + }); + + addTest("5.5 Discover items of node", new Event.Callback() { + public void run() { + PubSubTools.itemList(clientPub_, _pubSubDomain, new Slot2() { + public void call(DiscoItems items, ErrorPayload error) { + if (!assertTest(error==null, "Failed to retreieve pubsub node items.")) { + return; + } + if (!assertTest(items.getItems().size()>0, "There are no nodes on this domain.")) { + return; + } + System.out.println("Services at " + _pubSubDomain + ":"); + boolean foundTestService = false; + for (Item item : items.getItems()) { + System.out.println("\t" + item.getNode()); + if (item.getNode().equals(_pubSubNode)) { + foundTestService = true; + } + } + System.out.println(""); + if (!assertTest(foundTestService, "The service could not be found.")) { + return; + } + beginNextTest(); + } + }); + } + }); + + addTest("5.6 Subscriptions", new Event.Callback() { + public void run() { + PubSubTools.subscribe(clientSub_, _pubSubDomain, _pubSubNode, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to subscribe to a node.")) { + return; + } + PubSubTools.subscriptionList(clientSub_, _pubSubDomain, _pubSubNode, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null && pubSub!=null, "Failed to list subscriptions on a node.")) { + return; + } + PubSubSubscriptions results = (PubSubSubscriptions)pubSub.getPayload(); + if (!assertTest(results.getSubscriptions().size() == 1, "Unexpected subscription count.")) { + return; + } + beginNextTest(); + } + }); + } + }); + } + }); + } + + static void testSubscriberUseCases() { + //-------------------------------------------------------------------------------- + //-- 6. Subscriber use cases + //-------------------------------------------------------------------------------- + + addTest("6.1 Subscribe to a node", new Event.Callback() { + public void run() { + PubSubTools.subscribe(clientSub_, _pubSubDomain, _pubSubNode, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null && pubSub!=null, "Failed to subscribe to a node.")) { + return; + } + beginNextTest(); + } + }); + } + }); + + addTest("6.2 Unsubscribe from a node", new Event.Callback() { + public void run() { + PubSubTools.subscribe(clientSub_, _pubSubDomain, _pubSubNode, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null && pubSub!=null, "Failed to subscribe to a node.")) { + return; + } + PubSubTools.unsubscribe(clientSub_, _pubSubDomain, _pubSubNode, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to unsubscribe from a node.")) { + return; + } + beginNextTest(); + } + }); + } + }); + } + }); + + addTest("6.5 Retrieve items of a node", new Event.Callback() { + public void run() { /* publish 2 items, then retrieve them, making sure that we get back what we sent */ + final String publishItem1Id = "item_id"; + final SoftwareVersion publishItem1Payload = new SoftwareVersion("MyTest1", "1.0", "Java"); + PubSubTools.publish(clientPub_, _pubSubDomain, _pubSubNode, publishItem1Id, publishItem1Payload, new Slot2() { + public void call(PubSubPublish publish, ErrorPayload error) { + if (!assertTest(error==null, "Failed to publish item.")) { + return; + } + final String publishItem2Id = "item_id2"; + final SoftwareVersion publishItem2Payload = new SoftwareVersion("MyTest2", "2.0", "Java"); + PubSubTools.publish(clientPub_, _pubSubDomain, _pubSubNode, publishItem2Id, publishItem2Payload, new Slot2() { + public void call(PubSubPublish publish, ErrorPayload error) { + if (!assertTest(error==null, "Failed to publish item.")) { + return; + } + PubSubTools.getItems(clientSub_, _pubSubDomain, _pubSubNode, 2, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to retrieve items.")) { + return; + } + PubSubItems itemsPayload = (PubSubItems)pubSub.getPayload(); + List items = itemsPayload.getItems(); + if (!assertTest(items.size()==2, "Incorrect number of items.")) { + return; + } + Payload payload1 = items.get(0).getData().get(0); + if (!assertTest(compareItems(payload1, items.get(0).getID(), publishItem1Payload, publishItem1Id), "Invalid item received.")) { + return; + } + Payload payload2 = items.get(1).getData().get(0); + if (!assertTest(compareItems(payload2, items.get(1).getID(), publishItem2Payload, publishItem2Id), "Invalid item received.")) { + return; + } + beginNextTest(); + } + }); + }; + }); + } + }); + } + }); + + addTest("6.5.7 Requesting most recent items", new Event.Callback() { + public void run() { /* publish 3 items, then retrieve 2 of them, making sure that we receive the 2 most recent items published */ + final String publishItem1Id = "item_id"; + final SoftwareVersion publishItem1Payload = new SoftwareVersion("MyTest1", "1.0", "Java"); + PubSubTools.publish(clientPub_, _pubSubDomain, _pubSubNode, publishItem1Id, publishItem1Payload, new Slot2() { + public void call(PubSubPublish publish, ErrorPayload error) { + if (!assertTest(error==null, "Failed to publish item.")) { + return; + } + final String publishItem2Id = "item_id2"; + final SoftwareVersion publishItem2Payload = new SoftwareVersion("MyTest2", "2.0", "Java"); + PubSubTools.publish(clientPub_, _pubSubDomain, _pubSubNode, publishItem2Id, publishItem2Payload, new Slot2() { + public void call(PubSubPublish publish, ErrorPayload error) { + if (!assertTest(error==null, "Failed to publish item.")) { + return; + } + final String publishItem3Id = "item_id3"; + final SoftwareVersion publishItem3Payload = new SoftwareVersion("MyTest3", "3.0", "Java"); + PubSubTools.publish(clientPub_, _pubSubDomain, _pubSubNode, publishItem3Id, publishItem3Payload, new Slot2() { + public void call(PubSubPublish publish, ErrorPayload error) { + if (!assertTest(error==null, "Failed to publish item.")) { + return; + } + PubSubTools.getItems(clientSub_, _pubSubDomain, _pubSubNode, 2, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to retrieve items.")) { + return; + } + PubSubItems itemsPayload = (PubSubItems)pubSub.getPayload(); + List items = itemsPayload.getItems(); + if (!assertTest(items.size()==2, "Incorrect number of items.")) { + return; + } + Payload payload1 = items.get(0).getData().get(0); + if (!assertTest(compareItems(payload1, items.get(0).getID(), publishItem2Payload, publishItem2Id), "Invalid item received.")) { + return; + } + Payload payload2 = items.get(1).getData().get(0); + if (!assertTest(compareItems(payload2, items.get(1).getID(), publishItem3Payload, publishItem3Id), "Invalid item received.")) { + return; + } + beginNextTest(); + } + }); + } + }); + }; + }); + } + }); + } + }); + + addTest("6.5.8 requesting specific item", new Event.Callback() { + public void run() { /* publish 2 items, then ask for a specific item, making sure that we get back what we sent */ + final String publishItem1Id = "item_id"; + final SoftwareVersion publishItem1Payload = new SoftwareVersion("MyTest1", "1.0", "Java"); + PubSubTools.publish(clientPub_, _pubSubDomain, _pubSubNode, publishItem1Id, publishItem1Payload, new Slot2() { + public void call(PubSubPublish publish, ErrorPayload error) { + if (!assertTest(error==null, "Failed to publish item.")) { + return; + } + final String publishItem2Id = "item_id2"; + final SoftwareVersion publishItem2Payload = new SoftwareVersion("MyTest2", "2.0", "Java"); + PubSubTools.publish(clientPub_, _pubSubDomain, _pubSubNode, publishItem2Id, publishItem2Payload, new Slot2() { + public void call(PubSubPublish publish, ErrorPayload error) { + if (!assertTest(error==null, "Failed to publish item.")) { + return; + } + PubSubTools.getItem(clientSub_, _pubSubDomain, _pubSubNode, publishItem2Id, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to retrieve items.")) { + return; + } + PubSubItems itemsPayload = (PubSubItems)pubSub.getPayload(); + List items = itemsPayload.getItems(); + if (!assertTest(items.size()==1, "Incorrect number of items.")) { + return; + } + Payload payload2 = items.get(0).getData().get(0); + if (!assertTest(compareItems(payload2, items.get(0).getID(), publishItem2Payload, publishItem2Id), "Invalid item received.")) { + return; + } + beginNextTest(); + } + }); + }; + }); + } + }); + } + }); + } + + static void testPublisherUseCases() { + //-------------------------------------------------------------------------------- + //-- 7. Publisher use cases + //-------------------------------------------------------------------------------- + + addTest("7.1 Publish item to a node", new Event.Callback() { + public void run() { /* register a pubsub event handler callback and publish an item to the node, making sure we get back the same data */ + final String publishItemId = "item_id"; + final SoftwareVersion publishItemPayload = new SoftwareVersion("MyTest", "1.0", "Java"); + final PubSubManager clientPubManager = clientSub_.getPubSubManager(); + clientPubManager.onEvent.connect(new Slot2() { + public void call(JID jid, PubSubEventPayload payload) { + if (payload instanceof PubSubEventItems) { + PubSubEventItems items = (PubSubEventItems)payload; + if (items.getNode().equals(_pubSubNode) && items.getItems().size()>0) { + PubSubEventItem item = items.getItems().get(0); + Payload itemPayload = item.getData().get(0); + if (itemPayload instanceof SoftwareVersion) { + SoftwareVersion version = (SoftwareVersion)itemPayload; + if (!assertTest(compareItems(version, item.getID(), publishItemPayload, publishItemId), "Item data mismatch.")) { + return; + } + System.out.println("\tGot publish notification.\n"); + clientPubManager.onEvent.disconnectAll(); + beginNextTest(); + } + } + } + } + }); + PubSubTools.subscribe(clientSub_, _pubSubDomain, _pubSubNode, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to subscribe to a node.")) { + return; + } + PubSubTools.publish(clientPub_, _pubSubDomain, _pubSubNode, publishItemId, publishItemPayload, new Slot2() { + public void call(PubSubPublish pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to publish item to a node.")) { + return; + } + System.out.println("\tWaiting for publish notification..."); + } + }); + } + }); + } + }); + + addTest("7.2 Delete item from a node", new Event.Callback() { + public void run() { /* subscribe to a node, publish an item, then 'retract' (delete) it */ + PubSubTools.subscribe(clientSub_, _pubSubDomain, _pubSubNode, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to subscribe to a node.")) { + return; + } + final String publishItemId = "item_id"; + SoftwareVersion publishItemPayload = new SoftwareVersion("MyTest", "1.0", "Java"); + PubSubTools.publish(clientPub_, _pubSubDomain, _pubSubNode, publishItemId, publishItemPayload, new Slot2() { + public void call(PubSubPublish pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to publish item to a node.")) { + return; + } + PubSubTools.retract(clientPub_, _pubSubDomain, _pubSubNode, publishItemId, true, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to retract item from a node.")) { + return; + } + beginNextTest(); + } + }); + } + }); + } + }); + } + }); + + addTest("7.2.2.1 Delete and notify", new Event.Callback() { + public void run() { /* register a pubsub event handler callback and retract an item to the node, check that we are notified */ + final String publishItemId = "item_id"; + final SoftwareVersion publishItemPayload = new SoftwareVersion("MyTest", "1.0", "Java"); + final PubSubManager clientPubManager = clientSub_.getPubSubManager(); + clientPubManager.onEvent.connect(new Slot2() { + public void call(JID jid, PubSubEventPayload payload) { + if (payload instanceof PubSubEventItems) { + PubSubEventItems items = (PubSubEventItems)payload; + List retracts = items.getRetracts(); + if (items.getNode().equals(_pubSubNode) && retracts.size()==1) { + if (!assertTest(retracts.get(0).getID().equals(publishItemId), "Unexpected retract item.")) { + return; + } + System.out.println("\tGot retract notification.\n"); + clientPubManager.onEvent.disconnectAll(); + beginNextTest(); + } + } + } + }); + PubSubTools.subscribe(clientSub_, _pubSubDomain, _pubSubNode, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to subscribe to a node.")) { + return; + } + PubSubTools.publish(clientPub_, _pubSubDomain, _pubSubNode, publishItemId, publishItemPayload, new Slot2() { + public void call(PubSubPublish pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to publish item to a node.")) { + return; + } + PubSubTools.retract(clientPub_, _pubSubDomain, _pubSubNode, publishItemId, true, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to retract item from a node.")) { + return; + } + System.out.println("Waiting for retract notification..."); + } + }); + } + }); + } + }); + } + }); + + addTest("Publish an unknown element type", new Event.Callback() { + public void run() { /* subscribe to a node and publish raw xml, making sure we get back the data in the handler */ + final String publishItemId = "item_id"; + final RawXMLPayload publishItemPayload = new RawXMLPayload(); + publishItemPayload.setRawXML( + "" + + "Down the Rabbit Hole" + + "" + + "Alice was beginning to get very tired of sitting by her sister on the" + + "bank and of having nothing to do: once or twice she had peeped into the" + + "book her sister was reading, but it had no pictures or conversations in" + + "it, \"and what is the use of a book,\" thought Alice, \"without pictures" + + "or conversations?\'" + + "" + + "" + + "tag:gutenberg.org,2008:entry-1234" + + "2008-06-25T18:30:02Z" + + "2008-06-25T18:30:02Z" + + "" + ); + final PubSubManager clientPubManager = clientSub_.getPubSubManager(); + clientPubManager.onEvent.connect(new Slot2() { + public void call(JID jid, PubSubEventPayload payload) { + if (payload instanceof PubSubEventItems) { + PubSubEventItems items = (PubSubEventItems)payload; + List itemList = items.getItems(); + if (itemList.size() > 0) { + List payloads = itemList.get(0).getData(); + if (payloads.size() > 0) { + if (payloads.get(0) instanceof RawXMLPayload) { + System.out.println("\tGot publish notification.\n"); + clientPubManager.onEvent.disconnectAll(); + beginNextTest(); + } + } + } + } + } + }); + PubSubTools.subscribe(clientSub_, _pubSubDomain, _pubSubNode, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to subscribe to a node.")) { + return; + } + PubSubTools.publish(clientPub_, _pubSubDomain, _pubSubNode, publishItemId, publishItemPayload, new Slot2() { + public void call(PubSubPublish pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to publish item to a node.")) { + return; + } + System.out.println("Waiting for publish notification..."); + } + }); + } + }); + } + }); + } + + static void testOwnerUseCases() { + //-------------------------------------------------------------------------------- + //-- 8 Owner Use Cases + //-------------------------------------------------------------------------------- + + //-- 8.1 Create a node + //-- Create node with default config + //-- Create node with custom config + //-- 8.2 Configure node + // ^ not applicable ^ exist as separate tests in Sluift, but already used as part of the other tests + + addTest("8.3 Request Default Node Configuration Options", new Event.Callback() { + public void run() { + PubSubTools.ownerDefaultConfiguration(clientPub_, _pubSubDomain, new Slot2() { + public void call(Form config, ErrorPayload error) { + if (!assertTest(error==null && config!=null, "Failed to retrieve default configuration.")) { + return; + } + beginNextTest(); + } + }); + } + }); + + addTest("8.4 Delete node - with redirection", new Event.Callback() { + public void run() { + PubSubTools.subscribe(clientSub_, _pubSubDomain, _pubSubNode, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to subscribe to a node.")) { + return; + } + PubSubTools.delete(clientPub_, _pubSubDomain, _pubSubNode, "foo@bar.com", new Slot2() { + public void call(PubSubOwnerPubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to delete a node.")) { + return; + } + beginNextTest(); + } + }); + } + }); + } + }); + + // NOT IMPLEMENTED + // addTest("8.5 Purge node items", new Event.Callback() { + // public void run() { /* publish 2 items, then purge the node */ + // PubSubTools.subscribe(clientSub_, _pubSubDomain, _pubSubNode, new Slot2() { + // public void call(PubSub pubSub, ErrorPayload error) { + // if (!assertTest(error==null, "Failed to subscribe to a node.")) { + // return; + // } + // final String publishItem1Id = "item_id"; + // final SoftwareVersion publishItem1Payload = new SoftwareVersion("MyTest1", "1.0", "Java"); + // PubSubTools.publish(clientPub_, _pubSubDomain, _pubSubNode, publishItem1Id, publishItem1Payload, new Slot2() { + // public void call(PubSubPublish publish, ErrorPayload error) { + // if (!assertTest(error==null, "Failed to publish item.")) { + // return; + // } + // final String publishItem2Id = "item_id2"; + // final SoftwareVersion publishItem2Payload = new SoftwareVersion("MyTest2", "2.0", "Java"); + // PubSubTools.publish(clientPub_, _pubSubDomain, _pubSubNode, publishItem2Id, publishItem2Payload, new Slot2() { + // public void call(PubSubPublish publish, ErrorPayload error) { + // if (!assertTest(error==null, "Failed to publish item.")) { + // return; + // } + // PubSubTools.purge(clientPub_, _pubSubDomain, _pubSubNode, new Slot2() { + // public void call(PubSubOwnerPubSub pubSub, ErrorPayload error) { + // if (!assertTest(error==null, "Failed to purge node items.")) { + // return; + // } + // beginNextTest(); + // } + // }); + // } + // }); + // } + // }); + // } + // }); + // } + // }); + + addTest("8.8 Manage Subscriptions", new Event.Callback() { + public void run() { + PubSubTools.subscribe(clientSub_, _pubSubDomain, _pubSubNode, new Slot2() { + public void call(PubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to subscribe to a node.")) { + return; + } + PubSubTools.ownerSubscriptionlist(clientPub_, _pubSubDomain, _pubSubNode, new Slot2() { + public void call(PubSubOwnerPubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to retrieve subscription list.")) { + return; + } + System.out.println("Subscriptions to " + _pubSubNode + " on " + _pubSubDomain + ":"); + PubSubOwnerSubscriptions subscriptionPayload = (PubSubOwnerSubscriptions)pubSub.getPayload(); + ArrayList subscriptionList = subscriptionPayload.getSubscriptions(); + for (PubSubOwnerSubscription subscription : subscriptionList) { + System.out.println("\t" + subscription.getJID() + " (" + subscription.getSubscription().toString() + ")"); + } + System.out.println(""); + beginNextTest(); + } + }); + } + }); + } + }); + + addTest("8.9 Manage Affiliations", new Event.Callback() { + public void run() { + PubSubTools.ownerSetAffiliations(clientPub_, _pubSubDomain, _pubSubNode, clientSub_.getJID(), PubSubOwnerAffiliation.Type.Publisher, new Slot2() { + public void call(PubSubOwnerPubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to set affiliation.")) { + return; + } + PubSubTools.ownerGetAffiliations(clientPub_, _pubSubDomain, _pubSubNode, new Slot2() { + public void call(PubSubOwnerPubSub pubSub, ErrorPayload error) { + if (!assertTest(error==null, "Failed to retrieve affiliations.")) { + return; + } + PubSubOwnerAffiliations affiliationsPayload = (PubSubOwnerAffiliations)pubSub.getPayload(); + ArrayList affiliations = affiliationsPayload.getAffiliations(); + if (!assertTest(affiliations.size()==2, "Unexpected affiliation count.")) { + return; + } + PubSubOwnerAffiliation affiliationPub = affiliations.get(0); + if (!assertTest(compareJID(affiliationPub.getJID(),clientPub_.getJID()), "Unexpected affiliation JID.")) { + return; + } + if (!assertTest(affiliationPub.getType() == PubSubOwnerAffiliation.Type.Owner, "Unexpected affiliation type.")) { + return; + } + PubSubOwnerAffiliation affiliationSub = affiliations.get(1); + if (!assertTest(compareJID(affiliationSub.getJID(),clientSub_.getJID()), "Unexpected affiliation JID.")) { + return; + } + if (!assertTest(affiliationSub.getType() == PubSubOwnerAffiliation.Type.Publisher, "Unexpected affiliation type.")) { + return; + } + beginNextTest(); + } + }); + } + }); + } + }); + } + + public static void main(String[] args) { + /* print server supported features */ + + addTest("Query Domain Features", new Event.Callback() { + public void run() { + PubSubTools.featureList(clientSub_, _pubSubDomain, new Slot2() { + public void call(DiscoInfo info, ErrorPayload error) { + if (!assertTest(error==null, "Failed to retrieve server feature list.")) { + return; + } + System.out.println("List of features at " + _pubSubDomain + ":"); + for (String feature : info.getFeatures()) { + System.out.println("\t" + feature); + } + System.out.println(""); + beginNextTest(); + }; + }); + } + }); + + /* set up test cases */ + + testEntityUseCases(); + testSubscriberUseCases(); + testPublisherUseCases(); + testOwnerUseCases(); + + /* the final "test" disconnects the clients */ + + addTest("ShutdownEvent", new ShutdownEvent()); + + /* connect the client and begin the tests */ + + JavaNetworkFactories networkFactories = new JavaNetworkFactories(eventLoop_); + + Slot connectCallback = new Slot() { + public void call() { + if (clientPub_!=null && clientPub_.isConnected() && clientSub_!=null && clientSub_.isConnected()) { + beginNextTest(); /* kick off the tests once both clients are connected */ + } + } + }; + + clientPub_ = new Client("PUBLISHER", new JID(_pubJID), _pubPass, networkFactories, connectCallback); + clientSub_ = new Client("SUBSCRIBER", new JID(_subJID), _subPass, networkFactories, connectCallback); + + while (!shutdown_) { + eventLoop_.processEvents(); + } + + clientSub_.disconnect(); + clientPub_.disconnect(); + + /* the tests are over */ + + if (testRoutinesIndex_ == testRoutines_.size()) { + System.out.println("\n-----BEGIN TEST REPORT-----\n"); + System.out.println("Success: The tests completed.\n"); + System.out.println("-----END TEST REPORT-----\n"); + } + + System.out.println("Finished."); + } +} -- cgit v0.10.2-6-g49f6