diff options
author | Richard Maudsley <richard.maudsley@isode.com> | 2014-02-04 09:49:24 (GMT) |
---|---|---|
committer | Richard Maudsley <richard.maudsley@isode.com> | 2014-03-07 14:28:58 (GMT) |
commit | a511087b1f57f1f6372374f41d0b4b7ebeef9930 (patch) | |
tree | a319c6c65f4c4722635f78ac564a823a370d011c /src/com/isode/stroke/parser/payloadparsers | |
parent | 535e1a979a164f807aa64bf2df2bb36e7015ff17 (diff) | |
download | stroke-a511087b1f57f1f6372374f41d0b4b7ebeef9930.zip stroke-a511087b1f57f1f6372374f41d0b4b7ebeef9930.tar.bz2 |
PubSub parsers and serializers, plus manager and test code.
Change-Id: Ie8ca77ba8dbcd83926d46307ad0e73d804ff7422
Diffstat (limited to 'src/com/isode/stroke/parser/payloadparsers')
41 files changed, 2978 insertions, 1 deletions
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<MUCDestroyPayloadParser>("destroy", "http://jabber.org/protocol/muc#owner",MUCDestroyPayloadParser.class)); - //addFactory(new NicknameParserFactory()); + addFactory(new GenericPayloadParserFactory2<PubSubParser>("pubsub", "http://jabber.org/protocol/pubsub", this, PubSubParser.class)); + addFactory(new GenericPayloadParserFactory2<PubSubOwnerPubSubParser>("pubsub", "http://jabber.org/protocol/pubsub#owner", this, PubSubOwnerPubSubParser.class)); + addFactory(new GenericPayloadParserFactory2<PubSubEventParser>("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<PubSubAffiliation> { +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<PubSubAffiliations> { +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<PubSubConfigure> { +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<PubSubCreate> { +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<PubSubDefault> { +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<PubSubError> { + +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<String, PubSubError.Type> typeParser_ = new HashMap<String, PubSubError.Type>(); +HashMap<String, PubSubError.UnsupportedFeatureType> unsupportedTypeParser_ = new HashMap<String, PubSubError.UnsupportedFeatureType>(); +} 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<PubSubEventPayload> { + +} 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<PubSubEventAssociate> { +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<PubSubEventCollection> { +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<PubSubEventConfiguration> { +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<PubSubEventDelete> { +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<PubSubEventDisassociate> { +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<PubSubEventItem> { +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<PubSubEventItems> { +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<PubSubEvent> { + +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<PubSubEventPurge> { +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<PubSubEventRedirect> { +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<PubSubEventRetract> { +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<PubSubEventSubscription> { +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<PubSubItem> { +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<PubSubItems> { +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<PubSubOptions> { +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<PubSubOwnerAffiliation> { +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<PubSubOwnerAffiliations> { +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<PubSubOwnerConfigure> { +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<PubSubOwnerDefault> { +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<PubSubOwnerDelete> { +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<PubSubOwnerPurge> { +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<PubSubOwnerRedirect> { +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<PubSubOwnerSubscription> { +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<PubSubOwnerSubscriptions> { +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<PubSub> { + + 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<PubSubPublish> { +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<PubSubRetract> { +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<PubSubSubscribeOptions> { +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<PubSubSubscribe> { +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<PubSubSubscription> { +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<PubSubSubscriptions> { +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<PubSubUnsubscribe> { +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_; +} |