diff options
author | Alex Clayton <alex.clayton@isode.com> | 2014-11-13 15:15:41 (GMT) |
---|---|---|
committer | Alex Clayton <alex.clayton@isode.com> | 2014-11-26 09:39:53 (GMT) |
commit | b89bf2f3363bac56fcc5d02f5fb690c73eaaacdf (patch) | |
tree | 39893e33d2bb88f0eef3e04ae9533bb1d6139c17 /src/com/isode | |
parent | 47cad5fd7883b8c7273ea11073643aa585b485c6 (diff) | |
download | stroke-b89bf2f3363bac56fcc5d02f5fb690c73eaaacdf.zip stroke-b89bf2f3363bac56fcc5d02f5fb690c73eaaacdf.tar.bz2 |
Bring Stroke inline with Swiften with respect to MAM
Some patches for MAM had gone into swiften without being ported to stroke. This patch should bring stroke
update to date with Swiften.
The swiften patches in question are
9b762e1cf26cfe12cf601d9ea95cf91b3f95c799 -- Add node attribute to MAMQuery
8096f80861667381b777af774cfd446d6fc8cda8 -- Brining XEP-0313 (MAM) implementation in line with version 3.0.
Test-information:
Ran the updated JUnit tests in Eclipse they all passed ok.
Ran make and make test in a stroke checkout. Everything build ok and the JUNit tests passed.
Change-Id: I95bf5d598808f48fe2d7af12c0f07d852d68c115
Diffstat (limited to 'src/com/isode')
11 files changed, 221 insertions, 118 deletions
diff --git a/src/com/isode/stroke/elements/MAMArchived.java b/src/com/isode/stroke/elements/MAMArchived.java deleted file mode 100644 index c8ab2d9..0000000 --- a/src/com/isode/stroke/elements/MAMArchived.java +++ /dev/null @@ -1,34 +0,0 @@ -/* -* 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/MAMFin.java b/src/com/isode/stroke/elements/MAMFin.java new file mode 100644 index 0000000..ebc39e8 --- /dev/null +++ b/src/com/isode/stroke/elements/MAMFin.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.elements; + +public class MAMFin extends Payload { + + private boolean isComplete_; + + private boolean isStable_; + + private ResultSet resultSet_; + + private String queryID_; + + public MAMFin() { + isComplete_ = false; + isStable_ = true; + } + + public boolean isComplete() { + return isComplete_; + } + + public void setComplete(boolean isComplete) { + this.isComplete_ = isComplete; + } + + public boolean isStable() { + return isStable_; + } + + public void setStable(boolean isStable) { + this.isStable_ = isStable; + } + + public ResultSet getResultSet() { + return resultSet_; + } + + public void setResultSet(ResultSet resultSet) { + this.resultSet_ = resultSet; + } + + public String getQueryID() { + return queryID_; + } + + public void setQueryID(String queryID) { + this.queryID_ = queryID; + } + +} diff --git a/src/com/isode/stroke/elements/MAMQuery.java b/src/com/isode/stroke/elements/MAMQuery.java index 6da30b5..b889a8e 100644 --- a/src/com/isode/stroke/elements/MAMQuery.java +++ b/src/com/isode/stroke/elements/MAMQuery.java @@ -11,6 +11,7 @@ package com.isode.stroke.elements; public class MAMQuery extends Payload { + public void setQueryID(String queryID) { queryID_ = queryID; } @@ -19,6 +20,14 @@ public class MAMQuery extends Payload { return queryID_; } + public void setNode(String node) { + node_ = node; + } + + public String getNode() { + return node_; + } + public void setForm(Form form) { form_ = form; } @@ -36,6 +45,7 @@ public class MAMQuery extends Payload { } private String queryID_; + private String node_; private Form form_; private ResultSet resultSet_; } diff --git a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java index 41f44f5..4eeb741 100644 --- a/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java +++ b/src/com/isode/stroke/parser/payloadparsers/FullPayloadParserFactoryCollection.java @@ -69,7 +69,7 @@ public class FullPayloadParserFactoryCollection extends PayloadParserFactoryColl 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 GenericPayloadParserFactory<MAMFinParser>("fin", "urn:xmpp:mam:0", MAMFinParser.class)); //addFactory(new NicknameParserFactory()); diff --git a/src/com/isode/stroke/parser/payloadparsers/MAMArchivedParser.java b/src/com/isode/stroke/parser/payloadparsers/MAMArchivedParser.java deleted file mode 100644 index 5547a87..0000000 --- a/src/com/isode/stroke/parser/payloadparsers/MAMArchivedParser.java +++ /dev/null @@ -1,46 +0,0 @@ -/* -* 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/MAMFinParser.java b/src/com/isode/stroke/parser/payloadparsers/MAMFinParser.java new file mode 100644 index 0000000..f5ebdec --- /dev/null +++ b/src/com/isode/stroke/parser/payloadparsers/MAMFinParser.java @@ -0,0 +1,94 @@ +/* +* 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.MAMFin; +import com.isode.stroke.elements.Payload; +import com.isode.stroke.elements.ResultSet; +import com.isode.stroke.parser.AttributeMap; +import com.isode.stroke.parser.GenericPayloadParser; + +public class MAMFinParser extends GenericPayloadParser<MAMFin> { + + private static final String QUERYID_ATTRIBUTE = "queryid"; + + private static final String STABLE_ATTRIBUTE = "stable"; + + private static final String COMPLETE_ATTRIBUTE = "complete"; + + private static final String SET_ELEMENT = "set"; + + private static final String SET_NS = "http://jabber.org/protocol/rsm"; + + private static final int TOP_LEVEL = 0; + + private static final int PAYLOAD_LEVEL = 1; + + private ResultSetParser resultSetParser_ = null; + + private int level_ = 0; + + public MAMFinParser() { + super(new MAMFin()); + } + + @Override + public void handleStartElement(String element, String ns, + AttributeMap attributes) { + if (level_ == TOP_LEVEL) { + MAMFin internalPayload = getPayloadInternal(); + internalPayload.setComplete(attributes.getBoolAttribute(COMPLETE_ATTRIBUTE, false)); + internalPayload.setStable(attributes.getBoolAttribute(STABLE_ATTRIBUTE, true)); + String idAttributeValue = attributes.getAttributeValue(QUERYID_ATTRIBUTE); + if (idAttributeValue != null) { + internalPayload.setQueryID(idAttributeValue); + } + } + else if (level_ == PAYLOAD_LEVEL) { + if (element == SET_ELEMENT && ns == SET_NS) { + resultSetParser_ = new ResultSetParser(); + } + } + + if (resultSetParser_ != null) { + // Parsing a nested result set + resultSetParser_.handleStartElement(element, ns, attributes); + } + + ++level_; + } + + @Override + public void handleEndElement(String element, String ns) { + --level_; + + if (resultSetParser_ != null && level_ >= PAYLOAD_LEVEL) { + resultSetParser_.handleEndElement(element, ns); + } + + if (resultSetParser_ != null && level_ == PAYLOAD_LEVEL) { + MAMFin internalPayload = getPayloadInternal(); + Payload resultSetParserPayload = resultSetParser_.getPayload(); + if (resultSetParserPayload instanceof ResultSet) { + internalPayload.setResultSet((ResultSet) resultSetParser_.getPayload()); + } + resultSetParser_ = null; + } + } + + @Override + public void handleCharacterData(String data) { + if (resultSetParser_ != null) { + resultSetParser_.handleCharacterData(data); + } + } + +} diff --git a/src/com/isode/stroke/parser/payloadparsers/MAMQueryParser.java b/src/com/isode/stroke/parser/payloadparsers/MAMQueryParser.java index fcfd5e4..2543a68 100644 --- a/src/com/isode/stroke/parser/payloadparsers/MAMQueryParser.java +++ b/src/com/isode/stroke/parser/payloadparsers/MAMQueryParser.java @@ -24,9 +24,14 @@ public class MAMQueryParser extends GenericPayloadParser<MAMQuery> { public void handleStartElement(String element, String ns, AttributeMap attributes) { if (level_ == 0) { - String attributeValue = attributes.getAttributeValue("queryid"); - if (attributeValue != null) { - getPayloadInternal().setQueryID(attributeValue); + MAMQuery payloadInternal = getPayloadInternal(); + String queryIDValue = attributes.getAttributeValue("queryid"); + if (queryIDValue != null) { + payloadInternal.setQueryID(queryIDValue); + } + String nodeValue = attributes.getAttributeValue("node"); + if (nodeValue != null) { + payloadInternal.setNode(nodeValue); } } else if (level_ == 1) { if (element == "x" && ns == "jabber:x:data") { diff --git a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java index ee8ad05..5da22b8 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java +++ b/src/com/isode/stroke/serializer/payloadserializers/FullPayloadSerializerCollection.java @@ -66,7 +66,6 @@ public class FullPayloadSerializerCollection extends PayloadSerializerCollection 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 deleted file mode 100644 index 0a5f1f4..0000000 --- a/src/com/isode/stroke/serializer/payloadserializers/MAMArchivedSerializer.java +++ /dev/null @@ -1,33 +0,0 @@ -/* -* 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/MAMFinSerializer.java b/src/com/isode/stroke/serializer/payloadserializers/MAMFinSerializer.java new file mode 100644 index 0000000..3fcbc1d --- /dev/null +++ b/src/com/isode/stroke/serializer/payloadserializers/MAMFinSerializer.java @@ -0,0 +1,44 @@ +package com.isode.stroke.serializer.payloadserializers; + +import com.isode.stroke.elements.MAMFin; +import com.isode.stroke.elements.ResultSet; +import com.isode.stroke.serializer.GenericPayloadSerializer; +import com.isode.stroke.serializer.xml.XMLElement; +import com.isode.stroke.serializer.xml.XMLRawTextNode; + +public class MAMFinSerializer extends GenericPayloadSerializer<MAMFin> { + + public MAMFinSerializer() { + super(MAMFin.class); + } + + @Override + protected String serializePayload(MAMFin payload) { + if (payload == null) { + return ""; + } + + XMLElement element = new XMLElement("fin","urn:xmpp:mam:0"); + + if (payload.isComplete()) { + element.setAttribute("complete", "true"); + } + if (!payload.isStable()) { + element.setAttribute("stable", "false"); + } + String queryIDValue = payload.getQueryID(); + if (queryIDValue != null) { + element.setAttribute("queryid", queryIDValue); + } + ResultSet resultSet = payload.getResultSet(); + if (resultSet != null) { + ResultSetSerializer resultSetSerialized = new ResultSetSerializer(); + String serializedResultSet = resultSetSerialized.serialize(resultSet); + XMLRawTextNode rawTextNode = new XMLRawTextNode(serializedResultSet); + element.addNode(rawTextNode); + } + + return element.serialize(); + } + +} diff --git a/src/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializer.java b/src/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializer.java index 46cc42c..b027f7c 100644 --- a/src/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializer.java +++ b/src/com/isode/stroke/serializer/payloadserializers/MAMQuerySerializer.java @@ -21,6 +21,10 @@ public class MAMQuerySerializer extends GenericPayloadSerializer<MAMQuery> { if (payload.getQueryID() != null) { element.setAttribute("queryid", payload.getQueryID()); } + + if (payload.getNode() != null) { + element.setAttribute("node", payload.getNode()); + } if (payload.getForm() != null) { element.addNode(new XMLRawTextNode((new FormSerializer()).serialize(payload.getForm()))); |