Compress.java

  1. /**
  2.  *
  3.  * Copyright © 2014-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.smack.compress.packet;

  18. import java.util.Collections;
  19. import java.util.List;

  20. import javax.xml.namespace.QName;

  21. import org.jivesoftware.smack.packet.ExtensionElement;
  22. import org.jivesoftware.smack.packet.Nonza;
  23. import org.jivesoftware.smack.util.XmlStringBuilder;

  24. public class Compress implements Nonza {

  25.     public static final String ELEMENT = "compress";
  26.     public static final String NAMESPACE = "http://jabber.org/protocol/compress";

  27.     public final String method;

  28.     public Compress(String method) {
  29.         this.method = method;
  30.     }

  31.     @Override
  32.     public String getElementName() {
  33.         return ELEMENT;
  34.     }

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

  39.     @Override
  40.     public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
  41.         XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
  42.         xml.rightAngleBracket();
  43.         xml.element("method", method);
  44.         xml.closeElement(this);
  45.         return xml;
  46.     }

  47.     public static class Feature implements ExtensionElement {
  48.         public static final String ELEMENT = "compression";
  49.         public static final QName QNAME = new QName(NAMESPACE, ELEMENT);

  50.         public final List<String> methods;

  51.         public Feature(List<String> methods) {
  52.             this.methods = methods;
  53.         }

  54.         public List<String> getMethods() {
  55.             return Collections.unmodifiableList(methods);
  56.         }

  57.         @Override
  58.         public String getNamespace() {
  59.             return NAMESPACE;
  60.         }

  61.         @Override
  62.         public String getElementName() {
  63.             return ELEMENT;
  64.         }

  65.         @Override
  66.         public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
  67.             XmlStringBuilder xml = new XmlStringBuilder(this);
  68.             xml.rightAngleBracket();
  69.             for (String method : methods) {
  70.                 xml.element("method", method);
  71.             }
  72.             xml.closeElement(this);
  73.             return xml;
  74.         }
  75.     }
  76. }