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.packet;
018
019import javax.xml.namespace.QName;
020
021import org.jivesoftware.smack.util.XmlStringBuilder;
022
023public class StartTls implements Nonza {
024
025    public static final StartTls INSTANCE = new StartTls();
026
027    public static final String ELEMENT = "starttls";
028    public static final String NAMESPACE = "urn:ietf:params:xml:ns:xmpp-tls";
029    public static final QName QNAME = new QName(NAMESPACE, ELEMENT);
030
031    private final boolean required;
032
033    public StartTls() {
034        this(false);
035    }
036
037    public StartTls(boolean required) {
038        this.required = required;
039    }
040
041    public boolean required() {
042        return required;
043    }
044
045    @Override
046    public String getElementName() {
047        return ELEMENT;
048    }
049
050    @Override
051    public String getNamespace() {
052        return NAMESPACE;
053    }
054
055    @Override
056    public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
057        XmlStringBuilder xml = new XmlStringBuilder(this, enclosingNamespace);
058
059        if (required) {
060            xml.rightAngleBracket();
061            xml.emptyElement("required");
062            xml.closeElement(this);
063        } else {
064            xml.closeEmptyElement();
065        }
066
067        return xml;
068    }
069
070}