1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-13 00:21:07 +01:00

Cleanup carbons, forwarded and a few others API

Adopt to common design patterns in Smack:

- getFrom(Packet) in Packetextensions
- INSTANCES.put() in getInstanceFor()
- ELEMENT instead of ELEMENT_NAME
- Use XmlStringBuilder
This commit is contained in:
Florian Schmaus 2014-07-16 11:46:30 +02:00
parent 1ed5c48bcc
commit 49ee058c38
14 changed files with 105 additions and 90 deletions

View file

@ -44,7 +44,7 @@ public class DelayInformationManager {
* @return the Delayed Delivery information or <code>null</code>
*/
public static DelayInformation getXep203DelayInformation(Packet packet) {
return (DelayInformation) packet.getExtension(DelayInformation.ELEMENT, DelayInformation.NAMESPACE);
return DelayInformation.getFrom(packet);
}
/**
@ -56,7 +56,7 @@ public class DelayInformationManager {
* @return the Delayed Delivery information or <code>null</code>
*/
public static DelayInformation getLegacyDelayInformation(Packet packet) {
return (DelayInformation) packet.getExtension(LEGACY_DELAYED_DELIVERY_ELEMENT, LEGACY_DELAYED_DELIVERY_NAMESPACE);
return packet.getExtension(LEGACY_DELAYED_DELIVERY_ELEMENT, LEGACY_DELAYED_DELIVERY_NAMESPACE);
}
/**

View file

@ -18,6 +18,7 @@ package org.jivesoftware.smackx.delay.packet;
import java.util.Date;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jxmpp.util.XmppDateTime;
@ -96,16 +97,17 @@ public class DelayInformation implements PacketExtension {
}
@Override
public CharSequence toXML() {
public XmlStringBuilder toXML() {
XmlStringBuilder xml = new XmlStringBuilder(this);
xml.attribute("stamp", XmppDateTime.formatXEP0082Date(stamp));
xml.optAttribute("from", from);
xml.rightAngelBracket();
if (reason != null) {
xml.escape(reason);
}
xml.optAppend(reason);
xml.closeElement(this);
return xml;
}
public static DelayInformation getFrom(Packet packet) {
return packet.getExtension(ELEMENT, NAMESPACE);
}
}