diff options
author | steckbrief <steckbrief@chefmail.de> | 2017-08-06 14:28:00 +0200 |
---|---|---|
committer | steckbrief <steckbrief@chefmail.de> | 2017-08-06 14:28:00 +0200 |
commit | be1992ce897d3b0551e545646a3e0f45cc6dd8c2 (patch) | |
tree | c15c94ade61e5063095d8b429ae4acf85459493f /src/main/java/de/thedevstack/conversationsplus/xmpp | |
parent | f8e083a32cb7232c9601f5011b14738d43bb3b06 (diff) |
Implements XEP-0202 Entity Time, moves Software Version to xmpp package, moves namespace definitions for mam, carbons and avatar to xmpp package
Diffstat (limited to 'src/main/java/de/thedevstack/conversationsplus/xmpp')
11 files changed, 172 insertions, 17 deletions
diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java index dfea06c8..54db5346 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java @@ -71,6 +71,7 @@ import de.thedevstack.conversationsplus.xml.Element; import de.thedevstack.conversationsplus.xml.Tag; import de.thedevstack.conversationsplus.xml.TagWriter; import de.thedevstack.conversationsplus.xml.XmlReader; +import de.thedevstack.conversationsplus.xmpp.carbons.Carbons; import de.thedevstack.conversationsplus.xmpp.filetransfer.http.FileTransferHttp; import de.thedevstack.conversationsplus.xmpp.filetransfer.http.upload.HttpUpload; import de.thedevstack.conversationsplus.xmpp.forms.Data; @@ -79,6 +80,7 @@ import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException; import de.thedevstack.conversationsplus.xmpp.jid.Jid; import de.thedevstack.conversationsplus.xmpp.jingle.OnJinglePacketReceived; import de.thedevstack.conversationsplus.xmpp.jingle.stanzas.JinglePacket; +import de.thedevstack.conversationsplus.xmpp.mam.Mam; import de.thedevstack.conversationsplus.xmpp.stanzas.AbstractAcknowledgeableStanza; import de.thedevstack.conversationsplus.xmpp.stanzas.AbstractStanza; import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; @@ -1133,7 +1135,7 @@ public class XmppConnection implements Runnable { private void sendEnableCarbons() { final IqPacket iq = new IqPacket(IqPacket.TYPE.SET); - iq.addChild("enable", "urn:xmpp:carbons:2"); + iq.addChild("enable", Carbons.NAMESPACE); this.sendIqPacket(iq, new OnIqPacketReceived() { @Override @@ -1490,7 +1492,7 @@ public class XmppConnection implements Runnable { } public boolean carbons() { - return hasDiscoFeature(account.getServer(), "urn:xmpp:carbons:2"); + return hasDiscoFeature(account.getServer(), Carbons.NAMESPACE); } public boolean blocking() { @@ -1525,8 +1527,8 @@ public class XmppConnection implements Runnable { } public boolean mam() { - return hasDiscoFeature(account.getJid().toBareJid(), "urn:xmpp:mam:0") - || hasDiscoFeature(account.getServer(), "urn:xmpp:mam:0"); + return hasDiscoFeature(account.getJid().toBareJid(), Mam.NAMESPACE) + || hasDiscoFeature(account.getServer(), Mam.NAMESPACE); } public boolean push() { diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacket.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacket.java new file mode 100644 index 00000000..86cb2274 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacket.java @@ -0,0 +1,8 @@ +package de.thedevstack.conversationsplus.xmpp.avatar; + +/** + */ +public class AvatarPacket { + public static final String NAMESPACE_AVATAR_DATA = "urn:xmpp:avatar:data"; + public static final String NAMESPACE_AVATAR_METADATA = "urn:xmpp:avatar:metadata"; +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketGenerator.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketGenerator.java index 4534e870..f9e04122 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketGenerator.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketGenerator.java @@ -9,11 +9,9 @@ import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; /** * Generates the IQ Packets for handling Avatars * as defined in XEP-0084. - * @see {@link http://xmpp.org/extensions/xep-0084.html} + * @see http://xmpp.org/extensions/xep-0084.html */ public final class AvatarPacketGenerator { - public static final String NAMESPACE_AVATAR_DATA = "urn:xmpp:avatar:data"; - public static final String NAMESPACE_AVATAR_METADATA = "urn:xmpp:avatar:metadata"; /** * Generates an IqPacket for publishing avatar data. @@ -37,9 +35,9 @@ public final class AvatarPacketGenerator { public static IqPacket generatePublishAvatarPacket(Avatar avatar) { final Element item = new Element("item"); item.setAttribute("id", avatar.sha1sum); - final Element data = item.addChild("data", NAMESPACE_AVATAR_DATA); + final Element data = item.addChild("data", AvatarPacket.NAMESPACE_AVATAR_DATA); data.setContent(avatar.image); - return PubSubPacketGenerator.generatePubSubPublishPacket(NAMESPACE_AVATAR_DATA, item); + return PubSubPacketGenerator.generatePubSubPublishPacket(AvatarPacket.NAMESPACE_AVATAR_DATA, item); } /** @@ -60,7 +58,7 @@ public final class AvatarPacketGenerator { public static IqPacket generateRetrieveAvatarPacket(Avatar avatar) { final Element item = new Element("item"); item.setAttribute("id", avatar.sha1sum); - final IqPacket packet = PubSubPacketGenerator.generatePubSubRetrievePacket(NAMESPACE_AVATAR_DATA, item); + final IqPacket packet = PubSubPacketGenerator.generatePubSubRetrievePacket(AvatarPacket.NAMESPACE_AVATAR_DATA, item); packet.setTo(avatar.owner); return packet; } @@ -91,14 +89,14 @@ public final class AvatarPacketGenerator { public static IqPacket generatePublishAvatarMetadataPacket(Avatar avatar) { final Element item = new Element("item"); item.setAttribute("id", avatar.sha1sum); - final Element metadata = item.addChild("metadata", NAMESPACE_AVATAR_METADATA); + final Element metadata = item.addChild("metadata", AvatarPacket.NAMESPACE_AVATAR_METADATA); final Element info = metadata.addChild("info"); info.setAttribute("bytes", avatar.size); info.setAttribute("id", avatar.sha1sum); info.setAttribute("height", avatar.height); info.setAttribute("width", avatar.height); info.setAttribute("type", avatar.type); - return PubSubPacketGenerator.generatePubSubPublishPacket(NAMESPACE_AVATAR_METADATA, item); + return PubSubPacketGenerator.generatePubSubPublishPacket(AvatarPacket.NAMESPACE_AVATAR_METADATA, item); } /** @@ -108,7 +106,7 @@ public final class AvatarPacketGenerator { * @return the IqPacket */ public static IqPacket generateRetrieveAvatarMetadataPacket(Jid to) { - final IqPacket packet = PubSubPacketGenerator.generatePubSubRetrievePacket(NAMESPACE_AVATAR_METADATA, null); + final IqPacket packet = PubSubPacketGenerator.generatePubSubRetrievePacket(AvatarPacket.NAMESPACE_AVATAR_METADATA, null); if (to != null) { packet.setTo(to); } diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketParser.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketParser.java index 175f54bd..e9f90898 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketParser.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/avatar/AvatarPacketParser.java @@ -8,7 +8,7 @@ import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; /** * Parses the IQ Packets for handling Avatars * as defined in XEP-0084. - * @see {@link http://xmpp.org/extensions/xep-0084.html} + * @see <a href="http://xmpp.org/extensions/xep-0084.html">http://xmpp.org/extensions/xep-0084.html</a> */ public class AvatarPacketParser { /** @@ -22,7 +22,7 @@ public class AvatarPacketParser { if (null != items) { Element item = items.findChild("item"); if (null != item) { - base64Avatar = item.findChildContent("data", AvatarPacketGenerator.NAMESPACE_AVATAR_DATA); + base64Avatar = item.findChildContent("data", AvatarPacket.NAMESPACE_AVATAR_DATA); } } return base64Avatar; diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/carbons/Carbons.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/carbons/Carbons.java new file mode 100644 index 00000000..89b9317b --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/carbons/Carbons.java @@ -0,0 +1,7 @@ +package de.thedevstack.conversationsplus.xmpp.carbons; + +/** + */ +public interface Carbons { + String NAMESPACE = "urn:xmpp:carbons:2"; +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/chatstate/ChatState.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/chatstate/ChatState.java index 323d99c2..805e1f33 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/chatstate/ChatState.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/chatstate/ChatState.java @@ -5,9 +5,9 @@ import de.thedevstack.conversationsplus.xml.Element; public enum ChatState { ACTIVE, INACTIVE, GONE, COMPOSING, PAUSED; + public static final String NAMESPACE = "http://jabber.org/protocol/chatstates"; public static ChatState parse(Element element) { - final String NAMESPACE = "http://jabber.org/protocol/chatstates"; if (element.hasChild("active",NAMESPACE)) { return ACTIVE; } else if (element.hasChild("inactive",NAMESPACE)) { @@ -24,7 +24,6 @@ public enum ChatState { } public static Element toElement(ChatState state) { - final String NAMESPACE = "http://jabber.org/protocol/chatstates"; final Element element = new Element(state.toString().toLowerCase()); element.setAttribute("xmlns",NAMESPACE); return element; diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/iqversion/IqVersionPacket.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/iqversion/IqVersionPacket.java new file mode 100644 index 00000000..a3cecdac --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/iqversion/IqVersionPacket.java @@ -0,0 +1,23 @@ +package de.thedevstack.conversationsplus.xmpp.iqversion; + +import android.os.Build; + +import de.thedevstack.conversationsplus.ConversationsPlusApplication; +import de.thedevstack.conversationsplus.xml.Element; +import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; + +/** + * Representation of an software version packet as defined in XEP-0092. + * @see <a href="http://xmpp.org/extensions/xep-0092.html">http://xmpp.org/extensions/xep-0092.html</a> + */ +public class IqVersionPacket extends IqPacket { + public static final String NAMESPACE = "jabber:iq:version"; + + IqVersionPacket() { + super(IqPacket.TYPE.RESULT); + Element query = this.addChild("query", NAMESPACE); + query.addChild("name").setContent(ConversationsPlusApplication.getName()); + query.addChild("version").setContent(ConversationsPlusApplication.getVersion()); + query.addChild("os").setContent("Android " + Build.VERSION.RELEASE); + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/iqversion/IqVersionPacketGenerator.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/iqversion/IqVersionPacketGenerator.java new file mode 100644 index 00000000..97a7e90d --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/iqversion/IqVersionPacketGenerator.java @@ -0,0 +1,38 @@ +package de.thedevstack.conversationsplus.xmpp.iqversion; + +import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; + +/** + * Generates the IQ Packets for Software Version + * as defined in XEP-0092. + * @see <a href="http://xmpp.org/extensions/xep-0092.html">http://xmpp.org/extensions/xep-0092.html</a> + */ +public final class IqVersionPacketGenerator { + + /** + * Generates the IqPacket to reply the software version. + * <pre> + * <iq from='juliet@capulet.com/balcony' + * type='result' + * to='romeo@montague.net/orchard' + * id='version_1'> + * <query xmlns='jabber:iq:version'> + * <name>Exodus</name> + * <version>0.7.0.4</version> + * <os>Windows-XP 5.01.2600</os> + * </query> + * </iq> + * </pre> + * @param packet the packet to respond to + * @return + */ + public static IqVersionPacket generateResponse(IqPacket packet) { + IqVersionPacket iqVersionPacket = new IqVersionPacket(); + iqVersionPacket.setTo(packet.getFrom()); + iqVersionPacket.setId(packet.getId()); + + return iqVersionPacket; + } + + private IqVersionPacketGenerator() {} +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/mam/Mam.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/mam/Mam.java new file mode 100644 index 00000000..e2228b32 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/mam/Mam.java @@ -0,0 +1,7 @@ +package de.thedevstack.conversationsplus.xmpp.mam; + +/** + */ +public interface Mam { + String NAMESPACE = "urn:xmpp:mam:0"; +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacket.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacket.java new file mode 100644 index 00000000..d8756d41 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacket.java @@ -0,0 +1,35 @@ +package de.thedevstack.conversationsplus.xmpp.time; + +import java.util.Locale; +import java.util.TimeZone; + +import de.thedevstack.conversationsplus.generator.AbstractGenerator; +import de.thedevstack.conversationsplus.xml.Element; +import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; + +/** + * Representation of an software version packet as defined in XEP-0202. + * @see <a href="http://xmpp.org/extensions/xep-0202.html">http://xmpp.org/extensions/xep-0202.html</a> + */ +public class TimePacket extends IqPacket { + public static final String NAMESPACE = "urn:xmpp:time"; + + TimePacket() { + super(IqPacket.TYPE.RESULT); + Element time = this.addChild("time", NAMESPACE); + final long now = System.currentTimeMillis(); + time.addChild("utc").setContent(AbstractGenerator.getTimestamp(now)); + TimeZone ourTimezone = TimeZone.getDefault(); + long offsetSeconds = ourTimezone.getOffset(now) / 1000; + long offsetMinutes = Math.abs((offsetSeconds % 3600) / 60); + long offsetHours = offsetSeconds / 3600; + String hours; + if (offsetHours < 0) { + hours = String.format(Locale.US, "%03d", offsetHours); + } else { + hours = String.format(Locale.US, "%02d", offsetHours); + } + String minutes = String.format(Locale.US, "%02d", offsetMinutes); + time.addChild("tzo").setContent(hours + ":" + minutes); + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacketGenerator.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacketGenerator.java new file mode 100644 index 00000000..344beb9e --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacketGenerator.java @@ -0,0 +1,38 @@ +package de.thedevstack.conversationsplus.xmpp.time; + +import de.thedevstack.conversationsplus.xmpp.iqversion.IqVersionPacket; +import de.thedevstack.conversationsplus.xmpp.stanzas.IqPacket; + +/** + * Generates the IQ Packets for Entity Time + * as defined in XEP-0202. + * @see <a href="http://xmpp.org/extensions/xep-0202.html">http://xmpp.org/extensions/xep-0202.html</a> + */ +public final class TimePacketGenerator { + + /** + * Generates the IqPacket to reply the entity time. + * <pre> + * <iq type='result' + * from='juliet@capulet.com/balcony' + * to='romeo@montague.net/orchard' + * id='time_1'> + * <time xmlns='urn:xmpp:time'> + * <tzo>-06:00</tzo> + * <utc>2006-12-19T17:58:35Z</utc> + * </time> + * </iq> + * </pre> + * @param packet + * @return + */ + public static TimePacket generateResponse(IqPacket packet) { + TimePacket timePacket = new TimePacket(); + timePacket.setTo(packet.getFrom()); + timePacket.setId(packet.getId()); + + return timePacket; + } + + private TimePacketGenerator() {} +} |