CapsExtension.java

  1. /**
  2.  *
  3.  * Copyright © 2009 Jonas Ådahl, 2011-2020 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 javax.xml.namespace.QName;

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

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

  29.     private final String node, ver, hash;

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

  35.     @Override
  36.     public String getElementName() {
  37.         return ELEMENT;
  38.     }

  39.     @Override
  40.     public String getNamespace() {
  41.         return NAMESPACE;
  42.     }

  43.     public String getNode() {
  44.         return node;
  45.     }

  46.     public String getVer() {
  47.         return ver;
  48.     }

  49.     public String getHash() {
  50.         return hash;
  51.     }

  52.     /**
  53.      * {@inheritDoc}.
  54.      *
  55.      * <pre>
  56.      *  &lt;c xmlns='http://jabber.org/protocol/caps'
  57.      *     hash='sha-1'
  58.      *     node='http://code.google.com/p/exodus'
  59.      *     ver='QgayPKawpkPSDYmwT/WM94uAlu0='/&gt;
  60.      * </pre>
  61.      *
  62.      */
  63.     @Override
  64.     public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
  65.         XmlStringBuilder xml = new XmlStringBuilder(this);
  66.         xml.attribute("hash", hash).attribute("node", node).attribute("ver", ver);
  67.         xml.closeEmptyElement();
  68.         return xml;
  69.     }

  70.     public static CapsExtension from(Stanza stanza) {
  71.         return stanza.getExtension(CapsExtension.class);
  72.     }
  73. }