1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2024-06-26 05:14:49 +02:00
Smack/smack-extensions/src/main/java/org/jivesoftware/smackx/delay/packet/DelayInformation.java
Florian Schmaus eeb6c52f7e Move SASL logic into AbstractXMPPConnection
Besides the way the transport handles the stream after SASL
<success/>, the SASL logic is independend from the underlying
transport (BOSH, TCP, …). Hence move it up into
AbstractXMPPConnection.

This also has the benefit that we can make some more methods private
or package-private.

Also introduce XmlStringBuilder.optTextChild(), which causes some
associated changes.
2019-09-25 13:49:21 +02:00

135 lines
4.1 KiB
Java

/**
*
* Copyright the original author or authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smackx.delay.packet;
import java.util.Date;
import org.jivesoftware.smack.packet.ExtensionElement;
import org.jivesoftware.smack.packet.Stanza;
import org.jivesoftware.smack.util.XmlStringBuilder;
import org.jxmpp.util.XmppDateTime;
/**
* Represents timestamp information about data stored for later delivery. A DelayInformation will
* always includes the timestamp when the stanza was originally sent and may include more
* information such as the JID of the entity that originally sent the stanza as well as the reason
* for the delay.<p>
*
* For more information see <a href="http://xmpp.org/extensions/xep-0091.html">XEP-0091</a>
* and <a href="http://xmpp.org/extensions/xep-0203.html">XEP-0203</a>.
*
* @author Gaston Dombiak
* @author Florian Schmaus
*/
public class DelayInformation implements ExtensionElement {
public static final String ELEMENT = "delay";
public static final String NAMESPACE = "urn:xmpp:delay";
private final Date stamp;
private final String from;
private final String reason;
/**
* Creates a new instance with the specified timestamp.
* @param stamp the timestamp
* @param from sender
* @param reason reason of delay.
*/
public DelayInformation(Date stamp, String from, String reason) {
this.stamp = stamp;
this.from = from;
this.reason = reason;
}
public DelayInformation(Date stamp) {
this(stamp, null, null);
}
/**
* Returns the JID of the entity that originally sent the stanza or that delayed the
* delivery of the stanza or <code>null</code> if this information is not available.
*
* @return the JID of the entity that originally sent the stanza or that delayed the
* delivery of the packet.
*/
public String getFrom() {
return from;
}
/**
* Returns the timestamp when the stanza was originally sent. The returned Date is
* be understood as UTC.
*
* @return the timestamp when the stanza was originally sent.
*/
public Date getStamp() {
return stamp;
}
/**
* Returns a natural-language description of the reason for the delay or <code>null</code> if
* this information is not available.
*
* @return a natural-language description of the reason for the delay or <code>null</code>.
*/
public String getReason() {
return reason;
}
@Override
public String getElementName() {
return ELEMENT;
}
@Override
public String getNamespace() {
return NAMESPACE;
}
@Override
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
xml.attribute("stamp", XmppDateTime.formatXEP0082Date(stamp));
xml.optAttribute("from", from);
xml.optTextChild(reason, this);
return xml;
}
/**
* Return delay information from the given stanza.
*
* @param packet TODO javadoc me please
* @return the DelayInformation or null
* @deprecated use {@link #from(Stanza)} instead
*/
@Deprecated
public static DelayInformation getFrom(Stanza packet) {
return from(packet);
}
/**
* Return delay information from the given stanza.
*
* @param packet TODO javadoc me please
* @return the DelayInformation or null
*/
public static DelayInformation from(Stanza packet) {
return packet.getExtension(ELEMENT, NAMESPACE);
}
}