001/**
002 *
003 * Copyright 2013-2014 the original author or authors
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smackx.receipts;
018
019import org.jivesoftware.smack.packet.Packet;
020import org.jivesoftware.smack.packet.PacketExtension;
021import org.jivesoftware.smack.provider.PacketExtensionProvider;
022import org.xmlpull.v1.XmlPullParser;
023
024/**
025 * Represents a <b>message delivery receipt request</b> entry as specified by
026 * <a href="http://xmpp.org/extensions/xep-0184.html">Message Delivery Receipts</a>.
027 *
028 * @author Georg Lukas
029 */
030public class DeliveryReceiptRequest implements PacketExtension
031{
032    public static final String ELEMENT = "request";
033
034    public String getElementName()
035    {
036        return ELEMENT;
037    }
038
039    public String getNamespace()
040    {
041        return DeliveryReceipt.NAMESPACE;
042    }
043
044    public String toXML()
045    {
046        return "<request xmlns='" + DeliveryReceipt.NAMESPACE + "'/>";
047    }
048
049    /**
050     * Get the {@link DeliveryReceiptRequest} extension of the packet, if any.
051     *
052     * @param p the packet
053     * @return the {@link DeliveryReceiptRequest} extension or {@code null}
054     */
055    public static DeliveryReceiptRequest getFrom(Packet p) {
056        return p.getExtension(ELEMENT, DeliveryReceipt.NAMESPACE);
057    }
058
059    /**
060     * This Provider parses and returns DeliveryReceiptRequest packets.
061     */
062    public static class Provider implements PacketExtensionProvider {
063        @Override
064        public PacketExtension parseExtension(XmlPullParser parser) {
065            return new DeliveryReceiptRequest();
066        }
067    }
068}