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 java.util.Collection;
020import java.util.Collections;
021
022import org.jivesoftware.smack.packet.PacketExtension;
023
024/**
025 * Extension representing a list of headers as specified in <a href="http://xmpp.org/extensions/xep-0131">Stanza Headers and Internet Metadata (SHIM)</a>
026 * 
027 * @see Header
028 * 
029 * @author Robin Collier
030 */
031public class HeadersExtension implements PacketExtension
032{
033        public static final String NAMESPACE = "http://jabber.org/protocol/shim";
034        
035        private Collection<Header> headers = Collections.emptyList();
036        
037        public HeadersExtension(Collection<Header> headerList)
038        {
039                if (headerList != null)
040                        headers = headerList;
041        }
042        
043        public Collection<Header> getHeaders()
044        {
045                return headers;
046        }
047
048        public String getElementName()
049        {
050                return "headers";
051        }
052
053        public String getNamespace()
054        {
055                return NAMESPACE;
056        }
057
058        public String toXML()
059        {
060                StringBuilder builder = new StringBuilder("<" + getElementName() + " xmlns='" + getNamespace() + "'>");
061                
062                for (Header header : headers)
063                {
064                        builder.append(header.toXML());
065                }
066                builder.append("</" + getElementName() + '>');
067
068                return builder.toString();
069        }
070
071}