summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-03-10 20:00:51 (GMT)
committerKevin Smith <git@kismith.co.uk>2015-03-12 21:48:21 (GMT)
commit158a5ca03eea87054c4cb19d7f0de872059c6000 (patch)
tree3a0955b3726526c11786b83783dde30154be81bd /src/com/isode
parent91a69677c1ab752b867613c4f5666a5d97ba94f7 (diff)
downloadstroke-158a5ca03eea87054c4cb19d7f0de872059c6000.zip
stroke-158a5ca03eea87054c4cb19d7f0de872059c6000.tar.bz2
Add functionality for CapsInfo
Adds the Element, Parser, Serializer and CapsInfoSerializerTest. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Ported serializer test from Swiften, which passes. Change-Id: Iefc10f49732c835f1f17e5da00dabed899da975e
Diffstat (limited to 'src/com/isode')
-rw-r--r--src/com/isode/stroke/elements/CapsInfo.java134
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/CapsInfoParser.java40
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java1
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/CapsInfoSerializer.java26
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java2
5 files changed, 202 insertions, 1 deletions
diff --git a/src/com/isode/stroke/elements/CapsInfo.java b/src/com/isode/stroke/elements/CapsInfo.java
new file mode 100644
index 0000000..9c2e937
--- /dev/null
+++ b/src/com/isode/stroke/elements/CapsInfo.java
@@ -0,0 +1,134 @@
+package com.isode.stroke.elements;
+
+import com.isode.stroke.base.NotNull;
+import java.lang.Comparable;
+
+public class CapsInfo extends Payload implements Comparable<CapsInfo> {
+
+ private String node_;
+ private String version_;
+ private String hash_;
+
+ /**
+ * Initialize private variables
+ */
+ public void init(String node, String version, String hash) {
+ NotNull.exceptIfNull(node, "node");
+ NotNull.exceptIfNull(version, "version");
+ NotNull.exceptIfNull(hash, "hash");
+ this.node_ = node;
+ this.version_ = version;
+ this.hash_ = hash;
+ }
+
+ /**
+ * CapsInfo();
+ */
+ public CapsInfo() {
+ init("", "", "sha-1");
+ }
+
+ /**
+ * CapsInfo(node, "", "sha-1");
+ */
+ public CapsInfo(String node) {
+ init(node, "", "sha-1");
+ }
+
+ /**
+ * CapsInfo(node, version, "sha-1");
+ */
+ public CapsInfo(String node, String version) {
+ init(node, version, "sha-1");
+ }
+
+ /**
+ *
+ * @param node CapsInfo node, notnull.
+ * @param node CapsInfo version, notnull.
+ * @param node CapsInfo hash, notnull.
+ */
+ public CapsInfo(String node, String version, String hash) {
+ init(node, version, hash);
+ }
+
+ @Override
+ public boolean equals(Object other) {
+
+ if ((!(other instanceof CapsInfo)) || other == null) {
+ return false;
+ }
+
+ CapsInfo guest = (CapsInfo) other;
+ return (node_.equals(guest.node_)) && (version_.equals(guest.version_)) && (hash_.equals(guest.hash_));
+ }
+
+ @Override
+ public int compareTo(CapsInfo other) {
+ if(other == null) {
+ return -1;
+ }
+ if (node_.equals(other.node_)) {
+ if (version_.equals(other.version_)) {
+ return hash_.compareTo(other.hash_);
+ }
+ else {
+ return version_.compareTo(other.version_);
+ }
+ }
+ else {
+ return node_.compareTo(other.node_);
+ }
+ }
+
+ /**
+ *
+ * @return Node, notnull.
+ */
+ public String getNode() {
+ return node_;
+ }
+
+ /**
+ *
+ * @param node, notnull.
+ */
+ public void setNode(String node) {
+ NotNull.exceptIfNull(node, "node");
+ this.node_ = node;
+ }
+
+ /**
+ *
+ * @return version, notnull.
+ */
+ public String getVersion() {
+ return version_;
+ }
+
+ /**
+ *
+ * @param version, notnull.
+ */
+ public void setVersion(String version) {
+ NotNull.exceptIfNull(version, "version");
+ this.version_ = version;
+ }
+
+ /**
+ *
+ * @return hash, notnull.
+ */
+ public String getHash() {
+ return hash_;
+ }
+
+ /**
+ *
+ * @param hash, notnull.
+ */
+ public void setHash(String hash) {
+ NotNull.exceptIfNull(hash, "hash");
+ this.hash_ = hash;
+ }
+}
diff --git a/src/com/isode/stroke/parser/payloadparsers/CapsInfoParser.java b/src/com/isode/stroke/parser/payloadparsers/CapsInfoParser.java
new file mode 100644
index 0000000..de0053f
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/CapsInfoParser.java
@@ -0,0 +1,40 @@
+package com.isode.stroke.parser.payloadparsers;
+
+import com.isode.stroke.parser.GenericPayloadParser;
+import com.isode.stroke.parser.AttributeMap;
+import com.isode.stroke.elements.CapsInfo;
+import com.isode.stroke.base.NotNull;
+
+public class CapsInfoParser extends GenericPayloadParser<CapsInfo> {
+
+ private int level_ = 0;
+
+ /**
+ * CapsInfoParser();
+ */
+ public CapsInfoParser() {
+ super(new CapsInfo());
+ }
+
+ /**
+ * @param attributes, notnull.
+ */
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(attributes, "attributes");
+ if (this.level_ == 0) {
+ getPayloadInternal().setHash(attributes.getAttribute("hash"));
+ getPayloadInternal().setNode(attributes.getAttribute("node"));
+ getPayloadInternal().setVersion(attributes.getAttribute("ver"));
+ }
+ ++level_;
+ }
+
+ public void handleEndElement(String element, String ns) {
+ --level_;
+ }
+
+ public void handleCharacterData(String data) {
+
+ }
+
+}
diff --git a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
index 4eeb741..e9d0fc1 100644
--- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
+++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
@@ -31,6 +31,7 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl
addFactory(new RosterParserFactory());
addFactory(new GenericPayloadParserFactory<DiscoInfoParser>("query", "http://jabber.org/protocol/disco#info", DiscoInfoParser.class));
addFactory(new GenericPayloadParserFactory<DiscoItemsParser>("query", "http://jabber.org/protocol/disco#items", DiscoItemsParser.class));
+ addFactory(new GenericPayloadParserFactory<CapsInfoParser> ("c", "http://jabber.org/protocol/caps", CapsInfoParser.class));
//addFactory(new CapsInfoParserFactory());
addFactory(new ResourceBindParserFactory());
addFactory(new StartSessionParserFactory());
diff --git a/src/com/isode/stroke/serializer/payloadserializers/CapsInfoSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/CapsInfoSerializer.java
new file mode 100644
index 0000000..2aeacb4
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/CapsInfoSerializer.java
@@ -0,0 +1,26 @@
+package com.isode.stroke.serializer.payloadserializers;
+
+import com.isode.stroke.serializer.GenericPayloadSerializer;
+import com.isode.stroke.elements.CapsInfo;
+import com.isode.stroke.base.NotNull;
+import com.isode.stroke.serializer.xml.XMLElement;
+
+public class CapsInfoSerializer extends GenericPayloadSerializer<CapsInfo> {
+
+ /**
+ * CapsInfoSerializer();
+ */
+ public CapsInfoSerializer() {
+ super(CapsInfo.class);
+ }
+
+ @Override
+ protected String serializePayload(CapsInfo capsInfo) {
+ NotNull.exceptIfNull(capsInfo, "capsInfo");
+ XMLElement capsElement = new XMLElement("c", "http://jabber.org/protocol/caps");
+ capsElement.setAttribute("node", capsInfo.getNode());
+ capsElement.setAttribute("hash", capsInfo.getHash());
+ capsElement.setAttribute("ver", capsInfo.getVersion());
+ return capsElement.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 591b6ce..83a252f 100644
--- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
+++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
@@ -38,7 +38,7 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection
//addSerializer(new StatusShowSerializer());
addSerializer(new DiscoInfoSerializer());
addSerializer(new DiscoItemsSerializer());
- //addSerializer(new CapsInfoSerializer());
+ addSerializer(new CapsInfoSerializer());
addSerializer(new ResourceBindSerializer());
addSerializer(new StartSessionSerializer());
//addSerializer(new SecurityLabelSerializer());