2005-01-28 23:59:40 +01:00
|
|
|
/**
|
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Copyright the original author or authors
|
2005-01-28 23:59:40 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2005-01-28 23:59:40 +01:00
|
|
|
* 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.
|
|
|
|
*/
|
2014-02-15 11:35:08 +01:00
|
|
|
package org.jivesoftware.smackx.delay.packet;
|
2005-01-28 23:59:40 +01:00
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
2020-04-05 22:10:05 +02:00
|
|
|
import javax.xml.namespace.QName;
|
|
|
|
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.jivesoftware.smack.packet.Stanza;
|
2014-06-30 13:36:49 +02:00
|
|
|
import org.jivesoftware.smack.util.XmlStringBuilder;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-06-30 13:36:49 +02:00
|
|
|
import org.jxmpp.util.XmppDateTime;
|
2010-08-15 15:20:48 +02:00
|
|
|
|
2005-01-28 23:59:40 +01:00
|
|
|
/**
|
2018-05-09 23:06:12 +02:00
|
|
|
* 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
|
2018-03-31 14:17:30 +02:00
|
|
|
* information such as the JID of the entity that originally sent the stanza as well as the reason
|
2010-08-15 15:20:48 +02:00
|
|
|
* for the delay.<p>
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2010-08-15 15:20:48 +02:00
|
|
|
* 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>.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2005-01-28 23:59:40 +01:00
|
|
|
* @author Gaston Dombiak
|
2014-06-30 13:36:49 +02:00
|
|
|
* @author Florian Schmaus
|
2005-01-28 23:59:40 +01:00
|
|
|
*/
|
2015-02-26 18:41:17 +01:00
|
|
|
public class DelayInformation implements ExtensionElement {
|
2014-06-30 13:36:49 +02:00
|
|
|
public static final String ELEMENT = "delay";
|
|
|
|
public static final String NAMESPACE = "urn:xmpp:delay";
|
2020-04-05 22:10:05 +02:00
|
|
|
public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
|
2005-01-28 23:59:40 +01:00
|
|
|
|
2014-06-30 13:36:49 +02:00
|
|
|
private final Date stamp;
|
|
|
|
private final String from;
|
|
|
|
private final String reason;
|
2005-01-28 23:59:40 +01:00
|
|
|
|
|
|
|
/**
|
2018-05-09 23:06:12 +02:00
|
|
|
* Creates a new instance with the specified timestamp.
|
2010-08-15 15:20:48 +02:00
|
|
|
* @param stamp the timestamp
|
2017-12-23 20:21:19 +01:00
|
|
|
* @param from sender
|
|
|
|
* @param reason reason of delay.
|
2005-01-28 23:59:40 +01:00
|
|
|
*/
|
2014-06-30 13:36:49 +02:00
|
|
|
public DelayInformation(Date stamp, String from, String reason) {
|
2005-01-28 23:59:40 +01:00
|
|
|
this.stamp = stamp;
|
2014-06-30 13:36:49 +02:00
|
|
|
this.from = from;
|
|
|
|
this.reason = reason;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DelayInformation(Date stamp) {
|
|
|
|
this(stamp, null, null);
|
2005-01-28 23:59:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-09 23:06:12 +02:00
|
|
|
* Returns the JID of the entity that originally sent the stanza or that delayed the
|
2019-07-19 18:10:36 +02:00
|
|
|
* delivery of the stanza or <code>null</code> if this information is not available.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
|
|
|
* @return the JID of the entity that originally sent the stanza or that delayed the
|
2005-01-28 23:59:40 +01:00
|
|
|
* delivery of the packet.
|
|
|
|
*/
|
|
|
|
public String getFrom() {
|
|
|
|
return from;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-05-09 23:06:12 +02:00
|
|
|
* Returns the timestamp when the stanza was originally sent. The returned Date is
|
2005-01-28 23:59:40 +01:00
|
|
|
* be understood as UTC.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2018-03-31 14:17:30 +02:00
|
|
|
* @return the timestamp when the stanza was originally sent.
|
2005-01-28 23:59:40 +01:00
|
|
|
*/
|
|
|
|
public Date getStamp() {
|
|
|
|
return stamp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-07-19 18:10:36 +02:00
|
|
|
* Returns a natural-language description of the reason for the delay or <code>null</code> if
|
2005-01-28 23:59:40 +01:00
|
|
|
* this information is not available.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2019-07-19 18:10:36 +02:00
|
|
|
* @return a natural-language description of the reason for the delay or <code>null</code>.
|
2005-01-28 23:59:40 +01:00
|
|
|
*/
|
|
|
|
public String getReason() {
|
|
|
|
return reason;
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2005-01-28 23:59:40 +01:00
|
|
|
public String getElementName() {
|
2014-06-30 13:36:49 +02:00
|
|
|
return ELEMENT;
|
2005-01-28 23:59:40 +01:00
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2005-01-28 23:59:40 +01:00
|
|
|
public String getNamespace() {
|
2014-06-30 13:36:49 +02:00
|
|
|
return NAMESPACE;
|
2005-01-28 23:59:40 +01:00
|
|
|
}
|
|
|
|
|
2014-06-30 13:36:49 +02:00
|
|
|
@Override
|
2019-02-04 13:27:41 +01:00
|
|
|
public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
|
2019-09-07 18:17:08 +02:00
|
|
|
XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
|
2014-06-30 13:36:49 +02:00
|
|
|
xml.attribute("stamp", XmppDateTime.formatXEP0082Date(stamp));
|
|
|
|
xml.optAttribute("from", from);
|
2019-09-24 23:32:08 +02:00
|
|
|
xml.optTextChild(reason, this);
|
2014-06-30 13:36:49 +02:00
|
|
|
return xml;
|
2005-01-28 23:59:40 +01:00
|
|
|
}
|
|
|
|
|
2014-09-16 22:14:10 +02:00
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Return delay information from the given stanza.
|
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param packet TODO javadoc me please
|
2014-09-16 22:14:10 +02:00
|
|
|
* @return the DelayInformation or null
|
2015-02-05 11:17:27 +01:00
|
|
|
* @deprecated use {@link #from(Stanza)} instead
|
2014-09-16 22:14:10 +02:00
|
|
|
*/
|
|
|
|
@Deprecated
|
2015-02-05 11:17:27 +01:00
|
|
|
public static DelayInformation getFrom(Stanza packet) {
|
2014-09-16 22:14:10 +02:00
|
|
|
return from(packet);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Return delay information from the given stanza.
|
|
|
|
*
|
2019-08-30 12:08:30 +02:00
|
|
|
* @param packet TODO javadoc me please
|
2014-09-16 22:14:10 +02:00
|
|
|
* @return the DelayInformation or null
|
|
|
|
*/
|
2015-02-05 11:17:27 +01:00
|
|
|
public static DelayInformation from(Stanza packet) {
|
2020-04-05 22:10:05 +02:00
|
|
|
return packet.getExtension(DelayInformation.class);
|
2014-07-16 11:46:30 +02:00
|
|
|
}
|
2005-01-28 23:59:40 +01:00
|
|
|
}
|