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 PEPItem item; 033 034 /** 035 * Creates a new PubSub. 036 * 037 */ 038 public PEPPubSub(PEPItem item) { 039 super(); 040 041 this.item = item; 042 } 043 044 /** 045 * Returns the XML element name of the extension sub-packet root element. 046 * Always returns "x" 047 * 048 * @return the XML element name of the packet extension. 049 */ 050 public String getElementName() { 051 return "pubsub"; 052 } 053 054 /** 055 * Returns the XML namespace of the extension sub-packet root element. 056 * According the specification the namespace is always "jabber:x:roster" 057 * (which is not to be confused with the 'jabber:iq:roster' namespace 058 * 059 * @return the XML namespace of the packet extension. 060 */ 061 public String getNamespace() { 062 return "http://jabber.org/protocol/pubsub"; 063 } 064 065 /** 066 * Returns the XML representation of a Personal Event Publish according the specification. 067 * 068 * Usually the XML representation will be inside of a Message XML representation like 069 * in the following example: 070 * <pre> 071 * <message id="MlIpV-4" to="gato1@gato.home" from="gato3@gato.home/Smack"> 072 * <subject>Any subject you want</subject> 073 * <body>This message contains roster items.</body> 074 * <x xmlns="jabber:x:roster"> 075 * <item jid="gato1@gato.home"/> 076 * <item jid="gato2@gato.home"/> 077 * </x> 078 * </message> 079 * </pre> 080 * 081 */ 082 public String getChildElementXML() { 083 StringBuilder buf = new StringBuilder(); 084 buf.append("<").append(getElementName()).append(" xmlns=\"").append(getNamespace()).append("\">"); 085 buf.append("<publish node=\"").append(item.getNode()).append("\">"); 086 buf.append(item.toXML()); 087 buf.append("</publish>"); 088 buf.append("</").append(getElementName()).append(">"); 089 return buf.toString(); 090 } 091 092}