blob: ac14c603a4216f96e048ad871fffc98d2dc7060d [file] [log] [blame]
Shuyi Chend7955ce2013-05-22 14:51:55 -07001/**
2 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14package org.jivesoftware.smackx.pubsub;
15
16import org.jivesoftware.smackx.pubsub.util.XmlUtils;
17
18
19/**
20 * Represents an unsubscribe element.
21 *
22 * @author Robin Collier
23 */
24public class UnsubscribeExtension extends NodeExtension
25{
26 protected String jid;
27 protected String id;
28
29 public UnsubscribeExtension(String subscriptionJid)
30 {
31 this(subscriptionJid, null, null);
32 }
33
34 public UnsubscribeExtension(String subscriptionJid, String nodeId)
35 {
36 this(subscriptionJid, nodeId, null);
37 }
38
39 public UnsubscribeExtension(String jid, String nodeId, String subscriptionId)
40 {
41 super(PubSubElementType.UNSUBSCRIBE, nodeId);
42 this.jid = jid;
43 id = subscriptionId;
44 }
45
46 public String getJid()
47 {
48 return jid;
49 }
50
51 public String getId()
52 {
53 return id;
54 }
55
56 @Override
57 public String toXML()
58 {
59 StringBuilder builder = new StringBuilder("<");
60 builder.append(getElementName());
61 XmlUtils.appendAttribute(builder, "jid", jid);
62
63 if (getNode() != null)
64 XmlUtils.appendAttribute(builder, "node", getNode());
65
66 if (id != null)
67 XmlUtils.appendAttribute(builder, "subid", id);
68
69 builder.append("/>");
70 return builder.toString();
71 }
72
73}