Compress.java

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

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

  20. import org.jivesoftware.smack.packet.FullStreamElement;
  21. import org.jivesoftware.smack.packet.ExtensionElement;
  22. import org.jivesoftware.smack.util.XmlStringBuilder;

  23. public class Compress extends FullStreamElement {

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

  26.     public final String method;

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

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

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

  38.     @Override
  39.     public XmlStringBuilder toXML() {
  40.         XmlStringBuilder xml = new XmlStringBuilder(this);
  41.         xml.rightAngleBracket();
  42.         xml.element("method", method);
  43.         xml.closeElement(this);
  44.         return xml;
  45.     }

  46.     public static class Feature implements ExtensionElement {
  47.         public static final String ELEMENT = "compression";

  48.         public final List<String> methods;

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

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

  55.         @Override
  56.         public String getNamespace() {
  57.             return NAMESPACE;
  58.         }

  59.         @Override
  60.         public String getElementName() {
  61.             return ELEMENT;
  62.         }

  63.         @Override
  64.         public XmlStringBuilder toXML() {
  65.             XmlStringBuilder xml = new XmlStringBuilder(this);
  66.             xml.rightAngleBracket();
  67.             for (String method : methods) {
  68.                 xml.element("method", method);
  69.             }
  70.             xml.closeElement(this);
  71.             return xml;
  72.         }
  73.     }
  74. }