diff options
Diffstat (limited to 'src/com')
22 files changed, 956 insertions, 2 deletions
diff --git a/src/com/isode/stroke/base/DateTime.java b/src/com/isode/stroke/base/DateTime.java new file mode 100644 index 0000000..27c85d8 --- /dev/null +++ b/src/com/isode/stroke/base/DateTime.java @@ -0,0 +1,36 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.base; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.Date; +import java.util.TimeZone; + +public class DateTime { + public static Date stringToDate(String date) { + SimpleDateFormat parser = new SimpleDateFormat(format); + parser.setTimeZone(TimeZone.getTimeZone("UTC")); + try { + return parser.parse(date); + } catch (ParseException e) { + return null; + } + } + + public static String dateToString(Date date) { + SimpleDateFormat parser = new SimpleDateFormat(format); + parser.setTimeZone(TimeZone.getTimeZone("UTC")); + return parser.format(date); + } + + static private String format = "yyyy-MM-dd'T'HH:mm:ss'Z'"; +} diff --git a/src/com/isode/stroke/elements/Delay.java b/src/com/isode/stroke/elements/Delay.java new file mode 100644 index 0000000..9827a82 --- /dev/null +++ b/src/com/isode/stroke/elements/Delay.java @@ -0,0 +1,43 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import java.util.Date; +import com.isode.stroke.jid.JID; + +public class Delay extends Payload { + public Delay() { + } + + public Delay(Date time, JID from) { + time_ = time; + from_ = from; + } + + public Date getStamp() { + return time_; + } + + public void setStamp(Date time) { + time_ = time; + } + + public JID getFrom() { + return from_; + } + + public void setFrom(JID from) { + from_ = from; + } + + private Date time_; + private JID from_; +} diff --git a/src/com/isode/stroke/elements/Forwarded.java b/src/com/isode/stroke/elements/Forwarded.java new file mode 100644 index 0000000..fbfabce --- /dev/null +++ b/src/com/isode/stroke/elements/Forwarded.java @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +public class Forwarded extends Payload { + public void setDelay(Delay delay) { + delay_ = delay; + } + + public Delay getDelay() { + return delay_; + } + + public void setStanza(Stanza stanza) { + stanza_ = stanza; + } + + public Stanza getStanza() { + return stanza_; + } + + private Delay delay_; + private Stanza stanza_; +} diff --git a/src/com/isode/stroke/elements/MAMArchived.java b/src/com/isode/stroke/elements/MAMArchived.java new file mode 100644 index 0000000..c8ab2d9 --- /dev/null +++ b/src/com/isode/stroke/elements/MAMArchived.java @@ -0,0 +1,34 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +import com.isode.stroke.jid.JID; + +public class MAMArchived extends Payload { + public void setBy(JID by) { + by_ = by; + } + + public JID getBy() { + return by_; + } + + public void setID(String id) { + id_ = id; + } + + public String getID() { + return id_; + } + + private JID by_; + private String id_; +} diff --git a/src/com/isode/stroke/elements/MAMQuery.java b/src/com/isode/stroke/elements/MAMQuery.java new file mode 100644 index 0000000..6da30b5 --- /dev/null +++ b/src/com/isode/stroke/elements/MAMQuery.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * All rights reserved. + */ + +/* + * Copyright (c) 2014, Isode Limited, London, England. + * All rights reserved. + */ + +package com.isode.stroke.elements; + +public class MAMQuery extends Payload { + public void setQueryID(String queryID) { + queryID_ = queryID; + } + + public String getQueryID() { + return queryID_; + } + + public void setForm(Form form) { + form_ = form; + } + + public Form getForm() { + return form_; + } + + public void setResultSet(ResultSet resultSet) { + resultSet_ = resultSet; + } + + public ResultSet getResultSet() { + return resultSet_; + } + + private String queryID_; + private Form form_; + private ResultSet resultSet_; +} diff --git a/src/com/isode/stroke/elements/MAMResult.java b/src/com/isode/stroke/elements/MAMResult.java new file mode 100644 index 0000000..aa83c88 --- /dev/null +++ b/src/com/isode/stroke/elements/MAMResult.java @@ -0,0 +1,32 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +public class MAMResult extends ContainerPayload<Forwarded> { + public void setID(String id) { + id_ = id; + } + + public String getID() { + return id_; + } + + public void setQueryID(String queryID) { + queryID_ = queryID; + } + + public String getQueryID() { + return queryID_; + } + + private String id_; + private String queryID_; +} diff --git a/src/com/isode/stroke/elements/ResultSet.java b/src/com/isode/stroke/elements/ResultSet.java new file mode 100644 index 0000000..706d37c --- /dev/null +++ b/src/com/isode/stroke/elements/ResultSet.java @@ -0,0 +1,80 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.elements; + +/** + * ResultSet + */ +public class ResultSet extends Payload { + public void setMaxItems(Long maxItems) { + maxItems_ = maxItems; + } + + public Long getMaxItems() { + return maxItems_; + } + + public void setCount(Long count) { + count_ = count; + } + + public Long getCount() { + return count_; + } + + public void setFirstIDIndex(Long firstIndex) { + firstIndex_ = firstIndex; + } + + public Long getFirstIDIndex() { + return firstIndex_; + } + + public void setFirstID(String firstID) { + firstID_ = firstID; + } + + public String getFirstID() { + return firstID_; + } + + public void setLastID(String lastID) { + lastID_ = lastID; + } + + public String getLastID() { + return lastID_; + } + + public void setAfter(String after) { + after_ = after; + } + + public String getAfter() { + return after_; + } + + public void setBefore(String before) { + before_ = before; + } + + public String getBefore() { + return before_; + } + + private Long maxItems_; + private Long count_; + private Long firstIndex_; + private String firstID_; + private String lastID_; + private String after_; + private String before_; +} diff --git a/src/com/isode/stroke/parser/StanzaParser.java b/src/com/isode/stroke/parser/StanzaParser.java index cb7647d..6b0ccdf 100644 --- a/src/com/isode/stroke/parser/StanzaParser.java +++ b/src/com/isode/stroke/parser/StanzaParser.java @@ -25,7 +25,7 @@ public abstract class StanzaParser implements ElementParser { void handleStanzaAttributes(AttributeMap map) { } - Stanza getStanza() { + public Stanza getStanza() { return (Stanza) getElement(); } diff --git a/src/com/isode/stroke/parser/payloadparsers/DelayParser.java b/src/com/isode/stroke/parser/payloadparsers/DelayParser.java new file mode 100644 index 0000000..44d21ce --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/DelayParser.java @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import java.util.Date; +import com.isode.stroke.base.DateTime; +import com.isode.stroke.elements.Delay; +import com.isode.stroke.jid.JID; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; + +public class DelayParser extends GenericPayloadParser<Delay> { + + public DelayParser() { + super(new Delay()); + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + Date stamp = DateTime.stringToDate(attributes.getAttribute("stamp")); + getPayloadInternal().setStamp(stamp); + if (!attributes.getAttribute("from").isEmpty()) { + String from = attributes.getAttribute("from"); + getPayloadInternal().setFrom(new JID(from)); + } + } + ++level_; + } + + public void handleEndElement(String element, String ns) { + --level_; + } + + public void handleCharacterData(String data) { + } + + private int level_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/ForwardedParser.java b/src/com/isode/stroke/parser/payloadparsers/ForwardedParser.java new file mode 100644 index 0000000..b7a023e --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/ForwardedParser.java @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2014 Kevin Smith and Remko Tronçon + * All rights reserved. + */ + +/* + * Copyright (c) 2014, Isode Limited, London, England. + * All rights reserved. + */ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.elements.Delay; +import com.isode.stroke.elements.Forwarded; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.IQParser; +import com.isode.stroke.parser.MessageParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; +import com.isode.stroke.parser.PresenceParser; +import com.isode.stroke.parser.StanzaParser; + +public class ForwardedParser extends GenericPayloadParser<Forwarded> { + public ForwardedParser(PayloadParserFactoryCollection factories) { + super(new Forwarded()); + factories_ = factories; + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 1) { + if (element == "iq") { /* begin parsing a nested stanza? */ + childParser_ = new IQParser(factories_); + } else if (element == "message") { + childParser_ = new MessageParser(factories_); + } else if (element == "presence") { + childParser_ = new PresenceParser(factories_); + } else if (element == "delay" && ns == "urn:xmpp:delay") { + delayParser_ = new DelayParser(); + } + } + if (childParser_ != null) { /* parsing a nested stanza? */ + childParser_.handleStartElement(element, ns, attributes); + } + if (delayParser_ != null) { /* parsing a nested delay payload? */ + delayParser_.handleStartElement(element, ns, attributes); + } + ++level_; + } + + public void handleEndElement(String element, String ns) { + --level_; + if (childParser_ != null && level_ >= 1) { + childParser_.handleEndElement(element, ns); + } + if (childParser_ != null && level_ == 1) { /* done parsing nested stanza? */ + getPayloadInternal().setStanza(childParser_.getStanza()); + childParser_ = null; + } + if (delayParser_ != null && level_ >= 1) { + delayParser_.handleEndElement(element, ns); + } + if (delayParser_ != null && level_ == 1) { /* done parsing nested delay payload? */ + getPayloadInternal().setDelay((Delay) delayParser_.getPayload()); + delayParser_ = null; + } + } + + public void handleCharacterData(String data) { + if (childParser_ != null) { + childParser_.handleCharacterData(data); + } + if (delayParser_ != null) { + delayParser_.handleCharacterData(data); + } + } + + private PayloadParserFactoryCollection factories_; + private StanzaParser childParser_; + private DelayParser delayParser_; + private int level_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java index cf41338..41f44f5 100644 --- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java +++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java @@ -64,6 +64,13 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl addFactory(new GenericPayloadParserFactory2<PubSubEventParser>("event", "http://jabber.org/protocol/pubsub#event", this, PubSubEventParser.class)); addFactory(new PubSubErrorParserFactory()); + addFactory(new GenericPayloadParserFactory<DelayParser>("delay", "urn:xmpp:delay", DelayParser.class)); + addFactory(new GenericPayloadParserFactory<ResultSetParser>("set", "http://jabber.org/protocol/rsm", ResultSetParser.class)); + addFactory(new GenericPayloadParserFactory2<ForwardedParser>("forwarded", "urn:xmpp:forward:0", this, ForwardedParser.class)); + 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<MAMArchivedParser>("archived", "urn:xmpp:mam:0", MAMArchivedParser.class)); + //addFactory(new NicknameParserFactory()); PayloadParserFactory defaultFactory = new RawXMLPayloadParserFactory(); diff --git a/src/com/isode/stroke/parser/payloadparsers/MAMArchivedParser.java b/src/com/isode/stroke/parser/payloadparsers/MAMArchivedParser.java new file mode 100644 index 0000000..5547a87 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/MAMArchivedParser.java @@ -0,0 +1,46 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.elements.MAMArchived; +import com.isode.stroke.jid.JID; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; + +public class MAMArchivedParser extends GenericPayloadParser<MAMArchived> { + public MAMArchivedParser() { + super(new MAMArchived()); + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue = attributes.getAttributeValue("by"); + if (attributeValue != null) { + getPayloadInternal().setBy(JID.fromString(attributeValue)); + } + attributeValue = attributes.getAttributeValue("id"); + if (attributeValue != null) { + getPayloadInternal().setID(attributeValue); + } + } + + ++level_; + } + + public void handleEndElement(String element, String ns) { + --level_; + } + + public void handleCharacterData(String data) { + } + + private int level_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/MAMQueryParser.java b/src/com/isode/stroke/parser/payloadparsers/MAMQueryParser.java new file mode 100644 index 0000000..fcfd5e4 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/MAMQueryParser.java @@ -0,0 +1,82 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.elements.Form; +import com.isode.stroke.elements.MAMQuery; +import com.isode.stroke.elements.ResultSet; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; + +public class MAMQueryParser extends GenericPayloadParser<MAMQuery> { + + public MAMQueryParser() { + super(new MAMQuery()); + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue = attributes.getAttributeValue("queryid"); + if (attributeValue != null) { + getPayloadInternal().setQueryID(attributeValue); + } + } else if (level_ == 1) { + if (element == "x" && ns == "jabber:x:data") { + formParser_ = new FormParser(); + } else if (element == "set" && ns == "http://jabber.org/protocol/rsm") { + resultSetParser_ = new ResultSetParser(); + } + } + + if (formParser_ != null) { /* parsing a nested Form */ + formParser_.handleStartElement(element, ns, attributes); + } + + if (resultSetParser_ != null) { /* parsing a nested ResultSet */ + resultSetParser_.handleStartElement(element, ns, attributes); + } + + ++level_; + } + + public void handleEndElement(String element, String ns) { + --level_; + + if (formParser_ != null && level_>= 1) { + formParser_.handleEndElement(element, ns); + } + if (formParser_ != null && level_==1) { /* done parsing nested Form? */ + getPayloadInternal().setForm((Form)formParser_.getPayload()); + formParser_ = null; + } + + if (resultSetParser_ != null && level_>= 1) { + resultSetParser_.handleEndElement(element, ns); + } + if (resultSetParser_ != null && level_==1) { /* done parsing nested ResultSet? */ + getPayloadInternal().setResultSet((ResultSet)resultSetParser_.getPayload()); + resultSetParser_ = null; + } + } + + public void handleCharacterData(String data) { + if (formParser_ != null) { + formParser_.handleCharacterData(data); + } + if (resultSetParser_ != null) { + resultSetParser_.handleCharacterData(data); + } + } + + private FormParser formParser_; + private ResultSetParser resultSetParser_; + private int level_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/MAMResultParser.java b/src/com/isode/stroke/parser/payloadparsers/MAMResultParser.java new file mode 100644 index 0000000..cb3d7fd --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/MAMResultParser.java @@ -0,0 +1,68 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.elements.Forwarded; +import com.isode.stroke.elements.MAMResult; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; +import com.isode.stroke.parser.PayloadParserFactoryCollection; + +public class MAMResultParser extends GenericPayloadParser<MAMResult> { + public MAMResultParser(PayloadParserFactoryCollection factories) { + super(new MAMResult()); + factories_ = factories; + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + if (level_ == 0) { + String attributeValue = attributes.getAttributeValue("id"); + if (attributeValue != null) { + getPayloadInternal().setID(attributeValue); + } + attributeValue = attributes.getAttributeValue("queryid"); + if (attributeValue != null) { + getPayloadInternal().setQueryID(attributeValue); + } + } else if (level_ == 1) { + if (element == "forwarded" && ns == "urn:xmpp:forward:0") { + payloadParser_ = new ForwardedParser(factories_); + } + } + + if (payloadParser_ != null) { /* parsing a nested payload? */ + payloadParser_.handleStartElement(element, ns, attributes); + } + + ++level_; + } + + public void handleEndElement(String element, String ns) { + --level_; + if (payloadParser_ != null && level_ >= 1) { + payloadParser_.handleEndElement(element, ns); + } + if (payloadParser_ != null && level_ == 1) { /* done parsing nested stanza? */ + getPayloadInternal().setPayload((Forwarded)payloadParser_.getPayload()); + payloadParser_ = null; + } + } + + public void handleCharacterData(String data) { + if (payloadParser_ != null) { + payloadParser_.handleCharacterData(data); + } + } + + private ForwardedParser payloadParser_; + private PayloadParserFactoryCollection factories_; + private int level_; +} diff --git a/src/com/isode/stroke/parser/payloadparsers/ResultSetParser.java b/src/com/isode/stroke/parser/payloadparsers/ResultSetParser.java new file mode 100644 index 0000000..26343a0 --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/ResultSetParser.java @@ -0,0 +1,61 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.parser.payloadparsers; + +import com.isode.stroke.elements.ResultSet; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; + +public class ResultSetParser extends GenericPayloadParser<ResultSet> { + + public ResultSetParser() { + super(new ResultSet()); + } + + public void handleStartElement(String element, String ns, AttributeMap attributes) { + currentText_ = ""; + if (level_ == 1) { + if (element == "first" && ns == "http://jabber.org/protocol/rsm") { + String attributeValue = attributes.getAttributeValue("index"); + if (attributeValue != null) { + getPayloadInternal().setFirstIDIndex(Long.parseLong(attributeValue)); + } + } + } + ++level_; + } + + public void handleEndElement(String element, String ns) { + --level_; + if (level_ == 1) { + if (element == "max") { + getPayloadInternal().setMaxItems(Long.parseLong(currentText_)); + } else if (element == "count") { + getPayloadInternal().setCount(Long.parseLong(currentText_)); + } else if (element == "first") { + getPayloadInternal().setFirstID(currentText_); + } else if (element == "last") { + getPayloadInternal().setLastID(currentText_); + } else if (element == "after") { + getPayloadInternal().setAfter(currentText_); + } else if (element == "before") { + getPayloadInternal().setBefore(currentText_); + } + } + } + + public void handleCharacterData(String data) { + currentText_ += data; + } + + private String currentText_; + private int level_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/DelaySerializer.java b/src/com/isode/stroke/serializer/payloadserializers/DelaySerializer.java new file mode 100644 index 0000000..f54f38f --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/DelaySerializer.java @@ -0,0 +1,31 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.base.DateTime; +import com.isode.stroke.elements.Delay; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.xml.XMLElement; + +public class DelaySerializer extends GenericPayloadSerializer<Delay> { + public DelaySerializer() { + super(Delay.class); + } + + protected String serializePayload(Delay delay) { + XMLElement delayElement = new XMLElement("delay", "urn:xmpp:delay"); + if (delay.getFrom() != null && delay.getFrom().isValid()) { + delayElement.setAttribute("from", delay.getFrom().toString()); + } + delayElement.setAttribute("stamp", DateTime.dateToString(delay.getStamp())); + return delayElement.serialize(); + } +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/ForwardedSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/ForwardedSerializer.java new file mode 100644 index 0000000..625205e --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/ForwardedSerializer.java @@ -0,0 +1,56 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.elements.Forwarded; +import com.isode.stroke.elements.IQ; +import com.isode.stroke.elements.Message; +import com.isode.stroke.elements.Presence; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.IQSerializer; +import com.isode.stroke.serializer.MessageSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.PresenceSerializer; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.xml.XMLRawTextNode; + +public class ForwardedSerializer extends GenericPayloadSerializer<Forwarded> { + public ForwardedSerializer(PayloadSerializerCollection serializers) { + super(Forwarded.class); + serializers_ = serializers; + } + + public String serializePayload(Forwarded payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("forwarded", "urn:xmpp:forward:0"); + + if (payload.getDelay() != null) { + element.addNode(new XMLRawTextNode((new DelaySerializer()).serialize(payload.getDelay()))); + } + + if (payload.getStanza() != null) { /* find out what type of stanza we are dealing with and branch into the correct serializer */ + if (payload.getStanza() instanceof IQ) { + element.addNode(new XMLRawTextNode((new IQSerializer(serializers_)).serialize((IQ)payload.getStanza()))); + } else if (payload.getStanza() instanceof Message) { + element.addNode(new XMLRawTextNode((new MessageSerializer(serializers_)).serialize((Message)payload.getStanza()))); + } else if (payload.getStanza() instanceof Presence) { + element.addNode(new XMLRawTextNode((new PresenceSerializer(serializers_)).serialize((Presence)payload.getStanza()))); + } + } + + return element.serialize(); + } + + private PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java index f846d85..9cb3646 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java +++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java @@ -49,7 +49,7 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection //addSerializer(new VCardUpdateSerializer()); addSerializer(new RawXMLPayloadSerializer()); //addSerializer(new StorageSerializer()); - //addSerializer(new DelaySerializer()); + addSerializer(new DelaySerializer()); addSerializer(new FormSerializer()); //addSerializer(new PrivateStorageSerializer(this)); addSerializer(new CommandSerializer()); @@ -61,6 +61,12 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection addSerializer(new PubSubEventSerializer(this)); addSerializer(new PubSubOwnerPubSubSerializer(this)); addSerializer(new PubSubErrorSerializer()); + + addSerializer(new ResultSetSerializer()); + addSerializer(new ForwardedSerializer(this)); + addSerializer(new MAMResultSerializer(this)); + addSerializer(new MAMQuerySerializer()); + addSerializer(new MAMArchivedSerializer()); } } diff --git a/src/com/isode/stroke/serializer/payloadserializers/MAMArchivedSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/MAMArchivedSerializer.java new file mode 100644 index 0000000..0a5f1f4 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/MAMArchivedSerializer.java @@ -0,0 +1,33 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.elements.MAMArchived; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.xml.XMLElement; + +public class MAMArchivedSerializer extends GenericPayloadSerializer<MAMArchived> { + public MAMArchivedSerializer() { + super(MAMArchived.class); + } + + protected String serializePayload(MAMArchived payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("archived", "urn:xmpp:mam:0"); + element.setAttribute("by", payload.getBy().toString()); + element.setAttribute("id", payload.getID()); + + return element.serialize(); + } +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializer.java b/src/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializer.java new file mode 100644 index 0000000..46cc42c --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializer.java @@ -0,0 +1,35 @@ +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.elements.MAMQuery; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.xml.XMLRawTextNode; + +public class MAMQuerySerializer extends GenericPayloadSerializer<MAMQuery> { + + public MAMQuerySerializer() { + super(MAMQuery.class); + } + + protected String serializePayload(MAMQuery payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("query", "urn:xmpp:mam:0"); + + if (payload.getQueryID() != null) { + element.setAttribute("queryid", payload.getQueryID()); + } + + if (payload.getForm() != null) { + element.addNode(new XMLRawTextNode((new FormSerializer()).serialize(payload.getForm()))); + } + + if (payload.getResultSet() != null) { + element.addNode(new XMLRawTextNode((new ResultSetSerializer()).serialize(payload.getResultSet()))); + } + + return element.serialize(); + } +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/MAMResultSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/MAMResultSerializer.java new file mode 100644 index 0000000..532e93f --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/MAMResultSerializer.java @@ -0,0 +1,44 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.elements.MAMResult; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.PayloadSerializerCollection; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.xml.XMLRawTextNode; + +public class MAMResultSerializer extends GenericPayloadSerializer<MAMResult> { + public MAMResultSerializer(PayloadSerializerCollection serializers) { + super(MAMResult.class); + serializers_ = serializers; + } + + public String serializePayload(MAMResult payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("result", "urn:xmpp:mam:0"); + + element.setAttribute("id", payload.getID()); + + if (payload.getQueryID() != null) { + element.setAttribute("queryid", payload.getQueryID()); + } + + element.addNode(new XMLRawTextNode((new ForwardedSerializer(serializers_)).serialize(payload.getPayload()))); + + return element.serialize(); + } + + PayloadSerializerCollection serializers_; +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/ResultSetSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/ResultSetSerializer.java new file mode 100644 index 0000000..06589d5 --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/ResultSetSerializer.java @@ -0,0 +1,60 @@ +/* +* Copyright (c) 2014 Kevin Smith and Remko Tronçon +* All rights reserved. +*/ + +/* +* Copyright (c) 2014, Isode Limited, London, England. +* All rights reserved. +*/ + +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.elements.ResultSet; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.xml.XMLElement; + +public class ResultSetSerializer extends GenericPayloadSerializer<ResultSet> { + + public ResultSetSerializer() { + super(ResultSet.class); + } + + protected String serializePayload(ResultSet payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("set", "http://jabber.org/protocol/rsm"); + + if (payload.getMaxItems() != null) { + element.addNode(new XMLElement("max", "", payload.getMaxItems().toString())); + } + + if (payload.getCount() != null) { + element.addNode(new XMLElement("count", "", payload.getCount().toString())); + } + + if (payload.getFirstID() != null) { + XMLElement firstElement = new XMLElement("first", "", payload.getFirstID()); + if (payload.getFirstIDIndex() != null) { + firstElement.setAttribute("index", payload.getFirstIDIndex().toString()); + } + element.addNode(firstElement); + } + + if (payload.getLastID() != null) { + element.addNode(new XMLElement("last", "", payload.getLastID())); + } + + if (payload.getAfter() != null) { + element.addNode(new XMLElement("after", "", payload.getAfter())); + } + + if (payload.getBefore() != null) { + element.addNode(new XMLElement("before", "", payload.getBefore())); + } + + return element.serialize(); + } +} |