summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/isode')
-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
5 files changed, 142 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