summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'src/com')
-rw-r--r--src/com/isode/stroke/elements/Nickname.java51
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java2
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/NicknameParser.java59
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java2
-rw-r--r--src/com/isode/stroke/serializer/payloadserializers/NicknameSerializer.java32
5 files changed, 144 insertions, 2 deletions
diff --git a/src/com/isode/stroke/elements/Nickname.java b/src/com/isode/stroke/elements/Nickname.java
new file mode 100644
index 0000000..f77a636
--- /dev/null
+++ b/src/com/isode/stroke/elements/Nickname.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2010-2015 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;
+import com.isode.stroke.base.NotNull;
+
+public class Nickname extends Payload {
+
+ private String nickname;
+
+ /**
+ * Default Constructor.
+ */
+ public Nickname() {
+ this("");
+ }
+
+ /**
+ * Parameterized Constructor.
+ * @param nickname, Not Null.
+ */
+ public Nickname(String nickname) {
+ NotNull.exceptIfNull(nickname, "nickname");
+ this.nickname = nickname;
+ }
+
+ /**
+ * @param nickname, Not Null.
+ */
+ public void setNickname(String nickname) {
+ NotNull.exceptIfNull(nickname, "nickname");
+ this.nickname = nickname;
+ }
+
+ /**
+ * @return nickname, Not Null.
+ */
+ public String getNickname() {
+ return nickname;
+ }
+} \ 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 08d9f28..b591047 100644
--- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
+++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
@@ -83,7 +83,7 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl
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 GenericPayloadParserFactory<UserLocationParser>("geoloc", "http://jabber.org/protocol/geoloc", UserLocationParser.class));
- //addFactory(new NicknameParserFactory());
+ addFactory(new GenericPayloadParserFactory<NicknameParser>("nick", "http://jabber.org/protocol/nick", NicknameParser.class));
PayloadParserFactory defaultFactory = new RawXMLPayloadParserFactory();
setDefaultFactory(defaultFactory);
diff --git a/src/com/isode/stroke/parser/payloadparsers/NicknameParser.java b/src/com/isode/stroke/parser/payloadparsers/NicknameParser.java
new file mode 100644
index 0000000..97e9d30
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/NicknameParser.java
@@ -0,0 +1,59 @@
+/*
+ * 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.Nickname;
+import com.isode.stroke.base.NotNull;
+
+public class NicknameParser extends GenericPayloadParser<Nickname> {
+
+ private int level = 0;
+ private String text = "";
+
+ public NicknameParser() {
+ super(new Nickname());
+ this.level = 0;
+ }
+
+ /**
+ * @param element.
+ * @param ns.
+ * @param attributes.
+ */
+ @Override
+ public void handleStartElement(String element, String ns, AttributeMap attributes) {
+ ++level;
+ }
+
+ /**
+ * @param element, NotNull.
+ * @param ns.
+ */
+ @Override
+ public void handleEndElement(String element, String ns) {
+ --level;
+ if (level == 0) {
+ getPayloadInternal().setNickname(text);
+ }
+ }
+
+ /**
+ * @param data, NotNull.
+ */
+ @Override
+ public void handleCharacterData(String data) {
+ NotNull.exceptIfNull(data, "data");
+ text += 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 8c1f14b..9b88d0c 100644
--- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
+++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java
@@ -57,7 +57,7 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection
addSerializer(new FormSerializer());
addSerializer(new PrivateStorageSerializer(this));
addSerializer(new CommandSerializer());
- //addSerializer(new NicknameSerializer());
+ addSerializer(new NicknameSerializer());
addSerializer(new SearchPayloadSerializer());
addSerializer(new ReplaceSerializer());
addSerializer(new LastSerializer());
diff --git a/src/com/isode/stroke/serializer/payloadserializers/NicknameSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/NicknameSerializer.java
new file mode 100644
index 0000000..2964930
--- /dev/null
+++ b/src/com/isode/stroke/serializer/payloadserializers/NicknameSerializer.java
@@ -0,0 +1,32 @@
+/*
+ * 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.serializer.PayloadSerializerCollection;
+import com.isode.stroke.elements.Nickname;
+import com.isode.stroke.base.NotNull;
+
+public class NicknameSerializer extends GenericPayloadSerializer<Nickname> {
+
+ public NicknameSerializer() {
+ super(Nickname.class);
+ }
+
+ public String serializePayload(Nickname nick) {
+ XMLElement nickElement = new XMLElement("nick", "http://jabber.org/protocol/nick");
+ nickElement.addNode(new XMLTextNode(nick.getNickname()));
+ return nickElement.serialize();
+ }
+} \ No newline at end of file