001/**
002 *
003 * Copyright 2003-2007 Jive Software.
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018package org.jivesoftware.smackx.pep.packet;
019
020import org.jivesoftware.smack.packet.IQ;
021
022/**
023 * Represents XMPP PEP/XEP-163 pubsub packets.<p>
024 * 
025 * The 'http://jabber.org/protocol/pubsub' namespace  is used to publish personal events items from one client 
026 * to subscribed clients (See XEP-163).
027 *
028 * @author Jeff Williams
029 */
030public class PEPPubSub extends IQ {
031    
032    public static final String ELEMENT = "pubsub";
033    public static final String NAMESPACE = "http://jabber.org/protocol/pubsub";
034
035    private final PEPItem item;
036
037    /**
038    * Creates a new PubSub.
039    *
040    */
041    public PEPPubSub(PEPItem item) {
042        super(ELEMENT, NAMESPACE);
043        this.item = item;
044    }
045
046    /**
047     * Returns the XML representation of a Personal Event Publish according the specification.
048     * 
049     * Usually the XML representation will be inside of a Message XML representation like
050     * in the following example:
051     * <pre>
052     * &lt;message id="MlIpV-4" to="gato1@gato.home" from="gato3@gato.home/Smack"&gt;
053     *     &lt;subject&gt;Any subject you want&lt;/subject&gt;
054     *     &lt;body&gt;This message contains roster items.&lt;/body&gt;
055     *     &lt;x xmlns="jabber:x:roster"&gt;
056     *         &lt;item jid="gato1@gato.home"/&gt;
057     *         &lt;item jid="gato2@gato.home"/&gt;
058     *     &lt;/x&gt;
059     * &lt;/message&gt;
060     * </pre>
061     * 
062     */
063    @Override
064    protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder buf) {
065        buf.rightAngleBracket();
066
067        buf.openElement("publish").attribute("node", item.getNode()).rightAngleBracket();
068        buf.append(item.toXML());
069        buf.closeElement("publish");
070
071        return buf;
072    }
073
074}