AffiliationsExtension.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.pubsub;

  18. import java.util.Collections;
  19. import java.util.List;

  20. /**
  21.  * Represents the <b>affiliations</b> element of the reply to a request for affiliations.
  22.  * It is defined in the specification in section <a href="http://xmpp.org/extensions/xep-0060.html#entity-affiliations">5.7 Retrieve Affiliations</a>.
  23.  *
  24.  * @author Robin Collier
  25.  */
  26. public class AffiliationsExtension extends NodeExtension
  27. {
  28.     protected List<Affiliation> items = Collections.emptyList();
  29.    
  30.     public AffiliationsExtension()
  31.     {
  32.         super(PubSubElementType.AFFILIATIONS);
  33.     }
  34.    
  35.     public AffiliationsExtension(List<Affiliation> subList)
  36.     {
  37.         super(PubSubElementType.AFFILIATIONS);
  38.         items = subList;
  39.     }

  40.     public List<Affiliation> getAffiliations()
  41.     {
  42.         return items;
  43.     }

  44.     @Override
  45.     public CharSequence toXML()
  46.     {
  47.         if ((items == null) || (items.size() == 0))
  48.         {
  49.             return super.toXML();
  50.         }
  51.         else
  52.         {
  53.             StringBuilder builder = new StringBuilder("<");
  54.             builder.append(getElementName());
  55.             builder.append(">");
  56.            
  57.             for (Affiliation item : items)
  58.             {
  59.                 builder.append(item.toXML());
  60.             }
  61.            
  62.             builder.append("</");
  63.             builder.append(getElementName());
  64.             builder.append(">");
  65.             return builder.toString();
  66.         }
  67.     }
  68. }