PEPPubSub.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.IQ;

  19. /**
  20.  * Represents XMPP PEP/XEP-163 pubsub packets.<p>
  21.  *
  22.  * The 'http://jabber.org/protocol/pubsub' 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 class PEPPubSub extends IQ {
  28.    
  29.     public static final String ELEMENT = "pubsub";
  30.     public static final String NAMESPACE = "http://jabber.org/protocol/pubsub";

  31.     private final PEPItem item;

  32.     /**
  33.     * Creates a new PubSub.
  34.     *
  35.     */
  36.     public PEPPubSub(PEPItem item) {
  37.         super(ELEMENT, NAMESPACE);
  38.         this.item = item;
  39.     }

  40.     /**
  41.      * Returns the XML representation of a Personal Event Publish according the specification.
  42.      *
  43.      * Usually the XML representation will be inside of a Message XML representation like
  44.      * in the following example:
  45.      * <pre>
  46.      * &lt;message id="MlIpV-4" to="gato1@gato.home" from="gato3@gato.home/Smack"&gt;
  47.      *     &lt;subject&gt;Any subject you want&lt;/subject&gt;
  48.      *     &lt;body&gt;This message contains roster items.&lt;/body&gt;
  49.      *     &lt;x xmlns="jabber:x:roster"&gt;
  50.      *         &lt;item jid="gato1@gato.home"/&gt;
  51.      *         &lt;item jid="gato2@gato.home"/&gt;
  52.      *     &lt;/x&gt;
  53.      * &lt;/message&gt;
  54.      * </pre>
  55.      *
  56.      */
  57.     @Override
  58.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
  59.         buf.rightAngleBracket();

  60.         buf.openElement("publish").attribute("node", item.getNode()).rightAngleBracket();
  61.         buf.append(item.toXML());
  62.         buf.closeElement("publish");

  63.         return buf;
  64.     }

  65. }