KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > smackx > packet > MUCAdmin


1 /**
2  * $RCSfile$
3  * $Revision: 2407 $
4  * $Date: 2004-11-02 20:37:00 -0300 (Tue, 02 Nov 2004) $
5  *
6  * Copyright 2003-2004 Jive Software.
7  *
8  * All rights reserved. Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */

20
21 package org.jivesoftware.smackx.packet;
22 import java.util.*;
23
24 import org.jivesoftware.smack.packet.IQ;
25
26 /**
27  * IQ packet that serves for kicking users, granting and revoking voice, banning users,
28  * modifying the ban list, granting and revoking membership and granting and revoking
29  * moderator privileges. All these operations are scoped by the
30  * 'http://jabber.org/protocol/muc#admin' namespace.
31  *
32  * @author Gaston Dombiak
33  */

34 public class MUCAdmin extends IQ {
35
36     private List items = new ArrayList();
37
38     /**
39      * Returns an Iterator for item childs that holds information about roles, affiliation,
40      * jids and nicks.
41      *
42      * @return an Iterator for item childs that holds information about roles, affiliation,
43      * jids and nicks.
44      */

45     public Iterator getItems() {
46         synchronized (items) {
47             return Collections.unmodifiableList(new ArrayList(items)).iterator();
48         }
49     }
50
51     /**
52      * Adds an item child that holds information about roles, affiliation, jids and nicks.
53      *
54      * @param item the item child that holds information about roles, affiliation, jids and nicks.
55      */

56     public void addItem(Item item) {
57         synchronized (items) {
58             items.add(item);
59         }
60     }
61
62     public String JavaDoc getChildElementXML() {
63         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
64         buf.append("<query xmlns=\"http://jabber.org/protocol/muc#admin\">");
65         synchronized (items) {
66             for (int i = 0; i < items.size(); i++) {
67                 Item item = (Item) items.get(i);
68                 buf.append(item.toXML());
69             }
70         }
71         // Add packet extensions, if any are defined.
72
buf.append(getExtensionsXML());
73         buf.append("</query>");
74         return buf.toString();
75     }
76
77     /**
78      * Item child that holds information about roles, affiliation, jids and nicks.
79      *
80      * @author Gaston Dombiak
81      */

82     public static class Item {
83         private String JavaDoc actor;
84         private String JavaDoc reason;
85         private String JavaDoc affiliation;
86         private String JavaDoc jid;
87         private String JavaDoc nick;
88         private String JavaDoc role;
89         
90         /**
91          * Creates a new item child.
92          *
93          * @param affiliation the actor's affiliation to the room
94          * @param role the privilege level of an occupant within a room.
95          */

96         public Item(String JavaDoc affiliation, String JavaDoc role) {
97             this.affiliation = affiliation;
98             this.role = role;
99         }
100         
101         /**
102          * Returns the actor (JID of an occupant in the room) that was kicked or banned.
103          *
104          * @return the JID of an occupant in the room that was kicked or banned.
105          */

106         public String JavaDoc getActor() {
107             return actor;
108         }
109
110         /**
111          * Returns the reason for the item child. The reason is optional and could be used to
112          * explain the reason why a user (occupant) was kicked or banned.
113          *
114          * @return the reason for the item child.
115          */

116         public String JavaDoc getReason() {
117             return reason;
118         }
119
120         /**
121          * Returns the occupant's affiliation to the room. The affiliation is a semi-permanent
122          * association or connection with a room. The possible affiliations are "owner", "admin",
123          * "member", and "outcast" (naturally it is also possible to have no affiliation). An
124          * affiliation lasts across a user's visits to a room.
125          *
126          * @return the actor's affiliation to the room
127          */

128         public String JavaDoc getAffiliation() {
129             return affiliation;
130         }
131
132         /**
133          * Returns the <room@service/nick> by which an occupant is identified within the context
134          * of a room. If the room is non-anonymous, the JID will be included in the item.
135          *
136          * @return the room JID by which an occupant is identified within the room.
137          */

138         public String JavaDoc getJid() {
139             return jid;
140         }
141
142         /**
143          * Returns the new nickname of an occupant that is changing his/her nickname. The new
144          * nickname is sent as part of the unavailable presence.
145          *
146          * @return the new nickname of an occupant that is changing his/her nickname.
147          */

148         public String JavaDoc getNick() {
149             return nick;
150         }
151
152         /**
153          * Returns the temporary position or privilege level of an occupant within a room. The
154          * possible roles are "moderator", "participant", and "visitor" (it is also possible to
155          * have no defined role). A role lasts only for the duration of an occupant's visit to
156          * a room.
157          *
158          * @return the privilege level of an occupant within a room.
159          */

160         public String JavaDoc getRole() {
161             return role;
162         }
163
164         /**
165          * Sets the actor (JID of an occupant in the room) that was kicked or banned.
166          *
167          * @param actor the actor (JID of an occupant in the room) that was kicked or banned.
168          */

169         public void setActor(String JavaDoc actor) {
170             this.actor = actor;
171         }
172
173         /**
174          * Sets the reason for the item child. The reason is optional and could be used to
175          * explain the reason why a user (occupant) was kicked or banned.
176          *
177          * @param reason the reason why a user (occupant) was kicked or banned.
178          */

179         public void setReason(String JavaDoc reason) {
180             this.reason = reason;
181         }
182
183         /**
184          * Sets the <room@service/nick> by which an occupant is identified within the context
185          * of a room. If the room is non-anonymous, the JID will be included in the item.
186          *
187          * @param jid the JID by which an occupant is identified within a room.
188          */

189         public void setJid(String JavaDoc jid) {
190             this.jid = jid;
191         }
192
193         /**
194          * Sets the new nickname of an occupant that is changing his/her nickname. The new
195          * nickname is sent as part of the unavailable presence.
196          *
197          * @param nick the new nickname of an occupant that is changing his/her nickname.
198          */

199         public void setNick(String JavaDoc nick) {
200             this.nick = nick;
201         }
202
203         public String JavaDoc toXML() {
204             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
205             buf.append("<item");
206             if (getAffiliation() != null) {
207                 buf.append(" affiliation=\"").append(getAffiliation()).append("\"");
208             }
209             if (getJid() != null) {
210                 buf.append(" jid=\"").append(getJid()).append("\"");
211             }
212             if (getNick() != null) {
213                 buf.append(" nick=\"").append(getNick()).append("\"");
214             }
215             if (getRole() != null) {
216                 buf.append(" role=\"").append(getRole()).append("\"");
217             }
218             if (getReason() == null && getActor() == null) {
219                 buf.append("/>");
220             }
221             else {
222                 buf.append(">");
223                 if (getReason() != null) {
224                     buf.append("<reason>").append(getReason()).append("</reason>");
225                 }
226                 if (getActor() != null) {
227                     buf.append("<actor jid=\"").append(getActor()).append("\"/>");
228                 }
229                 buf.append("</item>");
230             }
231             return buf.toString();
232         }
233     };
234 }
235
Popular Tags