PEPItem.java

  1. /**
  2.  *
  3.  * Copyright 2003-2007 Jive Software.
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */

  17. package org.jivesoftware.smackx.pep.packet;

  18. import org.jivesoftware.smack.packet.ExtensionElement;

  19. /**
  20.  * Represents XMPP Personal Event Protocol packets.<p>
  21.  *
  22.  * The 'http://jabber.org/protocol/pubsub#event' namespace  is used to publish personal events items from one client
  23.  * to subscribed clients (See XEP-163).
  24.  *
  25.  * @author Jeff Williams
  26.  */
  27. public abstract class PEPItem implements ExtensionElement {
  28.    
  29.     String id;
  30.     abstract String getNode();
  31.     abstract String getItemDetailsXML();
  32.    
  33.     /**
  34.     * Creates a new PEPItem.
  35.     *
  36.     */
  37.     public PEPItem(String id) {
  38.         super();
  39.         this.id = id;
  40.     }
  41.    
  42.      /**
  43.     * Returns the XML element name of the extension sub-packet root element.
  44.     * Always returns "x"
  45.     *
  46.     * @return the XML element name of the packet extension.
  47.     */
  48.     public String getElementName() {
  49.         return "item";
  50.     }

  51.     /**
  52.      * Returns the XML namespace of the extension sub-packet root element.
  53.      *
  54.      * @return the XML namespace of the packet extension.
  55.      */
  56.     public String getNamespace() {
  57.         return "http://jabber.org/protocol/pubsub";
  58.     }

  59.     /**
  60.      * Returns the XML representation of a Personal Event Publish according the specification.
  61.      *
  62.      * Usually the XML representation will be inside of a Message XML representation like
  63.      * in the following example:
  64.      * <pre>
  65.      * &lt;message id="MlIpV-4" to="gato1@gato.home" from="gato3@gato.home/Smack"&gt;
  66.      *     &lt;subject&gt;Any subject you want&lt;/subject&gt;
  67.      *     &lt;body&gt;This message contains roster items.&lt;/body&gt;
  68.      *     &lt;x xmlns="jabber:x:roster"&gt;
  69.      *         &lt;item jid="gato1@gato.home"/&gt;
  70.      *         &lt;item jid="gato2@gato.home"/&gt;
  71.      *     &lt;/x&gt;
  72.      * &lt;/message&gt;
  73.      * </pre>
  74.      *
  75.      */
  76.     public String toXML() {
  77.         StringBuilder buf = new StringBuilder();
  78.         buf.append("<").append(getElementName()).append(" id=\"").append(id).append("\">");
  79.         buf.append(getItemDetailsXML());
  80.         buf.append("</").append(getElementName()).append(">");
  81.         return buf.toString();
  82.     }

  83. }