001/** 002 * 003 * Copyright © 2014-2020 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.smack.compress.packet; 018 019import java.util.Collections; 020import java.util.List; 021 022import javax.xml.namespace.QName; 023 024import org.jivesoftware.smack.packet.ExtensionElement; 025import org.jivesoftware.smack.packet.Nonza; 026import org.jivesoftware.smack.util.XmlStringBuilder; 027 028public class Compress implements Nonza { 029 030 public static final String ELEMENT = "compress"; 031 public static final String NAMESPACE = "http://jabber.org/protocol/compress"; 032 033 public final String method; 034 035 public Compress(String method) { 036 this.method = method; 037 } 038 039 @Override 040 public String getElementName() { 041 return ELEMENT; 042 } 043 044 @Override 045 public String getNamespace() { 046 return NAMESPACE; 047 } 048 049 @Override 050 public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { 051 XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace); 052 xml.rightAngleBracket(); 053 xml.element("method", method); 054 xml.closeElement(this); 055 return xml; 056 } 057 058 public static class Feature implements ExtensionElement { 059 public static final String ELEMENT = "compression"; 060 public static final QName QNAME = new QName(NAMESPACE, ELEMENT); 061 062 public final List<String> methods; 063 064 public Feature(List<String> methods) { 065 this.methods = methods; 066 } 067 068 public List<String> getMethods() { 069 return Collections.unmodifiableList(methods); 070 } 071 072 @Override 073 public String getNamespace() { 074 return NAMESPACE; 075 } 076 077 @Override 078 public String getElementName() { 079 return ELEMENT; 080 } 081 082 @Override 083 public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) { 084 XmlStringBuilder xml = new XmlStringBuilder(this); 085 xml.rightAngleBracket(); 086 for (String method : methods) { 087 xml.element("method", method); 088 } 089 xml.closeElement(this); 090 return xml; 091 } 092 } 093}