summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-06-10 18:32:35 (GMT)
committerTarun Gupta <tarun1995gupta@gmail.com>2015-06-16 19:11:04 (GMT)
commitb2a8ac9a0387a9a5e75e31f7704e62ac077faba4 (patch)
tree633f0aa33043bef9db2f677d6b0874552562db75 /src/com
parent2180f81bd45045021d98c3a2e0649f10680596f9 (diff)
downloadstroke-b2a8ac9a0387a9a5e75e31f7704e62ac077faba4.zip
stroke-b2a8ac9a0387a9a5e75e31f7704e62ac077faba4.tar.bz2
Add the UserTune Element.
Adds UserTune Element, its parser and Serializer. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Tests added for UserTune Parser and UserTune Serializer. Change-Id: I3330d8493c79c2305de426827b5018b68d5b8e1b
Diffstat (limited to 'src/com')
-rw-r--r--src/com/isode/stroke/elements/UserTune.java130
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java2
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/UserTuneParser.java87
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java1
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/UserTuneSerializer.java59
5 files changed, 278 insertions, 1 deletions
diff --git a/src/com/isode/stroke/elements/UserTune.java b/src/com/isode/stroke/elements/UserTune.java
new file mode 100644
index 0000000..9e651a5
--- /dev/null
+++ b/src/com/isode/stroke/elements/UserTune.java
@@ -0,0 +1,130 @@
+/*
+ * Copyright (c) 2014 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 UserTune extends Payload {
+
+ private Integer rating;
+ private String title;
+ private String track;
+ private String artist;
+ private String uri;
+ private String source;
+ private Integer length;
+
+ /**
+ * Default Constructor.
+ */
+ public UserTune() {
+
+ }
+
+ /**
+ * @return rating.
+ */
+ public Integer getRating() {
+ return rating;
+ }
+
+ /**
+ * @param rating.
+ */
+ public void setRating(Integer value) {
+ this.rating = value;
+ }
+
+ /**
+ * @return title.
+ */
+ public String getTitle() {
+ return title;
+ }
+
+ /**
+ * @param title.
+ */
+ public void setTitle(String value) {
+ this.title = value;
+ }
+
+ /**
+ * @return track.
+ */
+ public String getTrack() {
+ return track;
+ }
+
+ /**
+ * @param track.
+ */
+ public void setTrack(String value) {
+ this.track = value;
+ }
+
+ /**
+ * @return artist.
+ */
+ public String getArtist() {
+ return artist;
+ }
+
+ /**
+ * @param artist.
+ */
+ public void setArtist(String value) {
+ this.artist = value;
+ }
+
+ /**
+ * @return URI.
+ */
+ public String getURI() {
+ return uri;
+ }
+
+ /**
+ * @param URI.
+ */
+ public void setURI(String value) {
+ this.uri = value;
+ }
+
+ /**
+ * @return source.
+ */
+ public String getSource() {
+ return source;
+ }
+
+ /**
+ * @param source.
+ */
+ public void setSource(String value) {
+ this.source = value;
+ }
+
+ /**
+ * @return length.
+ */
+ public Integer getLength() {
+ return length;
+ }
+
+ /**
+ * @param length.
+ */
+ public void setLength(Integer value) {
+ this.length = value;
+ }
+}
diff --git a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
index 7c9679b..ef491dd 100644
--- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
+++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
@@ -71,7 +71,7 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl
addFactory(new GenericPayloadParserFactory2<MAMResultParser>("result", "urn:xmpp:mam:0", this, MAMResultParser.class));
addFactory(new GenericPayloadParserFactory<MAMQueryParser>("query", "urn:xmpp:mam:0", MAMQueryParser.class));
addFactory(new GenericPayloadParserFactory<MAMFinParser>("fin", "urn:xmpp:mam:0", MAMFinParser.class));
-
+ addFactory(new GenericPayloadParserFactory<UserTuneParser>("tune", "http://jabber.org/protocol/tune", UserTuneParser.class));
//addFactory(new NicknameParserFactory());
PayloadParserFactory defaultFactory = new RawXMLPayloadParserFactory();
diff --git a/src/com/isode/stroke/parser/payloadparsers/UserTuneParser.java b/src/com/isode/stroke/parser/payloadparsers/UserTuneParser.java
new file mode 100644
index 0000000..3526150
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/UserTuneParser.java
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2014 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.UserTune;
+import com.isode.stroke.base.NotNull;
+
+public class UserTuneParser extends GenericPayloadParser<UserTune> {
+
+ private int level = 0;
+ private String currentText;
+
+ public UserTuneParser() {
+ super(new UserTune());
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ if (level == 1) {
+ currentText = "";
+ }
+ ++level;
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+ NotNull.exceptIfNull(element, "element");
+ --level;
+ if (level == 1) {
+ try {
+ if (element.equals("artist")) {
+ getPayloadInternal().setArtist(currentText);
+ }
+ else if (element.equals("length")) {
+ getPayloadInternal().setLength(Integer.parseInt(currentText));
+ }
+ else if (element.equals("rating")) {
+ getPayloadInternal().setRating(Integer.parseInt(currentText));
+ }
+ else if (element.equals("source")) {
+ getPayloadInternal().setSource(currentText);
+ }
+ else if (element.equals("title")) {
+ getPayloadInternal().setTitle(currentText);
+ }
+ else if (element.equals("track")) {
+ getPayloadInternal().setTrack(currentText);
+ }
+ else if (element.equals("URI")) {
+ getPayloadInternal().setURI(currentText);
+ }
+ }
+ catch (NumberFormatException e) {
+
+ }
+ }
+ }
+
+ /**
+ * @param data, NotNull.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+ NotNull.exceptIfNull(data, "data");
+ currentText += data;
+ }
+} \ 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 644b7e0..bdb57cc 100644
--- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
+++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
@@ -68,6 +68,7 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection
addSerializer(new MAMResultSerializer(this));
addSerializer(new MAMQuerySerializer());
addSerializer(new MAMFinSerializer());
+ addSerializer(new UserTuneSerializer(this));
}
}
diff --git a/src/com/isode/stroke/serializer/payloadserializers/UserTuneSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/UserTuneSerializer.java
new file mode 100644
index 0000000..2a0a399
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/UserTuneSerializer.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2014 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.serializer.PayloadSerializerCollection;
+import com.isode.stroke.elements.UserTune;
+import com.isode.stroke.base.NotNull;
+
+public class UserTuneSerializer extends GenericPayloadSerializer<UserTune> {
+
+ private PayloadSerializerCollection serializers;
+
+ public UserTuneSerializer(PayloadSerializerCollection serializers) {
+ super(UserTune.class);
+ this.serializers = serializers;
+ }
+
+ public String serializePayload(UserTune payload) {
+ if (payload == null) {
+ return "";
+ }
+
+ XMLElement element = new XMLElement("tune", "http://jabber.org/protocol/tune");
+ if (payload.getRating() != null) {
+ element.addNode(new XMLElement("rating", "", Integer.toString(payload.getRating())));
+ }
+ if (payload.getTitle() != null) {
+ element.addNode(new XMLElement("title", "", payload.getTitle()));
+ }
+ if (payload.getTrack() != null) {
+ element.addNode(new XMLElement("track", "", payload.getTrack()));
+ }
+ if (payload.getArtist() != null) {
+ element.addNode(new XMLElement("artist", "", payload.getArtist()));
+ }
+ if (payload.getURI() != null) {
+ element.addNode(new XMLElement("uri", "", payload.getURI()));
+ }
+ if (payload.getSource() != null) {
+ element.addNode(new XMLElement("source", "", payload.getSource()));
+ }
+ if (payload.getLength() != null) {
+ element.addNode(new XMLElement("length", "", Integer.toString(payload.getLength())));
+ }
+ return element.serialize();
+ }
+} \ No newline at end of file