CapsExtension.java

  1. /**
  2.  *
  3.  * Copyright © 2009 Jonas Ådahl, 2011-2014 Florian Schmaus
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.caps.packet;

  18. import org.jivesoftware.smack.packet.Stanza;
  19. import org.jivesoftware.smack.packet.ExtensionElement;
  20. import org.jivesoftware.smack.util.XmlStringBuilder;

  21. /**
  22.  * A XEP-0115 Entity Capabilities extension.
  23.  */
  24. public class CapsExtension implements ExtensionElement {
  25.     public static final String NAMESPACE = "http://jabber.org/protocol/caps";
  26.     public static final String ELEMENT = "c";

  27.     private final String node, ver, hash;

  28.     public CapsExtension(String node, String version, String hash) {
  29.         this.node = node;
  30.         this.ver = version;
  31.         this.hash = hash;
  32.     }

  33.     public String getElementName() {
  34.         return ELEMENT;
  35.     }

  36.     public String getNamespace() {
  37.         return NAMESPACE;
  38.     }

  39.     public String getNode() {
  40.         return node;
  41.     }

  42.     public String getVer() {
  43.         return ver;
  44.     }

  45.     public String getHash() {
  46.         return hash;
  47.     }

  48.     /**
  49.      * <pre>
  50.      *  <c xmlns='http://jabber.org/protocol/caps'
  51.      *     hash='sha-1'
  52.      *     node='http://code.google.com/p/exodus'
  53.      *     ver='QgayPKawpkPSDYmwT/WM94uAlu0='/>
  54.      * </pre>
  55.      *
  56.      */
  57.     @Override
  58.     public XmlStringBuilder toXML() {
  59.         XmlStringBuilder xml = new XmlStringBuilder(this);
  60.         xml.attribute("hash", hash).attribute("node", node).attribute("ver", ver);
  61.         xml.closeEmptyElement();
  62.         return xml;
  63.     }

  64.     public static CapsExtension from(Stanza stanza) {
  65.         return stanza.getExtension(ELEMENT, NAMESPACE);
  66.     }
  67. }