blob: 78564dbbfe3d73107932ee52a5cce283dae7da58 [file] [log] [blame]
Shuyi Chend7955ce2013-05-22 14:51:55 -07001/**
2 * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14
15package org.jivesoftware.smackx.packet;
16
17import java.util.Collection;
18import java.util.Collections;
19
20import org.jivesoftware.smack.packet.PacketExtension;
21
22/**
23 * Extension representing a list of headers as specified in <a href="http://xmpp.org/extensions/xep-0131">Stanza Headers and Internet Metadata (SHIM)</a>
24 *
25 * @see Header
26 *
27 * @author Robin Collier
28 */
29public class HeadersExtension implements PacketExtension
30{
31 public static final String NAMESPACE = "http://jabber.org/protocol/shim";
32
33 private Collection<Header> headers = Collections.EMPTY_LIST;
34
35 public HeadersExtension(Collection<Header> headerList)
36 {
37 if (headerList != null)
38 headers = headerList;
39 }
40
41 public Collection<Header> getHeaders()
42 {
43 return headers;
44 }
45
46 public String getElementName()
47 {
48 return "headers";
49 }
50
51 public String getNamespace()
52 {
53 return NAMESPACE;
54 }
55
56 public String toXML()
57 {
58 StringBuilder builder = new StringBuilder("<" + getElementName() + " xmlns='" + getNamespace() + "'>");
59
60 for (Header header : headers)
61 {
62 builder.append(header.toXML());
63 }
64 builder.append("</" + getElementName() + '>');
65
66 return builder.toString();
67 }
68
69}