summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/isode/stroke/elements/CarbonsDisable.java19
-rw-r--r--src/com/isode/stroke/elements/CarbonsEnable.java19
-rw-r--r--src/com/isode/stroke/elements/CarbonsPrivate.java19
-rw-r--r--src/com/isode/stroke/elements/CarbonsReceived.java43
-rw-r--r--src/com/isode/stroke/elements/CarbonsSent.java43
-rw-r--r--src/com/isode/stroke/elements/Thread.java78
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/CarbonsDisableParser.java51
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/CarbonsEnableParser.java51
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/CarbonsPrivateParser.java51
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/CarbonsReceivedParser.java80
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/CarbonsSentParser.java80
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java6
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/ThreadParser.java69
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/CarbonsDisableSerializer.java30
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/CarbonsEnableSerializer.java30
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/CarbonsPrivateSerializer.java30
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/CarbonsReceivedSerializer.java37
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/CarbonsSentSerializer.java37
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java7
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/ThreadSerializer.java33
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/CarbonsParserTest.java138
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/CarbonsSerializerTest.java138
22 files changed, 1089 insertions, 0 deletions
diff --git a/src/com/isode/stroke/elements/CarbonsDisable.java b/src/com/isode/stroke/elements/CarbonsDisable.java
new file mode 100644
index 0000000..d88d14f
--- /dev/null
+++ b/src/com/isode/stroke/elements/CarbonsDisable.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.elements;
+
+import com.isode.stroke.elements.Payload;
+
+public class CarbonsDisable extends Payload {
+
+
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/elements/CarbonsEnable.java b/src/com/isode/stroke/elements/CarbonsEnable.java
new file mode 100644
index 0000000..a637439
--- /dev/null
+++ b/src/com/isode/stroke/elements/CarbonsEnable.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.elements;
+
+import com.isode.stroke.elements.Payload;
+
+public class CarbonsEnable extends Payload {
+
+
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/elements/CarbonsPrivate.java b/src/com/isode/stroke/elements/CarbonsPrivate.java
new file mode 100644
index 0000000..bf8e473
--- /dev/null
+++ b/src/com/isode/stroke/elements/CarbonsPrivate.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.elements;
+
+import com.isode.stroke.elements.Payload;
+
+public class CarbonsPrivate extends Payload {
+
+
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/elements/CarbonsReceived.java b/src/com/isode/stroke/elements/CarbonsReceived.java
new file mode 100644
index 0000000..5e36583
--- /dev/null
+++ b/src/com/isode/stroke/elements/CarbonsReceived.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.elements;
+
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.elements.Forwarded;
+import com.isode.stroke.base.NotNull;
+
+public class CarbonsReceived extends Payload {
+
+ private Forwarded forwarded_;
+
+ /**
+ * Default Constructor.
+ */
+ public CarbonsReceived() {
+
+ }
+
+ /**
+ * @param forwarded, Not Null.
+ */
+ public void setForwarded(Forwarded forwarded) {
+ NotNull.exceptIfNull(forwarded, "forwarded");
+ forwarded_ = forwarded;
+ }
+
+ /**
+ * @return forwarded, Not Null.
+ */
+ public Forwarded getForwarded() {
+ return forwarded_;
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/elements/CarbonsSent.java b/src/com/isode/stroke/elements/CarbonsSent.java
new file mode 100644
index 0000000..1d7d846
--- /dev/null
+++ b/src/com/isode/stroke/elements/CarbonsSent.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.elements;
+
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.elements.Forwarded;
+import com.isode.stroke.base.NotNull;
+
+public class CarbonsSent extends Payload {
+
+ private Forwarded forwarded_;
+
+ /**
+ * Default Constructor.
+ */
+ public CarbonsSent() {
+
+ }
+
+ /**
+ * @param forwarded, Not Null.
+ */
+ public void setForwarded(Forwarded forwarded) {
+ NotNull.exceptIfNull(forwarded, "forwarded");
+ forwarded_ = forwarded;
+ }
+
+ /**
+ * @return forwarded, Not Null.
+ */
+ public Forwarded getForwarded() {
+ return forwarded_;
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/elements/Thread.java b/src/com/isode/stroke/elements/Thread.java
new file mode 100644
index 0000000..40eeb8b
--- /dev/null
+++ b/src/com/isode/stroke/elements/Thread.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.elements;
+
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.base.NotNull;
+
+public class Thread extends Payload {
+
+ private String text_ = "";
+ private String parent_ = "";
+
+ /**
+ * Default Constructor.
+ */
+ public Thread() {
+ this("", "");
+ }
+
+ /**
+ * Parameterized Constructor.
+ * @param text, Not Null.
+ */
+ public Thread(String text) {
+ this(text, "");
+ }
+
+ /**
+ * Parameterized Constructor.
+ * @param text, Not Null.
+ * @param parent, not Null.
+ */
+ public Thread(String text, String parent) {
+ NotNull.exceptIfNull(text, "text");
+ NotNull.exceptIfNull(parent, "parent");
+ this.text_ = text;
+ this.parent_ = parent;
+ }
+
+ /**
+ * @param text, not Null.
+ */
+ public void setText(String text) {
+ NotNull.exceptIfNull(text, "text");
+ text_ = text;
+ }
+
+ /**
+ * @return text, not Null.
+ */
+ public String getText() {
+ return text_;
+ }
+
+ /**
+ * @param parent, not Null.
+ */
+ public void setParent(String parent) {
+ NotNull.exceptIfNull(parent, "parent");
+ parent_ = parent;
+ }
+
+ /**
+ * @return parent, not Null.
+ */
+ public String getParent() {
+ return parent_;
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/CarbonsDisableParser.java b/src/com/isode/stroke/parser/payloadparsers/CarbonsDisableParser.java
new file mode 100644
index 0000000..e61a0c6
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/CarbonsDisableParser.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.parser.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.elements.CarbonsDisable;
+import com.isode.stroke.base.NotNull;
+
+public class CarbonsDisableParser extends GenericPayloadParser<CarbonsDisable> {
+
+ public CarbonsDisableParser() {
+ super(new CarbonsDisable());
+ }
+
+ /**
+ * @param element.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+
+ }
+
+ /**
+ * @param element.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+
+ }
+
+ /**
+ * @param data.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/CarbonsEnableParser.java b/src/com/isode/stroke/parser/payloadparsers/CarbonsEnableParser.java
new file mode 100644
index 0000000..39240a7
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/CarbonsEnableParser.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.parser.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.elements.CarbonsEnable;
+import com.isode.stroke.base.NotNull;
+
+public class CarbonsEnableParser extends GenericPayloadParser<CarbonsEnable> {
+
+ public CarbonsEnableParser() {
+ super(new CarbonsEnable());
+ }
+
+ /**
+ * @param element.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+
+ }
+
+ /**
+ * @param element.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+
+ }
+
+ /**
+ * @param data.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/CarbonsPrivateParser.java b/src/com/isode/stroke/parser/payloadparsers/CarbonsPrivateParser.java
new file mode 100644
index 0000000..be8df74
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/CarbonsPrivateParser.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.parser.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.elements.CarbonsPrivate;
+import com.isode.stroke.base.NotNull;
+
+public class CarbonsPrivateParser extends GenericPayloadParser<CarbonsPrivate> {
+
+ public CarbonsPrivateParser() {
+ super(new CarbonsPrivate());
+ }
+
+ /**
+ * @param element.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+
+ }
+
+ /**
+ * @param element.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+
+ }
+
+ /**
+ * @param data.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/CarbonsReceivedParser.java b/src/com/isode/stroke/parser/payloadparsers/CarbonsReceivedParser.java
new file mode 100644
index 0000000..e5ba2b6
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/CarbonsReceivedParser.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.parser.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.payloadparsers.ForwardedParser;
+import com.isode.stroke.elements.CarbonsReceived;
+import com.isode.stroke.base.NotNull;
+
+public class CarbonsReceivedParser extends GenericPayloadParser<CarbonsReceived> {
+
+ private final int TopLevel = 0;
+ private final int PayloadLevel = 1;
+ private int level_ = TopLevel;
+ private PayloadParserFactoryCollection factories_;
+ private ForwardedParser forwardedParser_;
+
+ public CarbonsReceivedParser(PayloadParserFactoryCollection factories) {
+ super(new CarbonsReceived());
+ this.factories_ = factories;
+ this.level_ = TopLevel;
+ }
+
+ /**
+ * @param element.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(element, "element");
+ if (level_ == PayloadLevel) {
+ if (element.equals("forwarded")) {
+ forwardedParser_ = (ForwardedParser)(new ForwardedParser(factories_));
+ }
+ }
+ if (forwardedParser_ != null) {
+ forwardedParser_.handleStartElement(element, ns, attributes);
+ }
+ ++level_;
+ }
+
+ /**
+ * @param element.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+ --level_;
+ if (forwardedParser_ != null && level_ >= PayloadLevel) {
+ forwardedParser_.handleEndElement(element, ns);
+ }
+ if (forwardedParser_ != null && level_ == PayloadLevel) {
+ /* done parsing nested stanza */
+ getPayloadInternal().setForwarded(forwardedParser_.getPayloadInternal());
+ forwardedParser_ = null;
+ }
+ }
+
+ /**
+ * @param data.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+ if (forwardedParser_ != null) {
+ forwardedParser_.handleCharacterData(data);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/CarbonsSentParser.java b/src/com/isode/stroke/parser/payloadparsers/CarbonsSentParser.java
new file mode 100644
index 0000000..879e580
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/CarbonsSentParser.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.parser.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.PayloadParserFactoryCollection;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.parser.payloadparsers.ForwardedParser;
+import com.isode.stroke.elements.CarbonsSent;
+import com.isode.stroke.base.NotNull;
+
+public class CarbonsSentParser extends GenericPayloadParser<CarbonsSent> {
+
+ private final int TopLevel = 0;
+ private final int PayloadLevel = 1;
+ private int level_ = TopLevel;
+ private PayloadParserFactoryCollection factories_;
+ private ForwardedParser forwardedParser_;
+
+ public CarbonsSentParser(PayloadParserFactoryCollection factories) {
+ super(new CarbonsSent());
+ this.factories_ = factories;
+ this.level_ = TopLevel;
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(element, "element");
+ if (level_ == PayloadLevel) {
+ if (element.equals("forwarded")) {
+ forwardedParser_ = (ForwardedParser)(new ForwardedParser(factories_));
+ }
+ }
+ if (forwardedParser_ != null) {
+ forwardedParser_.handleStartElement(element, ns, attributes);
+ }
+ ++level_;
+ }
+
+ /**
+ * @param element.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+ --level_;
+ if (forwardedParser_ != null && level_ >= PayloadLevel) {
+ forwardedParser_.handleEndElement(element, ns);
+ }
+ if (forwardedParser_ != null && level_ == PayloadLevel) {
+ /* done parsing nested stanza */
+ getPayloadInternal().setForwarded(forwardedParser_.getPayloadInternal());
+ forwardedParser_ = null;
+ }
+ }
+
+ /**
+ * @param data.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+ if (forwardedParser_ != null) {
+ forwardedParser_.handleCharacterData(data);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
index f5ae485..d6d6483 100644
--- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
+++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
@@ -14,6 +14,11 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl
public FullPayloadParserFactoryCollection() {
/* TODO: Port more */
//addFactory(new GenericPayloadParserFactory<IBBParser>("", "http://jabber.org/protocol/ibb"));
+ addFactory(new GenericPayloadParserFactory<CarbonsDisableParser>("disable", "urn:xmpp:carbons:2", CarbonsDisableParser.class));
+ addFactory(new GenericPayloadParserFactory<CarbonsEnableParser>("enable", "urn:xmpp:carbons:2", CarbonsEnableParser.class));
+ addFactory(new GenericPayloadParserFactory<CarbonsPrivateParser>("private", "urn:xmpp:carbons:2", CarbonsPrivateParser.class));
+ addFactory(new GenericPayloadParserFactory2<CarbonsReceivedParser>("received", "urn:xmpp:carbons:2", this, CarbonsReceivedParser.class));
+ addFactory(new GenericPayloadParserFactory2<CarbonsSentParser>("sent", "urn:xmpp:carbons:2", this, CarbonsSentParser.class));
addFactory(new GenericPayloadParserFactory<StatusShowParser>("show", StatusShowParser.class));
addFactory(new GenericPayloadParserFactory<StatusParser>("status", StatusParser.class));
addFactory(new GenericPayloadParserFactory<ReplaceParser>("replace", "http://swift.im/protocol/replace", ReplaceParser.class));
@@ -50,6 +55,7 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl
addFactory(new GenericPayloadParserFactory<InBandRegistrationPayloadParser>("query", "jabber:iq:register", InBandRegistrationPayloadParser.class));
addFactory(new SearchPayloadParserFactory());
//addFactory(new StreamInitiationParserFactory());
+ addFactory(new GenericPayloadParserFactory<ThreadParser>("thread", ThreadParser.class));
addFactory(new GenericPayloadParserFactory<BytestreamsParser>("query", "http://jabber.org/protocol/bytestreams", BytestreamsParser.class));
addFactory(new GenericPayloadParserFactory<VCardUpdateParser>("x", "vcard-temp:x:update", VCardUpdateParser.class));
addFactory(new GenericPayloadParserFactory<VCardParser>("vCard", "vcard-temp", VCardParser.class));
diff --git a/src/com/isode/stroke/parser/payloadparsers/ThreadParser.java b/src/com/isode/stroke/parser/payloadparsers/ThreadParser.java
new file mode 100644
index 0000000..094e1e5
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/ThreadParser.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.parser.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.elements.Thread;
+import com.isode.stroke.base.NotNull;
+
+public class ThreadParser extends GenericPayloadParser<Thread> {
+
+ private int level_ = 0;
+ private String text_ = "";
+
+ public ThreadParser() {
+ super(new Thread());
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ * @param attributes, NotNull.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(element, "element");
+ NotNull.exceptIfNull(attributes, "attributes");
+ ++level_;
+ if (element.equals("thread")) {
+ if(attributes.getAttributeValue("parent") != null) {
+ getPayloadInternal().setParent(attributes.getAttributeValue("parent"));
+ } else {
+ getPayloadInternal().setParent("");
+ }
+ }
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+ --level_;
+ if (level_ == 0) {
+ getPayloadInternal().setText(text_);
+ }
+ }
+
+ /**
+ * @param data, NotNull.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+ NotNull.exceptIfNull(data, "data");
+ if (level_ == 1) {
+ text_ += data;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/serializer/payloadserializers/CarbonsDisableSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/CarbonsDisableSerializer.java
new file mode 100644
index 0000000..94cb014
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/CarbonsDisableSerializer.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.serializer.payloadserializers;
+
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.serializer.xml.XMLTextNode;
+import com.isode.stroke.serializer.xml.XMLElement;
+import com.isode.stroke.elements.CarbonsDisable;
+import com.isode.stroke.base.NotNull;
+
+public class CarbonsDisableSerializer extends GenericPayloadSerializer<CarbonsDisable> {
+
+ public CarbonsDisableSerializer() {
+ super(CarbonsDisable.class);
+ }
+
+ public String serializePayload(CarbonsDisable payload) {
+ XMLElement element = new XMLElement("disable", "urn:xmpp:carbons:2");
+ return element.serialize();
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/serializer/payloadserializers/CarbonsEnableSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/CarbonsEnableSerializer.java
new file mode 100644
index 0000000..f88e461
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/CarbonsEnableSerializer.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.serializer.payloadserializers;
+
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.serializer.xml.XMLTextNode;
+import com.isode.stroke.serializer.xml.XMLElement;
+import com.isode.stroke.elements.CarbonsEnable;
+import com.isode.stroke.base.NotNull;
+
+public class CarbonsEnableSerializer extends GenericPayloadSerializer<CarbonsEnable> {
+
+ public CarbonsEnableSerializer() {
+ super(CarbonsEnable.class);
+ }
+
+ public String serializePayload(CarbonsEnable payload) {
+ XMLElement element = new XMLElement("enable", "urn:xmpp:carbons:2");
+ return element.serialize();
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/serializer/payloadserializers/CarbonsPrivateSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/CarbonsPrivateSerializer.java
new file mode 100644
index 0000000..eeb2c3f
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/CarbonsPrivateSerializer.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.serializer.payloadserializers;
+
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.serializer.xml.XMLTextNode;
+import com.isode.stroke.serializer.xml.XMLElement;
+import com.isode.stroke.elements.CarbonsPrivate;
+import com.isode.stroke.base.NotNull;
+
+public class CarbonsPrivateSerializer extends GenericPayloadSerializer<CarbonsPrivate> {
+
+ public CarbonsPrivateSerializer() {
+ super(CarbonsPrivate.class);
+ }
+
+ public String serializePayload(CarbonsPrivate payload) {
+ XMLElement element = new XMLElement("private", "urn:xmpp:carbons:2");
+ return element.serialize();
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/serializer/payloadserializers/CarbonsReceivedSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/CarbonsReceivedSerializer.java
new file mode 100644
index 0000000..aa15010
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/CarbonsReceivedSerializer.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.serializer.payloadserializers;
+
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.serializer.PayloadSerializerCollection;
+import com.isode.stroke.serializer.xml.XMLRawTextNode;
+import com.isode.stroke.serializer.xml.XMLElement;
+import com.isode.stroke.elements.CarbonsReceived;
+import com.isode.stroke.base.NotNull;
+
+public class CarbonsReceivedSerializer extends GenericPayloadSerializer<CarbonsReceived> {
+
+ private PayloadSerializerCollection serializers_;
+
+ public CarbonsReceivedSerializer(PayloadSerializerCollection serializers) {
+ super(CarbonsReceived.class);
+ this.serializers_ = serializers;
+ }
+
+ public String serializePayload(CarbonsReceived received) {
+ XMLElement element = new XMLElement("received", "urn:xmpp:carbons:2");
+ if (received.getForwarded() != null) {
+ element.addNode(new XMLRawTextNode(new ForwardedSerializer(serializers_).serialize(received.getForwarded())));
+ }
+ return element.serialize();
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/serializer/payloadserializers/CarbonsSentSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/CarbonsSentSerializer.java
new file mode 100644
index 0000000..ac4b47a
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/CarbonsSentSerializer.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.serializer.payloadserializers;
+
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.serializer.PayloadSerializerCollection;
+import com.isode.stroke.serializer.xml.XMLRawTextNode;
+import com.isode.stroke.serializer.xml.XMLElement;
+import com.isode.stroke.elements.CarbonsSent;
+import com.isode.stroke.base.NotNull;
+
+public class CarbonsSentSerializer extends GenericPayloadSerializer<CarbonsSent> {
+
+ private PayloadSerializerCollection serializers_;
+
+ public CarbonsSentSerializer(PayloadSerializerCollection serializers) {
+ super(CarbonsSent.class);
+ this.serializers_ = serializers;
+ }
+
+ public String serializePayload(CarbonsSent sent) {
+ XMLElement element = new XMLElement("sent", "urn:xmpp:carbons:2");
+ if (sent.getForwarded() != null) {
+ element.addNode(new XMLRawTextNode(new ForwardedSerializer(serializers_).serialize(sent.getForwarded())));
+ }
+ return element.serialize();
+ }
+} \ No newline at end of file
diff --git a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
index 9ad402c..64b17d1 100644
--- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
+++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
@@ -20,6 +20,11 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection
addSerializer(new BodySerializer());
addSerializer(new SubjectSerializer());
addSerializer(new ChatStateSerializer());
+ addSerializer(new CarbonsDisableSerializer());
+ addSerializer(new CarbonsEnableSerializer());
+ addSerializer(new CarbonsPrivateSerializer());
+ addSerializer(new CarbonsReceivedSerializer(this));
+ addSerializer(new CarbonsSentSerializer(this));
//addSerializer(new PrioritySerializer());
addSerializer(new ErrorSerializer());
addSerializer(new InBandRegistrationPayloadSerializer());
@@ -48,7 +53,9 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection
addSerializer(new StartSessionSerializer());
addSerializer(new SecurityLabelSerializer());
addSerializer(new SecurityLabelsCatalogSerializer());
+ //addSerializer(new StreamInitiationFileInfoSerializer());
//addSerializer(new StreamInitiationSerializer());
+ addSerializer(new ThreadSerializer());
addSerializer(new BytestreamsSerializer());
addSerializer(new VCardSerializer());
addSerializer(new VCardUpdateSerializer());
diff --git a/src/com/isode/stroke/serializer/payloadserializers/ThreadSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/ThreadSerializer.java
new file mode 100644
index 0000000..93c6004
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/ThreadSerializer.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.serializer.payloadserializers;
+
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.serializer.xml.XMLTextNode;
+import com.isode.stroke.serializer.xml.XMLElement;
+import com.isode.stroke.elements.Thread;
+import com.isode.stroke.base.NotNull;
+
+public class ThreadSerializer extends GenericPayloadSerializer<Thread> {
+
+ public ThreadSerializer() {
+ super(Thread.class);
+ }
+
+ public String serializePayload(Thread thread) {
+ XMLElement threadNode = new XMLElement("thread", "", thread.getText());
+ if (thread.getParent().length() != 0) {
+ threadNode.setAttribute("parent", thread.getParent());
+ }
+ return threadNode.serialize();
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/CarbonsParserTest.java b/test/com/isode/stroke/parser/payloadparsers/CarbonsParserTest.java
new file mode 100644
index 0000000..226db1f
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/CarbonsParserTest.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.parser.payloadparsers;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import org.junit.Test;
+import com.isode.stroke.elements.Message;
+import com.isode.stroke.elements.Thread;
+import com.isode.stroke.elements.Forwarded;
+import com.isode.stroke.elements.CarbonsEnable;
+import com.isode.stroke.elements.CarbonsDisable;
+import com.isode.stroke.elements.CarbonsReceived;
+import com.isode.stroke.elements.CarbonsSent;
+import com.isode.stroke.elements.CarbonsPrivate;
+import com.isode.stroke.jid.JID;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+
+public class CarbonsParserTest {
+
+ public CarbonsParserTest() {
+
+ }
+
+ /*
+ * Test parsing of example 3 in XEP-0280.
+ */
+ @Test
+ public void testParseExample3() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<enable xmlns='urn:xmpp:carbons:2' />"));
+
+ CarbonsEnable enable = (CarbonsEnable)parser.getPayload();
+ assertNotNull(enable);
+ }
+
+ /*
+ * Test parsing of example 6 in XEP-0280.
+ */
+ @Test
+ public void testParseExample6() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<disable xmlns='urn:xmpp:carbons:2' />"));
+
+ CarbonsDisable disable = (CarbonsDisable)parser.getPayload();
+ assertNotNull(disable);
+ }
+
+ /*
+ * Test parsing of example 12 in XEP-0280.
+ */
+ @Test
+ public void testParseExample12() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<received xmlns='urn:xmpp:carbons:2'>" +
+ "<forwarded xmlns='urn:xmpp:forward:0'>" +
+ "<message xmlns='jabber:client'" +
+ " from='juliet@capulet.example/balcony'" +
+ " to='romeo@montague.example/garden'" +
+ " type='chat'>" +
+ "<body>What man art thou that, thus bescreen'd in night, so stumblest on my counsel?</body>" +
+ "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" +
+ "</message>" +
+ "</forwarded>" +
+ "</received>"));
+
+ CarbonsReceived received = (CarbonsReceived)parser.getPayload();
+ assertNotNull(received);
+
+ Forwarded forwarded = received.getForwarded();
+ assertNotNull(forwarded);
+
+ Message message = (Message)(forwarded.getStanza());
+ assertNotNull(message);
+ assertEquals(new JID("juliet@capulet.example/balcony"), message.getFrom());
+
+ Thread thread = message.getPayload(new Thread());
+ assertNotNull(thread);
+ assertEquals("0e3141cd80894871a68e6fe6b1ec56fa", thread.getText());
+ }
+
+ /*
+ * Test parsing of example 14 in XEP-0280.
+ */
+ @Test
+ public void testParseExample14() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<sent xmlns='urn:xmpp:carbons:2'>" +
+ "<forwarded xmlns='urn:xmpp:forward:0'>" +
+ "<message xmlns='jabber:client'" +
+ " to='juliet@capulet.example/balcony'" +
+ " from='romeo@montague.example/home'" +
+ " type='chat'>" +
+ "<body>Neither, fair saint, if either thee dislike.</body>" +
+ "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" +
+ "</message>" +
+ "</forwarded>" +
+ "</sent>"));
+
+ CarbonsSent sent = (CarbonsSent)parser.getPayload();
+ assertNotNull(sent);
+
+ Forwarded forwarded = sent.getForwarded();
+ assertNotNull(forwarded);
+
+ Message message = (Message)(forwarded.getStanza());
+ assertNotNull(message);
+ assertEquals(new JID("juliet@capulet.example/balcony"), message.getTo());
+ }
+
+ /*
+ * Test parsing of example 15 in XEP-0280.
+ */
+ @Test
+ public void testParseExample15() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertNotNull(parser.parse("<private xmlns='urn:xmpp:carbons:2'/>"));
+
+ CarbonsPrivate privae = (CarbonsPrivate)parser.getPayload();
+ assertNotNull(privae);
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/CarbonsSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/CarbonsSerializerTest.java
new file mode 100644
index 0000000..8f57b77
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/CarbonsSerializerTest.java
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 2015 Isode Limited.
+ * All rights reserved.
+ * See the COPYING file for more information.
+ */
+/*
+ * Copyright (c) 2015 Tarun Gupta.
+ * Licensed under the simplified BSD license.
+ * See Documentation/Licenses/BSD-simplified.txt for more information.
+ */
+
+package com.isode.stroke.serializer.payloadserializers;
+
+import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+import com.isode.stroke.elements.Message;
+import com.isode.stroke.elements.Thread;
+import com.isode.stroke.elements.Forwarded;
+import com.isode.stroke.elements.CarbonsEnable;
+import com.isode.stroke.elements.CarbonsDisable;
+import com.isode.stroke.elements.CarbonsReceived;
+import com.isode.stroke.elements.CarbonsSent;
+import com.isode.stroke.elements.CarbonsPrivate;
+import com.isode.stroke.serializer.payloadserializers.FullPayloadSerializerCollection;
+import com.isode.stroke.serializer.payloadserializers.CarbonsEnableSerializer;
+import com.isode.stroke.serializer.payloadserializers.CarbonsDisableSerializer;
+import com.isode.stroke.serializer.payloadserializers.CarbonsReceivedSerializer;
+import com.isode.stroke.serializer.payloadserializers.CarbonsSentSerializer;
+import com.isode.stroke.serializer.payloadserializers.CarbonsPrivateSerializer;
+import com.isode.stroke.jid.JID;
+
+public class CarbonsSerializerTest {
+
+ private FullPayloadSerializerCollection serializers = new FullPayloadSerializerCollection();
+
+ /**
+ * Default Constructor.
+ */
+ public CarbonsSerializerTest() {
+
+ }
+
+ /*
+ * Test serializing of example 3 in XEP-0280.
+ */
+ @Test
+ public void testSerializeExample3() {
+ CarbonsEnableSerializer testling = new CarbonsEnableSerializer();
+
+ assertEquals("<enable xmlns=\"urn:xmpp:carbons:2\"/>", testling.serialize(new CarbonsEnable()));
+ }
+
+ /*
+ * Test serializing of example 6 in XEP-0280.
+ */
+ @Test
+ public void testSerializeExample6() {
+ CarbonsDisableSerializer testling = new CarbonsDisableSerializer();
+
+ assertEquals("<disable xmlns=\"urn:xmpp:carbons:2\"/>", testling.serialize(new CarbonsDisable()));
+ }
+
+ /*
+ * Test serializing of example 12 in XEP-0280.
+ */
+ @Test
+ public void testSerializeExample12() {
+ CarbonsReceivedSerializer testling = new CarbonsReceivedSerializer(serializers);
+
+ CarbonsReceived received = new CarbonsReceived();
+
+ Forwarded forwarded = new Forwarded();
+
+ Message message = new Message();
+ message.setFrom(new JID("juliet@capulet.example/balcony"));
+ message.setTo(new JID("romeo@montague.example/garden"));
+ message.setBody("What man art thou that, thus bescreen'd in night, so stumblest on my counsel?");
+ message.addPayload(new Thread("0e3141cd80894871a68e6fe6b1ec56fa"));
+
+ forwarded.setStanza(message);
+ received.setForwarded(forwarded);
+
+ assertEquals(
+ "<received xmlns=\"urn:xmpp:carbons:2\">" +
+ "<forwarded xmlns=\"urn:xmpp:forward:0\">" +
+ "<message from=\"juliet@capulet.example/balcony\"" +
+ " to=\"romeo@montague.example/garden\"" +
+ " type=\"chat\">" +
+ "<body>What man art thou that, thus bescreen'd in night, so stumblest on my counsel?</body>" +
+ "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" +
+ "</message>" +
+ "</forwarded>" +
+ "</received>", testling.serialize(received));
+ }
+
+ /*
+ * Test serializing of example 14 in XEP-0280.
+ */
+ @Test
+ public void testSerializeExample14() {
+ CarbonsSentSerializer testling = new CarbonsSentSerializer(serializers);
+
+ CarbonsSent sent = new CarbonsSent();
+
+ Forwarded forwarded = new Forwarded();
+
+ Message message = new Message();
+ message.setTo(new JID("juliet@capulet.example/balcony"));
+ message.setFrom(new JID("romeo@montague.example/home"));
+ message.setBody("Neither, fair saint, if either thee dislike.");
+ message.addPayload(new Thread("0e3141cd80894871a68e6fe6b1ec56fa"));
+
+ forwarded.setStanza(message);
+ sent.setForwarded(forwarded);
+
+ assertEquals(
+ "<sent xmlns=\"urn:xmpp:carbons:2\">" +
+ "<forwarded xmlns=\"urn:xmpp:forward:0\">" +
+ "<message from=\"romeo@montague.example/home\"" +
+ " to=\"juliet@capulet.example/balcony\"" +
+ " type=\"chat\">" +
+ "<body>Neither, fair saint, if either thee dislike.</body>" +
+ "<thread>0e3141cd80894871a68e6fe6b1ec56fa</thread>" +
+ "</message>" +
+ "</forwarded>" +
+ "</sent>", testling.serialize(sent));
+ }
+
+ /*
+ * Test serializing of example 15 in XEP-0280.
+ */
+ @Test
+ public void testSerializeExample15() {
+ CarbonsPrivateSerializer testling = new CarbonsPrivateSerializer();
+
+ assertEquals("<private xmlns=\"urn:xmpp:carbons:2\"/>", testling.serialize(new CarbonsPrivate()));
+ }
+} \ No newline at end of file