summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Maudsley <richard.maudsley@isode.com>2014-02-04 09:49:24 (GMT)
committerRichard Maudsley <richard.maudsley@isode.com>2014-03-07 14:28:58 (GMT)
commita511087b1f57f1f6372374f41d0b4b7ebeef9930 (patch)
treea319c6c65f4c4722635f78ac564a823a370d011c /src/com/isode/stroke/parser/payloadparsers/PubSubOwnerAffiliationParser.java
parent535e1a979a164f807aa64bf2df2bb36e7015ff17 (diff)
downloadstroke-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/PubSubOwnerAffiliationParser.java')
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/PubSubOwnerAffiliationParser.java86
1 files changed, 86 insertions, 0 deletions
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_;
+}