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