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/time | |
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 '')
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacket.java | 35 | ||||
-rw-r--r-- | src/main/java/de/thedevstack/conversationsplus/xmpp/time/TimePacketGenerator.java | 38 |
2 files changed, 73 insertions, 0 deletions
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() {} +} |