001/**
002 *
003 * Copyright the original author or authors
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.smackx.shim.packet;
018
019import javax.xml.namespace.QName;
020
021import org.jivesoftware.smack.packet.ExtensionElement;
022import org.jivesoftware.smack.packet.NamedElement;
023import org.jivesoftware.smack.util.XmlStringBuilder;
024
025/**
026 * Represents a <b>Header</b> entry as specified by the <a href="http://xmpp.org/extensions/xep-0131.html">Stanza Headers and Internet Metadata (SHIM)</a>.
027
028 * @author Robin Collier
029 */
030public class Header implements ExtensionElement {
031    public static final String ELEMENT = "header";
032    public static final QName QNAME = new QName(HeadersExtension.NAMESPACE, ELEMENT);
033
034    private final String name;
035    private final String value;
036
037    public Header(String name, String value) {
038        this.name = name;
039        this.value = value;
040    }
041
042    public String getName() {
043        return name;
044    }
045
046    public String getValue() {
047        return value;
048    }
049
050    @Override
051    public String getElementName() {
052        return QNAME.getLocalPart();
053    }
054
055    @Override
056    public String getNamespace() {
057        return QNAME.getNamespaceURI();
058    }
059
060    @Override
061    public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
062        // Upcast to NamedElement since we don't want a xmlns attribute
063        XmlStringBuilder xml = new XmlStringBuilder((NamedElement) this);
064        xml.attribute("name", name);
065        xml.rightAngleBracket();
066        xml.escape(value);
067        xml.closeElement(this);
068        return xml;
069    }
070}