001/**
002 *
003 * Copyright the original author or authors
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 */
017package org.jivesoftware.smackx.pubsub;
018
019import org.jivesoftware.smack.util.XmlStringBuilder;
020
021
022/**
023 * Represents an unsubscribe element.
024 * 
025 * @author Robin Collier
026 */
027public class UnsubscribeExtension extends NodeExtension
028{
029    protected String jid;
030    protected String id;
031
032    public UnsubscribeExtension(String subscriptionJid)
033    {
034        this(subscriptionJid, null, null);
035    }
036
037    public UnsubscribeExtension(String subscriptionJid, String nodeId)
038    {
039        this(subscriptionJid, nodeId, null);
040    }
041
042    public UnsubscribeExtension(String jid, String nodeId, String subscriptionId)
043    {
044        super(PubSubElementType.UNSUBSCRIBE, nodeId);
045        this.jid = jid;
046        id = subscriptionId;
047    }
048
049    public String getJid()
050    {
051        return jid;
052    }
053
054    public String getId()
055    {
056        return id;
057    }
058
059    @Override
060    public XmlStringBuilder toXML() {
061        XmlStringBuilder xml = new XmlStringBuilder();
062        xml.halfOpenElement(getElementName());
063        xml.attribute("jid", jid);
064        xml.optAttribute("node", getNode());
065        xml.optAttribute("subid", id);
066        xml.closeEmptyElement();
067        return xml;
068    }
069}