KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  * $RCSfile$
3  * $Revision: 2428 $
4  * $Date: 2004-12-15 15:04:13 -0300 (Wed, 15 Dec 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 granting and revoking ownership privileges, granting
28  * and revoking administrative privileges and destroying a room. All these operations
29  * are scoped by the 'http://jabber.org/protocol/muc#owner' namespace.
30  *
31  * @author Gaston Dombiak
32  */

33 public class MUCOwner extends IQ {
34
35     private List items = new ArrayList();
36     private Destroy destroy;
37
38     /**
39      * Returns an Iterator for item childs that holds information about affiliation,
40      * jids and nicks.
41      *
42      * @return an Iterator for item childs that holds information about 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      * Returns a request to the server to destroy a room. The sender of the request
53      * should be the room's owner. If the sender of the destroy request is not the room's owner
54      * then the server will answer a "Forbidden" error.
55      *
56      * @return a request to the server to destroy a room.
57      */

58     public Destroy getDestroy() {
59         return destroy;
60     }
61
62     /**
63      * Sets a request to the server to destroy a room. The sender of the request
64      * should be the room's owner. If the sender of the destroy request is not the room's owner
65      * then the server will answer a "Forbidden" error.
66      *
67      * @param destroy the request to the server to destroy a room.
68      */

69     public void setDestroy(Destroy destroy) {
70         this.destroy = destroy;
71     }
72
73     /**
74      * Adds an item child that holds information about affiliation, jids and nicks.
75      *
76      * @param item the item child that holds information about affiliation, jids and nicks.
77      */

78     public void addItem(Item item) {
79         synchronized (items) {
80             items.add(item);
81         }
82     }
83
84     public String JavaDoc getChildElementXML() {
85         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
86         buf.append("<query xmlns=\"http://jabber.org/protocol/muc#owner\">");
87         synchronized (items) {
88             for (int i = 0; i < items.size(); i++) {
89                 Item item = (Item) items.get(i);
90                 buf.append(item.toXML());
91             }
92         }
93         if (getDestroy() != null) {
94             buf.append(getDestroy().toXML());
95         }
96         // Add packet extensions, if any are defined.
97
buf.append(getExtensionsXML());
98         buf.append("</query>");
99         return buf.toString();
100     }
101
102     /**
103      * Item child that holds information about affiliation, jids and nicks.
104      *
105      * @author Gaston Dombiak
106      */

107     public static class Item {
108         
109         private String JavaDoc actor;
110         private String JavaDoc reason;
111         private String JavaDoc affiliation;
112         private String JavaDoc jid;
113         private String JavaDoc nick;
114         private String JavaDoc role;
115
116         /**
117          * Creates a new item child.
118          *
119          * @param affiliation the actor's affiliation to the room
120          */

121         public Item(String JavaDoc affiliation) {
122             this.affiliation = affiliation;
123         }
124         
125         /**
126          * Returns the actor (JID of an occupant in the room) that was kicked or banned.
127          *
128          * @return the JID of an occupant in the room that was kicked or banned.
129          */

130         public String JavaDoc getActor() {
131             return actor;
132         }
133
134         /**
135          * Returns the reason for the item child. The reason is optional and could be used to
136          * explain the reason why a user (occupant) was kicked or banned.
137          *
138          * @return the reason for the item child.
139          */

140         public String JavaDoc getReason() {
141             return reason;
142         }
143
144         /**
145          * Returns the occupant's affiliation to the room. The affiliation is a semi-permanent
146          * association or connection with a room. The possible affiliations are "owner", "admin",
147          * "member", and "outcast" (naturally it is also possible to have no affiliation). An
148          * affiliation lasts across a user's visits to a room.
149          *
150          * @return the actor's affiliation to the room
151          */

152         public String JavaDoc getAffiliation() {
153             return affiliation;
154         }
155
156         /**
157          * Returns the <room@service/nick> by which an occupant is identified within the context
158          * of a room. If the room is non-anonymous, the JID will be included in the item.
159          *
160          * @return the room JID by which an occupant is identified within the room.
161          */

162         public String JavaDoc getJid() {
163             return jid;
164         }
165
166         /**
167          * Returns the new nickname of an occupant that is changing his/her nickname. The new
168          * nickname is sent as part of the unavailable presence.
169          *
170          * @return the new nickname of an occupant that is changing his/her nickname.
171          */

172         public String JavaDoc getNick() {
173             return nick;
174         }
175
176         /**
177          * Returns the temporary position or privilege level of an occupant within a room. The
178          * possible roles are "moderator", "participant", and "visitor" (it is also possible to
179          * have no defined role). A role lasts only for the duration of an occupant's visit to
180          * a room.
181          *
182          * @return the privilege level of an occupant within a room.
183          */

184         public String JavaDoc getRole() {
185             return role;
186         }
187
188         /**
189          * Sets the actor (JID of an occupant in the room) that was kicked or banned.
190          *
191          * @param actor the actor (JID of an occupant in the room) that was kicked or banned.
192          */

193         public void setActor(String JavaDoc actor) {
194             this.actor = actor;
195         }
196
197         /**
198          * Sets the reason for the item child. The reason is optional and could be used to
199          * explain the reason why a user (occupant) was kicked or banned.
200          *
201          * @param reason the reason why a user (occupant) was kicked or banned.
202          */

203         public void setReason(String JavaDoc reason) {
204             this.reason = reason;
205         }
206
207         /**
208          * Sets the <room@service/nick> by which an occupant is identified within the context
209          * of a room. If the room is non-anonymous, the JID will be included in the item.
210          *
211          * @param jid the JID by which an occupant is identified within a room.
212          */

213         public void setJid(String JavaDoc jid) {
214             this.jid = jid;
215         }
216
217         /**
218          * Sets the new nickname of an occupant that is changing his/her nickname. The new
219          * nickname is sent as part of the unavailable presence.
220          *
221          * @param nick the new nickname of an occupant that is changing his/her nickname.
222          */

223         public void setNick(String JavaDoc nick) {
224             this.nick = nick;
225         }
226
227         /**
228          * Sets the temporary position or privilege level of an occupant within a room. The
229          * possible roles are "moderator", "participant", and "visitor" (it is also possible to
230          * have no defined role). A role lasts only for the duration of an occupant's visit to
231          * a room.
232          *
233          * @param role the new privilege level of an occupant within a room.
234          */

235         public void setRole(String JavaDoc role) {
236             this.role = role;
237         }
238
239         public String JavaDoc toXML() {
240             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
241             buf.append("<item");
242             if (getAffiliation() != null) {
243                 buf.append(" affiliation=\"").append(getAffiliation()).append("\"");
244             }
245             if (getJid() != null) {
246                 buf.append(" jid=\"").append(getJid()).append("\"");
247             }
248             if (getNick() != null) {
249                 buf.append(" nick=\"").append(getNick()).append("\"");
250             }
251             if (getRole() != null) {
252                 buf.append(" role=\"").append(getRole()).append("\"");
253             }
254             if (getReason() == null && getActor() == null) {
255                 buf.append("/>");
256             }
257             else {
258                 buf.append(">");
259                 if (getReason() != null) {
260                     buf.append("<reason>").append(getReason()).append("</reason>");
261                 }
262                 if (getActor() != null) {
263                     buf.append("<actor jid=\"").append(getActor()).append("\"/>");
264                 }
265                 buf.append("</item>");
266             }
267             return buf.toString();
268         }
269     };
270
271     /**
272      * Represents a request to the server to destroy a room. The sender of the request
273      * should be the room's owner. If the sender of the destroy request is not the room's owner
274      * then the server will answer a "Forbidden" error.
275      *
276      * @author Gaston Dombiak
277      */

278     public static class Destroy {
279         private String JavaDoc reason;
280         private String JavaDoc jid;
281         
282         
283         /**
284          * Returns the JID of an alternate location since the current room is being destroyed.
285          *
286          * @return the JID of an alternate location.
287          */

288         public String JavaDoc getJid() {
289             return jid;
290         }
291
292         /**
293          * Returns the reason for the room destruction.
294          *
295          * @return the reason for the room destruction.
296          */

297         public String JavaDoc getReason() {
298             return reason;
299         }
300
301         /**
302          * Sets the JID of an alternate location since the current room is being destroyed.
303          *
304          * @param jid the JID of an alternate location.
305          */

306         public void setJid(String JavaDoc jid) {
307             this.jid = jid;
308         }
309
310         /**
311          * Sets the reason for the room destruction.
312          *
313          * @param reason the reason for the room destruction.
314          */

315         public void setReason(String JavaDoc reason) {
316             this.reason = reason;
317         }
318
319         public String JavaDoc toXML() {
320             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
321             buf.append("<destroy");
322             if (getJid() != null) {
323                 buf.append(" jid=\"").append(getJid()).append("\"");
324             }
325             if (getReason() == null) {
326                 buf.append("/>");
327             }
328             else {
329                 buf.append(">");
330                 if (getReason() != null) {
331                     buf.append("<reason>").append(getReason()).append("</reason>");
332                 }
333                 buf.append("</destroy>");
334             }
335             return buf.toString();
336         }
337
338     }
339 }
340
Popular Tags