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