Home | History | Annotate | Download | only in receipts
      1 /**
      2  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
      3  * you may not use this file except in compliance with the License.
      4  * You may obtain a copy of the License at
      5  *
      6  *     http://www.apache.org/licenses/LICENSE-2.0
      7  *
      8  * Unless required by applicable law or agreed to in writing, software
      9  * distributed under the License is distributed on an "AS IS" BASIS,
     10  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     11  * See the License for the specific language governing permissions and
     12  * limitations under the License.
     13  */
     14 package org.jivesoftware.smackx.receipts;
     15 
     16 import java.util.List;
     17 import java.util.Map;
     18 
     19 import org.jivesoftware.smack.packet.PacketExtension;
     20 import org.jivesoftware.smack.provider.EmbeddedExtensionProvider;
     21 
     22 /**
     23  * Represents a <b>message delivery receipt</b> entry as specified by
     24  * <a href="http://xmpp.org/extensions/xep-0184.html">Message Delivery Receipts</a>.
     25  *
     26  * @author Georg Lukas
     27  */
     28 public class DeliveryReceipt implements PacketExtension
     29 {
     30     public static final String NAMESPACE = "urn:xmpp:receipts";
     31     public static final String ELEMENT = "received";
     32 
     33     private String id; /// original ID of the delivered message
     34 
     35     public DeliveryReceipt(String id)
     36     {
     37         this.id = id;
     38     }
     39 
     40     public String getId()
     41     {
     42         return id;
     43     }
     44 
     45     @Override
     46     public String getElementName()
     47     {
     48         return ELEMENT;
     49     }
     50 
     51     @Override
     52     public String getNamespace()
     53     {
     54         return NAMESPACE;
     55     }
     56 
     57     @Override
     58     public String toXML()
     59     {
     60         return "<received xmlns='" + NAMESPACE + "' id='" + id + "'/>";
     61     }
     62 
     63     /**
     64      * This Provider parses and returns DeliveryReceipt packets.
     65      */
     66     public static class Provider extends EmbeddedExtensionProvider
     67     {
     68 
     69         @Override
     70         protected PacketExtension createReturnExtension(String currentElement, String currentNamespace,
     71                 Map<String, String> attributeMap, List<? extends PacketExtension> content)
     72         {
     73             return new DeliveryReceipt(attributeMap.get("id"));
     74         }
     75 
     76     }
     77 }
     78