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 org.jivesoftware.smack.packet.NamedElement;
  19. import org.jivesoftware.smack.packet.ExtensionElement;
  20. import org.jivesoftware.smack.util.XmlStringBuilder;

  21. /**
  22.  * Represents a <b>Header</b> entry as specified by the <a href="http://xmpp.org/extensions/xep-031.html">Stanza Headers and Internet Metadata (SHIM)</a>

  23.  * @author Robin Collier
  24.  */
  25. public class Header implements ExtensionElement {
  26.     public static final String ELEMENT = "header";

  27.     private final String name;
  28.     private final String value;

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

  33.     public String getName() {
  34.         return name;
  35.     }

  36.     public String getValue() {
  37.         return value;
  38.     }

  39.     public String getElementName() {
  40.         return ELEMENT;
  41.     }

  42.     public String getNamespace() {
  43.         return HeadersExtension.NAMESPACE;
  44.     }

  45.     @Override
  46.     public XmlStringBuilder toXML() {
  47.         // Upcast to NamedElement since we don't want a xmlns attribute
  48.         XmlStringBuilder xml = new XmlStringBuilder((NamedElement) this);
  49.         xml.attribute("name", name);
  50.         xml.rightAngleBracket();
  51.         xml.escape(value);
  52.         xml.closeElement(this);
  53.         return xml;
  54.     }
  55. }