Home | History | Annotate | Download | only in packet
      1 /**
      2  * $RCSfile: PEPItem.java,v $
      3  * $Revision: 1.2 $
      4  * $Date: 2007/11/06 02:05:09 $
      5  *
      6  * Copyright 2003-2007 Jive Software.
      7  *
      8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
      9  * you may not use this file except in compliance with the License.
     10  * You may obtain a copy of the License at
     11  *
     12  *     http://www.apache.org/licenses/LICENSE-2.0
     13  *
     14  * Unless required by applicable law or agreed to in writing, software
     15  * distributed under the License is distributed on an "AS IS" BASIS,
     16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     17  * See the License for the specific language governing permissions and
     18  * limitations under the License.
     19  */
     20 
     21 package org.jivesoftware.smackx.packet;
     22 
     23 import org.jivesoftware.smack.packet.PacketExtension;
     24 
     25 /**
     26  * Represents XMPP Personal Event Protocol packets.<p>
     27  *
     28  * The 'http://jabber.org/protocol/pubsub#event' namespace  is used to publish personal events items from one client
     29  * to subscribed clients (See XEP-163).
     30  *
     31  * @author Jeff Williams
     32  */
     33 public abstract class PEPItem implements PacketExtension {
     34 
     35     String id;
     36     abstract String getNode();
     37     abstract String getItemDetailsXML();
     38 
     39     /**
     40     * Creates a new PEPItem.
     41     *
     42     */
     43     public PEPItem(String id) {
     44         super();
     45         this.id = id;
     46     }
     47 
     48      /**
     49     * Returns the XML element name of the extension sub-packet root element.
     50     * Always returns "x"
     51     *
     52     * @return the XML element name of the packet extension.
     53     */
     54     public String getElementName() {
     55         return "item";
     56     }
     57 
     58     /**
     59      * Returns the XML namespace of the extension sub-packet root element.
     60      *
     61      * @return the XML namespace of the packet extension.
     62      */
     63     public String getNamespace() {
     64         return "http://jabber.org/protocol/pubsub";
     65     }
     66 
     67     /**
     68      * Returns the XML representation of a Personal Event Publish according the specification.
     69      *
     70      * Usually the XML representation will be inside of a Message XML representation like
     71      * in the following example:
     72      * <pre>
     73      * &lt;message id="MlIpV-4" to="gato1 (at) gato.home" from="gato3 (at) gato.home/Smack"&gt;
     74      *     &lt;subject&gt;Any subject you want&lt;/subject&gt;
     75      *     &lt;body&gt;This message contains roster items.&lt;/body&gt;
     76      *     &lt;x xmlns="jabber:x:roster"&gt;
     77      *         &lt;item jid="gato1 (at) gato.home"/&gt;
     78      *         &lt;item jid="gato2 (at) gato.home"/&gt;
     79      *     &lt;/x&gt;
     80      * &lt;/message&gt;
     81      * </pre>
     82      *
     83      */
     84     public String toXML() {
     85         StringBuilder buf = new StringBuilder();
     86         buf.append("<").append(getElementName()).append(" id=\"").append(id).append("\">");
     87         buf.append(getItemDetailsXML());
     88         buf.append("</").append(getElementName()).append(">");
     89         return buf.toString();
     90     }
     91 
     92 }
     93