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.pubsub;
018
019import java.util.Collections;
020import java.util.List;
021
022/**
023 * Represents the <b>affiliations</b> element of the reply to a request for affiliations.
024 * It is defined in the specification in section <a href="http://xmpp.org/extensions/xep-0060.html#entity-affiliations">5.7 Retrieve Affiliations</a>.
025 * 
026 * @author Robin Collier
027 */
028public class AffiliationsExtension extends NodeExtension
029{
030        protected List<Affiliation> items = Collections.emptyList();
031        
032        public AffiliationsExtension()
033        {
034                super(PubSubElementType.AFFILIATIONS);
035        }
036        
037        public AffiliationsExtension(List<Affiliation> subList)
038        {
039                super(PubSubElementType.AFFILIATIONS);
040                items = subList;
041        }
042
043        public List<Affiliation> getAffiliations()
044        {
045                return items;
046        }
047
048        @Override
049        public CharSequence toXML()
050        {
051                if ((items == null) || (items.size() == 0))
052                {
053                        return super.toXML();
054                }
055                else
056                {
057                        StringBuilder builder = new StringBuilder("<");
058                        builder.append(getElementName());
059                        builder.append(">");
060                        
061                        for (Affiliation item : items)
062                        {
063                                builder.append(item.toXML());
064                        }
065                        
066                        builder.append("</");
067                        builder.append(getElementName());
068                        builder.append(">");
069                        return builder.toString();
070                }
071        }
072}