1 /** 2 * $RCSfile: PEPPubSub.java,v $ 3 * $Revision: 1.2 $ 4 * $Date: 2007/11/03 04:46:52 $ 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.IQ; 24 25 /** 26 * Represents XMPP PEP/XEP-163 pubsub packets.<p> 27 * 28 * The 'http://jabber.org/protocol/pubsub' 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 PEPPubSub extends IQ { 34 35 PEPItem item; 36 37 /** 38 * Creates a new PubSub. 39 * 40 */ 41 public PEPPubSub(PEPItem item) { 42 super(); 43 44 this.item = item; 45 } 46 47 /** 48 * Returns the XML element name of the extension sub-packet root element. 49 * Always returns "x" 50 * 51 * @return the XML element name of the packet extension. 52 */ 53 public String getElementName() { 54 return "pubsub"; 55 } 56 57 /** 58 * Returns the XML namespace of the extension sub-packet root element. 59 * According the specification the namespace is always "jabber:x:roster" 60 * (which is not to be confused with the 'jabber:iq:roster' namespace 61 * 62 * @return the XML namespace of the packet extension. 63 */ 64 public String getNamespace() { 65 return "http://jabber.org/protocol/pubsub"; 66 } 67 68 /** 69 * Returns the XML representation of a Personal Event Publish according the specification. 70 * 71 * Usually the XML representation will be inside of a Message XML representation like 72 * in the following example: 73 * <pre> 74 * <message id="MlIpV-4" to="gato1 (at) gato.home" from="gato3 (at) gato.home/Smack"> 75 * <subject>Any subject you want</subject> 76 * <body>This message contains roster items.</body> 77 * <x xmlns="jabber:x:roster"> 78 * <item jid="gato1 (at) gato.home"/> 79 * <item jid="gato2 (at) gato.home"/> 80 * </x> 81 * </message> 82 * </pre> 83 * 84 */ 85 public String getChildElementXML() { 86 StringBuilder buf = new StringBuilder(); 87 buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append("\">"); 88 buf.append("<publish node=\"").append(item.getNode()).append("\">"); 89 buf.append(item.toXML()); 90 buf.append("</publish>"); 91 buf.append("</").append(getElementName()).append(">"); 92 return buf.toString(); 93 } 94 95 } 96