diff options
author | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-03 12:17:53 (GMT) |
---|---|---|
committer | Tarun Gupta <tarun1995gupta@gmail.com> | 2015-06-14 13:30:22 (GMT) |
commit | afaf2c8e7a9276bc4a61337357092c49e6817159 (patch) | |
tree | 143b1551c29c4158403c956e175861de71bbf0d8 /src/com | |
parent | cae0635287b9ccf0d846dffd550440b347bd6721 (diff) | |
download | stroke-afaf2c8e7a9276bc4a61337357092c49e6817159.zip stroke-afaf2c8e7a9276bc4a61337357092c49e6817159.tar.bz2 |
Add VCardUpdate Element.
Adds the VCardUpdate Element, VCardUpdate Parser, VCardUpdateSerializer.
License:
This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details.
Test-Information:
Tests ported for VCardUpdateParser and VCardUpdateSerializer, which passes.
Change-Id: I9baf8f6787567c8766b52dbe70105e8870c02b2d
Diffstat (limited to 'src/com')
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 |