Home | History | Annotate | Download | only in packet
      1 /**
      2  * $RCSfile: PEPEvent.java,v $
      3  * $Revision: 1.1 $
      4  * $Date: 2007/11/03 00:14:32 $
      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 class PEPEvent implements PacketExtension {
     34 
     35     PEPItem item;
     36 
     37     /**
     38      * Creates a new empty roster exchange package.
     39      *
     40      */
     41     public PEPEvent() {
     42         super();
     43     }
     44 
     45     /**
     46      * Creates a new empty roster exchange package.
     47      *
     48      */
     49     public PEPEvent(PEPItem item) {
     50         super();
     51 
     52         this.item = item;
     53     }
     54 
     55     public void addPEPItem(PEPItem item) {
     56         this.item = item;
     57     }
     58 
     59     /**
     60     * Returns the XML element name of the extension sub-packet root element.
     61     * Always returns "x"
     62     *
     63     * @return the XML element name of the packet extension.
     64     */
     65     public String getElementName() {
     66         return "event";
     67     }
     68 
     69     /**
     70      * Returns the XML namespace of the extension sub-packet root element.
     71      * According the specification the namespace is always "jabber:x:roster"
     72      * (which is not to be confused with the 'jabber:iq:roster' namespace
     73      *
     74      * @return the XML namespace of the packet extension.
     75      */
     76     public String getNamespace() {
     77         return "http://jabber.org/protocol/pubsub";
     78     }
     79 
     80     /**
     81      * Returns the XML representation of a Personal Event Publish according the specification.
     82      *
     83      * Usually the XML representation will be inside of a Message XML representation like
     84      * in the following example:
     85      * <pre>
     86      * &lt;message id="MlIpV-4" to="gato1 (at) gato.home" from="gato3 (at) gato.home/Smack"&gt;
     87      *     &lt;subject&gt;Any subject you want&lt;/subject&gt;
     88      *     &lt;body&gt;This message contains roster items.&lt;/body&gt;
     89      *     &lt;x xmlns="jabber:x:roster"&gt;
     90      *         &lt;item jid="gato1 (at) gato.home"/&gt;
     91      *         &lt;item jid="gato2 (at) gato.home"/&gt;
     92      *     &lt;/x&gt;
     93      * &lt;/message&gt;
     94      * </pre>
     95      *
     96      */
     97     public String toXML() {
     98         StringBuilder buf = new StringBuilder();
     99         buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append("\">");
    100         buf.append(item.toXML());
    101         buf.append("</").append(getElementName()).append(">");
    102         return buf.toString();
    103     }
    104 
    105 }
    106