Header.java

  1. /**
  2.  *
  3.  * Copyright the original author or authors
  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.smackx.shim.packet;

  18. import javax.xml.namespace.QName;

  19. import org.jivesoftware.smack.packet.ExtensionElement;
  20. import org.jivesoftware.smack.packet.NamedElement;
  21. import org.jivesoftware.smack.util.XmlStringBuilder;

  22. /**
  23.  * 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>.

  24.  * @author Robin Collier
  25.  */
  26. public class Header implements ExtensionElement {
  27.     public static final String ELEMENT = "header";
  28.     public static final QName QNAME = new QName(HeadersExtension.NAMESPACE, ELEMENT);

  29.     private final String name;
  30.     private final String value;

  31.     public Header(String name, String value) {
  32.         this.name = name;
  33.         this.value = value;
  34.     }

  35.     public String getName() {
  36.         return name;
  37.     }

  38.     public String getValue() {
  39.         return value;
  40.     }

  41.     @Override
  42.     public String getElementName() {
  43.         return QNAME.getLocalPart();
  44.     }

  45.     @Override
  46.     public String getNamespace() {
  47.         return QNAME.getNamespaceURI();
  48.     }

  49.     @Override
  50.     public XmlStringBuilder toXML(org.jivesoftware.smack.packet.XmlEnvironment enclosingNamespace) {
  51.         // Upcast to NamedElement since we don't want a xmlns attribute
  52.         XmlStringBuilder xml = new XmlStringBuilder((NamedElement) this);
  53.         xml.attribute("name", name);
  54.         xml.rightAngleBracket();
  55.         xml.escape(value);
  56.         xml.closeElement(this);
  57.         return xml;
  58.     }
  59. }