blob: 563147eeb06efb1d3e125d2f85469b84d2923c45 [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 */
14package org.jivesoftware.smackx.pubsub;
15
16import java.util.Collections;
17import java.util.List;
18
19/**
20 * Represents the <b>affiliations</b> element of the reply to a request for affiliations.
21 * It is defined in the specification in section <a href="http://xmpp.org/extensions/xep-0060.html#entity-affiliations">5.7 Retrieve Affiliations</a>.
22 *
23 * @author Robin Collier
24 */
25public class AffiliationsExtension extends NodeExtension
26{
27 protected List<Affiliation> items = Collections.EMPTY_LIST;
28
29 public AffiliationsExtension()
30 {
31 super(PubSubElementType.AFFILIATIONS);
32 }
33
34 public AffiliationsExtension(List<Affiliation> affiliationList)
35 {
36 super(PubSubElementType.AFFILIATIONS);
37
38 if (affiliationList != null)
39 items = affiliationList;
40 }
41
42 /**
43 * Affiliations for the specified node.
44 *
45 * @param nodeId
46 * @param subList
47 */
48 public AffiliationsExtension(String nodeId, List<Affiliation> affiliationList)
49 {
50 super(PubSubElementType.AFFILIATIONS, nodeId);
51
52 if (affiliationList != null)
53 items = affiliationList;
54 }
55
56 public List<Affiliation> getAffiliations()
57 {
58 return items;
59 }
60
61 @Override
62 public String toXML()
63 {
64 if ((items == null) || (items.size() == 0))
65 {
66 return super.toXML();
67 }
68 else
69 {
70 StringBuilder builder = new StringBuilder("<");
71 builder.append(getElementName());
72 if (getNode() != null)
73 {
74 builder.append(" node='");
75 builder.append(getNode());
76 builder.append("'");
77 }
78 builder.append(">");
79
80 for (Affiliation item : items)
81 {
82 builder.append(item.toXML());
83 }
84
85 builder.append("</");
86 builder.append(getElementName());
87 builder.append(">");
88 return builder.toString();
89 }
90 }
91}