2014-01-22 03:25:32 +01:00
|
|
|
/**
|
2014-02-17 18:57:38 +01:00
|
|
|
*
|
2014-07-16 11:46:30 +02:00
|
|
|
* Copyright 2013-2014 Georg Lukas
|
2014-01-22 03:25:32 +01:00
|
|
|
*
|
2014-02-17 18:57:38 +01:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
2014-01-22 03:25:32 +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.
|
|
|
|
*/
|
2015-01-09 11:02:11 +01:00
|
|
|
package org.jivesoftware.smackx.forward.packet;
|
2014-01-22 03:25:32 +01:00
|
|
|
|
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-07-16 11:46:30 +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.jivesoftware.smackx.delay.packet.DelayInformation;
|
2014-01-22 03:25:32 +01:00
|
|
|
|
|
|
|
/**
|
2017-12-25 12:51:41 +01:00
|
|
|
* Stanza extension for XEP-0297: Stanza Forwarding.
|
2014-01-22 03:25:32 +01:00
|
|
|
*
|
|
|
|
* @author Georg Lukas
|
2015-01-09 11:02:11 +01:00
|
|
|
* @see <a href="http://xmpp.org/extensions/xep-0297.html">XEP-0297: Stanza Forwarding</a>
|
2014-01-22 03:25:32 +01:00
|
|
|
*/
|
2015-02-26 18:41:17 +01:00
|
|
|
public class Forwarded implements ExtensionElement {
|
2014-01-22 03:25:32 +01:00
|
|
|
public static final String NAMESPACE = "urn:xmpp:forward:0";
|
2014-07-16 11:46:30 +02:00
|
|
|
public static final String ELEMENT = "forwarded";
|
2014-01-22 03:25:32 +01:00
|
|
|
|
2015-01-09 11:02:11 +01:00
|
|
|
private final DelayInformation delay;
|
2015-02-05 11:17:27 +01:00
|
|
|
private final Stanza forwardedPacket;
|
2014-01-22 03:25:32 +01:00
|
|
|
|
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Creates a new Forwarded stanza extension.
|
2014-01-22 03:25:32 +01:00
|
|
|
*
|
2014-06-30 13:36:49 +02:00
|
|
|
* @param delay an optional {@link DelayInformation} timestamp of the packet.
|
2018-03-31 14:17:30 +02:00
|
|
|
* @param fwdPacket the stanza that is forwarded (required).
|
2014-01-22 03:25:32 +01:00
|
|
|
*/
|
2015-02-05 11:17:27 +01:00
|
|
|
public Forwarded(DelayInformation delay, Stanza fwdPacket) {
|
2014-01-22 03:25:32 +01:00
|
|
|
this.delay = delay;
|
|
|
|
this.forwardedPacket = fwdPacket;
|
|
|
|
}
|
|
|
|
|
2014-01-31 04:52:13 +01:00
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* Creates a new Forwarded stanza extension.
|
2014-01-31 04:52:13 +01:00
|
|
|
*
|
2018-03-31 14:17:30 +02:00
|
|
|
* @param fwdPacket the stanza that is forwarded (required).
|
2014-01-31 04:52:13 +01:00
|
|
|
*/
|
2015-02-05 11:17:27 +01:00
|
|
|
public Forwarded(Stanza fwdPacket) {
|
2015-01-09 11:02:11 +01:00
|
|
|
this(null, fwdPacket);
|
2014-01-31 04:52:13 +01:00
|
|
|
}
|
|
|
|
|
2014-01-22 03:25:32 +01:00
|
|
|
@Override
|
|
|
|
public String getElementName() {
|
2014-07-16 11:46:30 +02:00
|
|
|
return ELEMENT;
|
2014-01-22 03:25:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getNamespace() {
|
|
|
|
return NAMESPACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-04-25 14:20:18 +02:00
|
|
|
public XmlStringBuilder toXML(String enclosingNamespace) {
|
2014-07-16 11:46:30 +02:00
|
|
|
XmlStringBuilder xml = new XmlStringBuilder(this);
|
2014-08-20 21:25:14 +02:00
|
|
|
xml.rightAngleBracket();
|
2014-07-16 11:46:30 +02:00
|
|
|
xml.optElement(getDelayInformation());
|
2018-05-09 16:52:22 +02:00
|
|
|
xml.append(forwardedPacket.toXML(NAMESPACE));
|
2014-07-16 11:46:30 +02:00
|
|
|
xml.closeElement(this);
|
|
|
|
return xml;
|
|
|
|
}
|
2014-01-22 03:25:32 +01:00
|
|
|
|
|
|
|
/**
|
2018-03-31 14:17:30 +02:00
|
|
|
* get the stanza forwarded by this stanza.
|
2014-01-22 03:25:32 +01:00
|
|
|
*
|
2015-02-05 11:17:27 +01:00
|
|
|
* @return the {@link Stanza} instance (typically a message) that was forwarded.
|
2015-06-02 17:30:23 +02:00
|
|
|
* @deprecated use @{link {@link #getForwardedStanza()}} instead.
|
2014-01-22 03:25:32 +01:00
|
|
|
*/
|
2015-06-02 17:30:23 +02:00
|
|
|
@Deprecated
|
2015-02-05 11:17:27 +01:00
|
|
|
public Stanza getForwardedPacket() {
|
2014-01-22 03:25:32 +01:00
|
|
|
return forwardedPacket;
|
|
|
|
}
|
|
|
|
|
2015-06-02 17:30:23 +02:00
|
|
|
/**
|
|
|
|
* Get the forwarded Stanza found in this extension.
|
|
|
|
*
|
|
|
|
* @return the {@link Stanza} (typically a message) that was forwarded.
|
|
|
|
*/
|
|
|
|
public Stanza getForwardedStanza() {
|
|
|
|
return forwardedPacket;
|
|
|
|
}
|
|
|
|
|
2014-01-22 03:25:32 +01:00
|
|
|
/**
|
|
|
|
* get the timestamp of the forwarded packet.
|
|
|
|
*
|
2018-03-31 14:17:30 +02:00
|
|
|
* @return the {@link DelayInformation} representing the time when the original stanza was sent. May be null.
|
2014-01-22 03:25:32 +01:00
|
|
|
*/
|
2015-01-09 11:02:11 +01:00
|
|
|
public DelayInformation getDelayInformation() {
|
|
|
|
return delay;
|
2014-06-30 13:36:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-03-29 12:15:32 +02:00
|
|
|
* Get the forwarded extension.
|
2015-01-09 11:02:11 +01:00
|
|
|
* @param packet
|
|
|
|
* @return the Forwarded extension or null
|
2014-06-30 13:36:49 +02:00
|
|
|
*/
|
2015-02-05 11:17:27 +01:00
|
|
|
public static Forwarded from(Stanza packet) {
|
2015-01-09 11:02:11 +01:00
|
|
|
return packet.getExtension(ELEMENT, NAMESPACE);
|
2014-01-22 03:25:32 +01:00
|
|
|
}
|
|
|
|
}
|