001/**
002 *
003 * Copyright © 2009 Jonas Ådahl, 2011-2014 Florian Schmaus
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.caps.packet;
018
019import org.jivesoftware.smack.packet.PacketExtension;
020import org.jivesoftware.smack.util.XmlStringBuilder;
021import org.jivesoftware.smackx.caps.EntityCapsManager;
022
023public class CapsExtension implements PacketExtension {
024
025    private final String node, ver, hash;
026
027    public CapsExtension(String node, String version, String hash) {
028        this.node = node;
029        this.ver = version;
030        this.hash = hash;
031    }
032
033    public String getElementName() {
034        return EntityCapsManager.ELEMENT;
035    }
036
037    public String getNamespace() {
038        return EntityCapsManager.NAMESPACE;
039    }
040
041    public String getNode() {
042        return node;
043    }
044
045    public String getVer() {
046        return ver;
047    }
048
049    public String getHash() {
050        return hash;
051    }
052
053    /*
054     *  <c xmlns='http://jabber.org/protocol/caps'
055     *  hash='sha-1'
056     *  node='http://code.google.com/p/exodus'
057     *  ver='QgayPKawpkPSDYmwT/WM94uAlu0='/>
058     *
059     */
060    public CharSequence toXML() {
061        XmlStringBuilder xml = new XmlStringBuilder(this);
062        xml.attribute("hash", hash).attribute("node", node).attribute("ver", ver);
063        xml.closeEmptyElement();
064        return xml;
065    }
066}