summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/com/isode/stroke/elements/VCardUpdate.java35
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java2
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/VCardUpdateParser.java64
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java2
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/VCardUpdateSerializer.java41
-rw-r--r--test/com/isode/stroke/parser/payloadparsers/VCardUpdateParserTest.java35
-rw-r--r--test/com/isode/stroke/serializer/payloadserializers/VCardUpdateSerializerTest.java30
7 files changed, 207 insertions, 2 deletions
diff --git a/src/com/isode/stroke/elements/VCardUpdate.java b/src/com/isode/stroke/elements/VCardUpdate.java
new file mode 100644
index 0000000..ef02456
--- /dev/null
+++ b/src/com/isode/stroke/elements/VCardUpdate.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2010 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 VCardUpdate extends Payload {
+
+ private String photoHash_ = new String();
+
+ public VCardUpdate() {
+ this("");
+ }
+
+ public VCardUpdate(String photoHash) {
+ this.photoHash_ = photoHash;
+ }
+
+ public void setPhotoHash(String photoHash) {
+ photoHash_ = photoHash;
+ }
+
+ public String getPhotoHash() {
+ return photoHash_;
+ }
+} \ 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 4294370..80d5a5b 100644
--- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
+++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
@@ -40,7 +40,7 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl
addFactory(new SearchPayloadParserFactory());
//addFactory(new StreamInitiationParserFactory());
//addFactory(new BytestreamsParserFactory());
- //addFactory(new VCardUpdateParserFactory());
+ addFactory(new GenericPayloadParserFactory<VCardUpdateParser>("x", "vcard-temp:x:update", VCardUpdateParser.class));
addFactory(new GenericPayloadParserFactory<VCardParser>("vCard", "vcard-temp", VCardParser.class));
addFactory(new PrivateStorageParserFactory(this));
addFactory(new ChatStateParserFactory());
diff --git a/src/com/isode/stroke/parser/payloadparsers/VCardUpdateParser.java b/src/com/isode/stroke/parser/payloadparsers/VCardUpdateParser.java
new file mode 100644
index 0000000..70e4b27
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/VCardUpdateParser.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2010 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.VCardUpdate;
+import com.isode.stroke.base.NotNull;
+
+public class VCardUpdateParser extends GenericPayloadParser<VCardUpdate> {
+
+ private final int TopLevel = 0;
+ private final int PayloadLevel = 1;
+ private int level_ = TopLevel;
+ private String currentText_ = new String();
+
+
+ /**
+ * Default Constructor.
+ */
+ public VCardUpdateParser() {
+ super(new VCardUpdate());
+ }
+
+ /**
+ * @param element, notnull.
+ */
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ NotNull.exceptIfNull(element, "element");
+ if (level_ == PayloadLevel) {
+ currentText_ = "";
+ }
+ ++level_;
+ }
+
+ /**
+ * @param element, notnull.
+ */
+ public void handleEndElement(String element, String ns) {
+ NotNull.exceptIfNull(element, "element");
+ --level_;
+ if (level_ == PayloadLevel && element.equals("photo")) {
+ getPayloadInternal().setPhotoHash(currentText_);
+ }
+ }
+
+ /**
+ * @param text, notnull.
+ */
+ public void handleCharacterData(String text) {
+ NotNull.exceptIfNull(text, "text");
+ currentText_ += text;
+ }
+
+} \ 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 66fb664..5232d2c 100644
--- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
+++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
@@ -42,7 +42,7 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection
//addSerializer(new StreamInitiationSerializer());
//addSerializer(new BytestreamsSerializer());
addSerializer(new VCardSerializer());
- //addSerializer(new VCardUpdateSerializer());
+ addSerializer(new VCardUpdateSerializer());
addSerializer(new RawXMLPayloadSerializer());
addSerializer(new StorageSerializer());
addSerializer(new DelaySerializer());
diff --git a/src/com/isode/stroke/serializer/payloadserializers/VCardUpdateSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/VCardUpdateSerializer.java
new file mode 100644
index 0000000..9363e68
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/VCardUpdateSerializer.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2010 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.VCardUpdate;
+import com.isode.stroke.base.NotNull;
+
+public class VCardUpdateSerializer extends GenericPayloadSerializer<VCardUpdate> {
+
+ /**
+ * Constructor.
+ */
+ public VCardUpdateSerializer() {
+ super(VCardUpdate.class);
+ }
+
+ /**
+ * @param vcardUpdate, notnull
+ */
+ @Override
+ public String serializePayload(VCardUpdate vcardUpdate) {
+ NotNull.exceptIfNull(vcardUpdate, "vcardUpdate");
+ XMLElement updateElement = new XMLElement("x", "vcard-temp:x:update");
+ XMLElement photoElement = new XMLElement("photo");
+ photoElement.addNode(new XMLTextNode(vcardUpdate.getPhotoHash()));
+ updateElement.addNode(photoElement);
+ return updateElement.serialize();
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/parser/payloadparsers/VCardUpdateParserTest.java b/test/com/isode/stroke/parser/payloadparsers/VCardUpdateParserTest.java
new file mode 100644
index 0000000..d8ee2a5
--- /dev/null
+++ b/test/com/isode/stroke/parser/payloadparsers/VCardUpdateParserTest.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2010 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.assertTrue;
+import static org.junit.Assert.assertEquals;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import com.isode.stroke.elements.VCardUpdate;
+import com.isode.stroke.elements.Payload;
+import com.isode.stroke.parser.payloadparsers.VCardUpdateParser;
+import com.isode.stroke.parser.payloadparsers.PayloadsParserTester;
+import com.isode.stroke.eventloop.DummyEventLoop;
+
+public class VCardUpdateParserTest {
+
+ @Test
+ public void testParse() {
+ DummyEventLoop eventLoop = new DummyEventLoop();
+ PayloadsParserTester parser = new PayloadsParserTester(eventLoop);
+ assertTrue(parser.parse("<x xmlns='vcard-temp:x:update'><photo>sha1-hash-of-image</photo></x>"));
+ VCardUpdate payload = (VCardUpdate)parser.getPayload();
+ assertEquals("sha1-hash-of-image", payload.getPhotoHash());
+ }
+} \ No newline at end of file
diff --git a/test/com/isode/stroke/serializer/payloadserializers/VCardUpdateSerializerTest.java b/test/com/isode/stroke/serializer/payloadserializers/VCardUpdateSerializerTest.java
new file mode 100644
index 0000000..e6573bb
--- /dev/null
+++ b/test/com/isode/stroke/serializer/payloadserializers/VCardUpdateSerializerTest.java
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2010 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.BeforeClass;
+import org.junit.Test;
+import com.isode.stroke.elements.VCardUpdate;
+import com.isode.stroke.serializer.payloadserializers.VCardUpdateSerializer;
+
+public class VCardUpdateSerializerTest {
+
+ @Test
+ public void testSerialize() {
+ VCardUpdateSerializer testling = new VCardUpdateSerializer();
+ VCardUpdate update = new VCardUpdate();
+ update.setPhotoHash("sha1-hash-of-image");
+ String expectedResult = "<x xmlns=\"vcard-temp:x:update\"><photo>sha1-hash-of-image</photo></x>";
+ assertEquals(expectedResult, testling.serialize(update));
+ }
+} \ No newline at end of file