summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTarun Gupta <tarun1995gupta@gmail.com>2015-06-11 20:23:56 (GMT)
committerTarun Gupta <tarun1995gupta@gmail.com>2015-06-16 19:14:39 (GMT)
commite868c966e23716d8a0261b222cccbeb04616e235 (patch)
tree2e26cc205e671f54bc5de527917913f8de47e0f4 /src/com/isode/stroke/parser
parentb2a8ac9a0387a9a5e75e31f7704e62ac077faba4 (diff)
downloadstroke-e868c966e23716d8a0261b222cccbeb04616e235.zip
stroke-e868c966e23716d8a0261b222cccbeb04616e235.tar.bz2
Add the UserLocation Element.
Adds UserLocation Element, its parser and Serializer. License: This patch is BSD-licensed, see Documentation/Licenses/BSD-simplified.txt for details. Test-Information: Tests added for UserLocation Parser and UserLocation Serializer, which passes. Change-Id: Ia1d57f4233351e755770f06fdc8e292db1acf521
Diffstat (limited to 'src/com/isode/stroke/parser')
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java1
-rw-r--r--src/com/isode/stroke/parser/payloadparsers/UserLocationParser.java133
2 files changed, 134 insertions, 0 deletions
diff --git a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
index ef491dd..1872feb 100644
--- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
+++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java
@@ -72,6 +72,7 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl
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 GenericPayloadParserFactory<UserLocationParser>("geoloc", "http://jabber.org/protocol/geoloc", UserLocationParser.class));
//addFactory(new NicknameParserFactory());
PayloadParserFactory defaultFactory = new RawXMLPayloadParserFactory();
diff --git a/src/com/isode/stroke/parser/payloadparsers/UserLocationParser.java b/src/com/isode/stroke/parser/payloadparsers/UserLocationParser.java
new file mode 100644
index 0000000..28cde78
--- /dev/null
+++ b/src/com/isode/stroke/parser/payloadparsers/UserLocationParser.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2013 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.UserLocation;
+import com.isode.stroke.base.NotNull;
+import com.isode.stroke.base.DateTime;
+
+public class UserLocationParser extends GenericPayloadParser<UserLocation> {
+
+ private int level = 0;
+ private String currentText = "";
+
+ public UserLocationParser() {
+ super(new UserLocation());
+ }
+
+ /**
+ * @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("accuracy")) {
+ getPayloadInternal().setAccuracy(Float.parseFloat(currentText));
+ }
+ else if (element.equals("alt")) {
+ getPayloadInternal().setAltitude(Float.parseFloat(currentText));
+ }
+ else if (element.equals("area")) {
+ getPayloadInternal().setArea(currentText);
+ }
+ else if (element.equals("bearing")) {
+ getPayloadInternal().setBearing(Float.parseFloat(currentText));
+ }
+ else if (element.equals("building")) {
+ getPayloadInternal().setBuilding(currentText);
+ }
+ else if (element.equals("country")) {
+ getPayloadInternal().setCountry(currentText);
+ }
+ else if (element.equals("countrycode")) {
+ getPayloadInternal().setCountryCode(currentText);
+ }
+ else if (element.equals("datum")) {
+ getPayloadInternal().setDatum(currentText);
+ }
+ else if (element.equals("description")) {
+ getPayloadInternal().setDescription(currentText);
+ }
+ else if (element.equals("error")) {
+ getPayloadInternal().setError(Float.parseFloat(currentText));
+ }
+ else if (element.equals("floor")) {
+ getPayloadInternal().setFloor(currentText);
+ }
+ else if (element.equals("lat")) {
+ getPayloadInternal().setLatitude(Float.parseFloat(currentText));
+ }
+ else if (element.equals("locality")) {
+ getPayloadInternal().setLocality(currentText);
+ }
+ else if (element.equals("lon")) {
+ getPayloadInternal().setLongitude(Float.parseFloat(currentText));
+ }
+ else if (element.equals("postalcode")) {
+ getPayloadInternal().setPostalCode(currentText);
+ }
+ else if (element.equals("region")) {
+ getPayloadInternal().setRegion(currentText);
+ }
+ else if (element.equals("room")) {
+ getPayloadInternal().setRoom(currentText);
+ }
+ else if (element.equals("speed")) {
+ getPayloadInternal().setSpeed(Float.parseFloat(currentText));
+ }
+ else if (element.equals("street")) {
+ getPayloadInternal().setStreet(currentText);
+ }
+ else if (element.equals("text")) {
+ getPayloadInternal().setText(currentText);
+ }
+ else if (element.equals("timestamp")) {
+ getPayloadInternal().setTimestamp(DateTime.stringToDate(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