diff options
Diffstat (limited to 'src/com/isode')
4 files changed, 97 insertions, 2 deletions
diff --git a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java index b1afefd..0a46d75 100644 --- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java +++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java @@ -34,7 +34,7 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl addFactory(new GenericPayloadParserFactory<JingleIBBTransportMethodPayloadParser>("transport", "urn:xmpp:jingle:transports:ibb:1", JingleIBBTransportMethodPayloadParser.class)); addFactory(new GenericPayloadParserFactory<JingleS5BTransportMethodPayloadParser>("transport", "urn:xmpp:jingle:transports:s5b:1", JingleS5BTransportMethodPayloadParser.class)); addFactory(new JingleContentPayloadParserFactory(this)); - //addFactory(new GenericPayloadParserFactory<PriorityParser>("priority", PriorityParser.class)); + addFactory(new GenericPayloadParserFactory<PriorityParser>("priority", PriorityParser.class)); addFactory(new ErrorParserFactory(this)); addFactory(new SoftwareVersionParserFactory()); addFactory(new GenericPayloadParserFactory<IsodeIQDelegationParser>("delegate", "http://isode.com/iq_delegation", IsodeIQDelegationParser.class)); diff --git a/src/com/isode/stroke/parser/payloadparsers/PriorityParser.java b/src/com/isode/stroke/parser/payloadparsers/PriorityParser.java new file mode 100644 index 0000000..f2a99e9 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/PriorityParser.java @@ -0,0 +1,66 @@ +/* + * 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.parser.payloadparsers; + +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.elements.Priority; +import com.isode.stroke.base.NotNull; + +public class PriorityParser extends GenericPayloadParser<Priority> { + + private int level_ = 0; + private String text_ = ""; + + public PriorityParser() { + super(new Priority()); + this.level_ = 0; + } + + /** + * @param element, NotNull. + * @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) { + int priority = 0; + try { + priority = Integer.parseInt(text_); + } + catch (NumberFormatException e) { + + } + getPayloadInternal().setPriority(priority); + } + } + + /** + * @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 ba0d4e9..001d126 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java +++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java @@ -25,7 +25,7 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection addSerializer(new CarbonsPrivateSerializer()); addSerializer(new CarbonsReceivedSerializer(this)); addSerializer(new CarbonsSentSerializer(this)); - //addSerializer(new PrioritySerializer()); + addSerializer(new PrioritySerializer()); addSerializer(new ErrorSerializer()); addSerializer(new InBandRegistrationPayloadSerializer()); addSerializer(new IBBSerializer()); diff --git a/src/com/isode/stroke/serializer/payloadserializers/PrioritySerializer.java b/src/com/isode/stroke/serializer/payloadserializers/PrioritySerializer.java new file mode 100644 index 0000000..e043c4d --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/PrioritySerializer.java @@ -0,0 +1,29 @@ +/* + * 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.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.Priority; +import com.isode.stroke.base.NotNull; + +public class PrioritySerializer extends GenericPayloadSerializer<Priority> { + + public PrioritySerializer() { + super(Priority.class); + } + + public String serializePayload(Priority priority) { + return "<priority>" + Integer.toString(priority.getPriority()) + "</priority>"; + } +}
\ No newline at end of file |