blob: 420ce6127874510d1bc3df793f3f8c415a183cdf [file] [log] [blame]
Shuyi Chend7955ce2013-05-22 14:51:55 -07001/**
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
21package org.jivesoftware.smackx.packet;
22
23import 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 */
33public 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 * &lt;message id="MlIpV-4" to="gato1@gato.home" from="gato3@gato.home/Smack"&gt;
75 * &lt;subject&gt;Any subject you want&lt;/subject&gt;
76 * &lt;body&gt;This message contains roster items.&lt;/body&gt;
77 * &lt;x xmlns="jabber:x:roster"&gt;
78 * &lt;item jid="gato1@gato.home"/&gt;
79 * &lt;item jid="gato2@gato.home"/&gt;
80 * &lt;/x&gt;
81 * &lt;/message&gt;
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}