2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
*
|
2014-07-13 10:16:10 +02:00
|
|
|
* Copyright 2013-2014 the original author or authors
|
2014-02-17 23:58:40 +01:00
|
|
|
*
|
|
|
|
* 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.receipts;
|
|
|
|
|
2014-10-07 21:15:20 +02:00
|
|
|
import java.io.IOException;
|
|
|
|
|
2017-06-14 17:12:43 +02:00
|
|
|
import org.jivesoftware.smack.packet.ExtensionElement;
|
2014-10-05 16:46:39 +02:00
|
|
|
import org.jivesoftware.smack.packet.Message;
|
2015-02-05 11:17:27 +01:00
|
|
|
import org.jivesoftware.smack.packet.Stanza;
|
2015-01-19 16:23:50 +01:00
|
|
|
import org.jivesoftware.smack.packet.id.StanzaIdUtil;
|
2015-02-26 18:41:17 +01:00
|
|
|
import org.jivesoftware.smack.provider.ExtensionElementProvider;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
import org.xmlpull.v1.XmlPullParser;
|
2014-10-07 21:15:20 +02:00
|
|
|
import org.xmlpull.v1.XmlPullParserException;
|
2014-02-17 23:58:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a <b>message delivery receipt request</b> entry as specified by
|
|
|
|
* <a href="http://xmpp.org/extensions/xep-0184.html">Message Delivery Receipts</a>.
|
|
|
|
*
|
|
|
|
* @author Georg Lukas
|
|
|
|
*/
|
2018-04-06 10:21:46 +02:00
|
|
|
public class DeliveryReceiptRequest implements ExtensionElement {
|
2014-02-17 23:58:40 +01:00
|
|
|
public static final String ELEMENT = "request";
|
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2018-04-06 10:21:46 +02:00
|
|
|
public String getElementName() {
|
2014-02-17 23:58:40 +01:00
|
|
|
return ELEMENT;
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2018-04-06 10:21:46 +02:00
|
|
|
public String getNamespace() {
|
2014-02-17 23:58:40 +01:00
|
|
|
return DeliveryReceipt.NAMESPACE;
|
|
|
|
}
|
|
|
|
|
2017-02-11 16:16:41 +01:00
|
|
|
@Override
|
2018-04-25 14:20:18 +02:00
|
|
|
public String toXML(String enclosingNamespace) {
|
2014-02-17 23:58:40 +01:00
|
|
|
return "<request xmlns='" + DeliveryReceipt.NAMESPACE + "'/>";
|
|
|
|
}
|
|
|
|
|
2014-07-13 10:16:10 +02:00
|
|
|
/**
|
|
|
|
* Get the {@link DeliveryReceiptRequest} extension of the packet, if any.
|
|
|
|
*
|
|
|
|
* @param p the packet
|
|
|
|
* @return the {@link DeliveryReceiptRequest} extension or {@code null}
|
2015-02-05 11:17:27 +01:00
|
|
|
* @deprecated use {@link #from(Stanza)} instead
|
2014-07-13 10:16:10 +02:00
|
|
|
*/
|
2014-09-16 22:14:10 +02:00
|
|
|
@Deprecated
|
2015-02-05 11:17:27 +01:00
|
|
|
public static DeliveryReceiptRequest getFrom(Stanza p) {
|
2014-09-16 22:14:10 +02:00
|
|
|
return from(p);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the {@link DeliveryReceiptRequest} extension of the packet, if any.
|
|
|
|
*
|
|
|
|
* @param packet the packet
|
|
|
|
* @return the {@link DeliveryReceiptRequest} extension or {@code null}
|
|
|
|
*/
|
2015-02-05 11:17:27 +01:00
|
|
|
public static DeliveryReceiptRequest from(Stanza packet) {
|
2014-09-16 22:14:10 +02:00
|
|
|
return packet.getExtension(ELEMENT, DeliveryReceipt.NAMESPACE);
|
2014-07-13 10:16:10 +02:00
|
|
|
}
|
|
|
|
|
2014-10-05 16:46:39 +02:00
|
|
|
/**
|
|
|
|
* Add a delivery receipt request to an outgoing packet.
|
|
|
|
*
|
|
|
|
* Only message packets may contain receipt requests as of XEP-0184,
|
|
|
|
* therefore only allow Message as the parameter type.
|
|
|
|
*
|
|
|
|
* @param message Message object to add a request to
|
|
|
|
* @return the Message ID which will be used as receipt ID
|
|
|
|
*/
|
|
|
|
public static String addTo(Message message) {
|
2015-02-05 11:17:27 +01:00
|
|
|
if (message.getStanzaId() == null) {
|
|
|
|
message.setStanzaId(StanzaIdUtil.newStanzaId());
|
2015-01-19 16:23:50 +01:00
|
|
|
}
|
2014-10-05 16:46:39 +02:00
|
|
|
message.addExtension(new DeliveryReceiptRequest());
|
2015-02-05 11:17:27 +01:00
|
|
|
return message.getStanzaId();
|
2014-10-05 16:46:39 +02:00
|
|
|
}
|
|
|
|
|
2014-02-17 23:58:40 +01:00
|
|
|
/**
|
|
|
|
* This Provider parses and returns DeliveryReceiptRequest packets.
|
|
|
|
*/
|
2015-02-26 18:41:17 +01:00
|
|
|
public static class Provider extends ExtensionElementProvider<DeliveryReceiptRequest> {
|
2014-02-17 23:58:40 +01:00
|
|
|
@Override
|
2014-10-07 21:15:20 +02:00
|
|
|
public DeliveryReceiptRequest parse(XmlPullParser parser,
|
|
|
|
int initialDepth) throws XmlPullParserException,
|
|
|
|
IOException {
|
2014-02-17 23:58:40 +01:00
|
|
|
return new DeliveryReceiptRequest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|