KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > messenger > muc > spi > IQOwnerHandler


1 /**
2  * $RCSfile: IQOwnerHandler.java,v $
3  * $Revision: 1.26 $
4  * $Date: 2005/07/12 21:40:16 $
5  *
6  * Copyright (C) 2004 Jive Software. All rights reserved.
7  *
8  * This software is published under the terms of the GNU Public License (GPL),
9  * a copy of which is included in this distribution.
10  */

11
12 package org.jivesoftware.messenger.muc.spi;
13
14 import org.jivesoftware.messenger.forms.DataForm;
15 import org.jivesoftware.messenger.forms.FormField;
16 import org.jivesoftware.messenger.forms.spi.XDataFormImpl;
17 import org.jivesoftware.messenger.forms.spi.XFormFieldImpl;
18 import org.jivesoftware.messenger.muc.ConflictException;
19 import org.jivesoftware.messenger.muc.ForbiddenException;
20 import org.jivesoftware.messenger.muc.MUCRole;
21 import org.jivesoftware.util.LocaleUtils;
22 import org.jivesoftware.messenger.*;
23 import org.jivesoftware.messenger.user.UserNotFoundException;
24 import java.util.*;
25
26 import org.dom4j.DocumentHelper;
27 import org.dom4j.Element;
28 import org.dom4j.QName;
29 import org.xmpp.packet.Presence;
30 import org.xmpp.packet.JID;
31 import org.xmpp.packet.IQ;
32 import org.xmpp.packet.PacketError;
33
34 /**
35  * A handler for the IQ packet with namespace http://jabber.org/protocol/muc#owner. This kind of
36  * packets are usually sent by room owners. So this handler provides the necessary functionality
37  * to support owner requirements such as: room configuration and room destruction.
38  *
39  * @author Gaston Dombiak
40  */

41 public class IQOwnerHandler {
42     private MUCRoomImpl room;
43
44     private PacketRouter router;
45
46     private XDataFormImpl configurationForm;
47
48     private Element probeResult;
49
50     public IQOwnerHandler(MUCRoomImpl chatroom, PacketRouter packetRouter) {
51         this.room = chatroom;
52         this.router = packetRouter;
53         init();
54     }
55
56     /**
57      * Handles the IQ packet sent by an owner of the room. Possible actions are:
58      * <ul>
59      * <li>Return the list of owners</li>
60      * <li>Return the list of admins</li>
61      * <li>Change user's affiliation to owner</li>
62      * <li>Change user's affiliation to admin</li>
63      * <li>Change user's affiliation to member</li>
64      * <li>Change user's affiliation to none</li>
65      * <li>Destroy the room</li>
66      * <li>Return the room configuration within a dataform</li>
67      * <li>Update the room configuration based on the sent dataform</li>
68      * </ul>
69      *
70      * @param packet the IQ packet sent by an owner of the room.
71      * @param role the role of the user that sent the packet.
72      * @throws ForbiddenException if the user does not have enough permissions (ie. is not an owner).
73      * @throws ConflictException If the room was going to lose all of its owners.
74      */

75     public void handleIQ(IQ packet, MUCRole role) throws ForbiddenException, ConflictException {
76         // Only owners can send packets with the namespace "http://jabber.org/protocol/muc#owner"
77
if (MUCRole.Affiliation.owner != role.getAffiliation()) {
78             throw new ForbiddenException();
79         }
80
81         IQ reply = IQ.createResultIQ(packet);
82         Element element = packet.getChildElement();
83
84         // Analyze the action to perform based on the included element
85
Element formElement = element.element(QName.get("x", "jabber:x:data"));
86         if (formElement != null) {
87             handleDataFormElement(role, formElement);
88         }
89         else {
90             Element destroyElement = element.element("destroy");
91             if (destroyElement != null) {
92                 room.destroyRoom(destroyElement.attributeValue("jid"), destroyElement
93                         .elementTextTrim("reason"));
94             }
95             else {
96                 List itemsList = element.elements("item");
97                 if (!itemsList.isEmpty()) {
98                     handleItemsElement(itemsList, role, reply);
99                 }
100                 else {
101                     // If no element was included in the query element then answer the
102
// configuration form
103
if (!element.elementIterator().hasNext()) {
104                         refreshConfigurationFormValues();
105                         reply.setChildElement(probeResult.createCopy());
106                     }
107                     // An unknown and possibly incorrect element was included in the query
108
// element so answer a BAD_REQUEST error
109
else {
110                         reply.setChildElement(packet.getChildElement().createCopy());
111                         reply.setError(PacketError.Condition.bad_request);
112                     }
113                 }
114             }
115         }
116         if (reply.getTo() != null) {
117             // Send a reply only if the sender of the original packet was from a real JID. (i.e. not
118
// a packet generated locally)
119
router.route(reply);
120         }
121     }
122
123     /**
124      * Handles packets that includes item elements. Depending on the item's attributes the
125      * interpretation of the request may differ. For example, an item that only contains the
126      * "affiliation" attribute is requesting the list of owners or admins. Whilst if the item
127      * contains the affiliation together with a jid means that the client is changing the
128      * affiliation of the requested jid.
129      *
130      * @param itemsList the list of items sent by the client.
131      * @param senderRole the role of the user that sent the items.
132      * @param reply the iq packet that will be sent back as a reply to the client's request.
133      * @throws ForbiddenException if the user does not have enough permissions.
134      * @throws ConflictException If the room was going to lose all of its owners.
135      */

136     private void handleItemsElement(List itemsList, MUCRole senderRole, IQ reply)
137             throws ForbiddenException, ConflictException {
138         Element item;
139         String JavaDoc affiliation = null;
140         boolean hasJID = ((Element)itemsList.get(0)).attributeValue("jid") != null;
141         boolean hasNick = ((Element)itemsList.get(0)).attributeValue("nick") != null;
142         // Check if the client is requesting or changing the list of owners/admin
143
if (!hasJID && !hasNick) {
144             // The client is requesting the list of owners or admins
145
for (Iterator items = itemsList.iterator(); items.hasNext();) {
146                 item = (Element)items.next();
147                 affiliation = item.attributeValue("affiliation");
148                 // Create the result that will hold an item for each owner or admin
149
Element result = reply.setChildElement("query", "http://jabber.org/protocol/muc#owner");
150
151                 if ("owner".equals(affiliation)) {
152                     // The client is requesting the list of owners
153
Element ownerMetaData;
154                     MUCRole role;
155                     for (String JavaDoc jid : room.getOwners()) {
156                         ownerMetaData = result.addElement("item", "http://jabber.org/protocol/muc#owner");
157                         ownerMetaData.addAttribute("affiliation", "owner");
158                         ownerMetaData.addAttribute("jid", jid);
159                         // Add role and nick to the metadata if the user is in the room
160
try {
161                             List<MUCRole> roles = room.getOccupantsByBareJID(jid);
162                             role = roles.get(0);
163                             ownerMetaData.addAttribute("role", role.getRole().toString());
164                             ownerMetaData.addAttribute("nick", role.getNickname());
165                         }
166                         catch (UserNotFoundException e) {
167                             // Do nothing
168
}
169                     }
170                 }
171                 else if ("admin".equals(affiliation)) {
172                     // The client is requesting the list of admins
173
Element adminMetaData;
174                     MUCRole role;
175                     for (String JavaDoc jid : room.getAdmins()) {
176                         adminMetaData = result.addElement("item", "http://jabber.org/protocol/muc#owner");
177                         adminMetaData.addAttribute("affiliation", "admin");
178                         adminMetaData.addAttribute("jid", jid);
179                         // Add role and nick to the metadata if the user is in the room
180
try {
181                             List<MUCRole> roles = room.getOccupantsByBareJID(jid);
182                             role = roles.get(0);
183                             adminMetaData.addAttribute("role", role.getRole().toString());
184                             adminMetaData.addAttribute("nick", role.getNickname());
185                         }
186                         catch (UserNotFoundException e) {
187                             // Do nothing
188
}
189                     }
190                 }
191                 else {
192                     reply.setError(PacketError.Condition.bad_request);
193                 }
194             }
195         }
196         else {
197             // The client is modifying the list of owners or admins
198
Map<String JavaDoc,String JavaDoc> jids = new HashMap<String JavaDoc,String JavaDoc>();
199             String JavaDoc bareJID = null;
200             String JavaDoc nick;
201             // Collect the new affiliations for the specified jids
202
for (Iterator items = itemsList.iterator(); items.hasNext();) {
203                 try {
204                     item = (Element)items.next();
205                     affiliation = item.attributeValue("affiliation");
206                     if (hasJID) {
207                         bareJID = new JID(item.attributeValue("jid")).toBareJID();
208                     }
209                     else {
210                         // Get the bare JID based on the requested nick
211
nick = item.attributeValue("nick");
212                         bareJID = room.getOccupant(nick).getChatUser().getAddress().toBareJID();
213                     }
214                     jids.put(bareJID, affiliation);
215                 }
216                 catch (UserNotFoundException e) {
217                     // Do nothing
218
}
219             }
220
221             // Keep a registry of the updated presences
222
List<Presence> presences = new ArrayList<Presence>(jids.size());
223
224             room.lock.readLock().lock();
225             try {
226                 // Check if all the existing owners are being removed
227
if (jids.keySet().containsAll(room.owners)) {
228                     // Answer a conflict error if we are only removing ALL the owners
229
if (!jids.containsValue("owner")) {
230                         throw new ConflictException();
231                     }
232                 }
233
234                 room.lock.readLock().unlock();
235                 room.lock.writeLock().lock();
236                 try {
237                     String JavaDoc targetAffiliation = null;
238                     for (Iterator<String JavaDoc> it = jids.keySet().iterator(); it.hasNext();) {
239                         bareJID = it.next();
240                         targetAffiliation = jids.get(bareJID);
241                         if ("owner".equals(targetAffiliation)) {
242                             // Add the new user as an owner of the room
243
presences.addAll(room.addOwner(bareJID, senderRole));
244                         }
245                         else if ("admin".equals(targetAffiliation)) {
246                             // Add the new user as an admin of the room
247
presences.addAll(room.addAdmin(bareJID, senderRole));
248                         }
249                         else if ("member".equals(targetAffiliation)) {
250                             // Add the new user as a member of the room
251
boolean hadAffiliation = room.getAffiliation(bareJID) != MUCRole.Affiliation.none;
252                             presences.addAll(room.addMember(bareJID, null, senderRole));
253                             // If the user had an affiliation don't send an invitation. Otherwise
254
// send an invitation if the room is members-only
255
if (!hadAffiliation && room.isMembersOnly()) {
256                                 room.sendInvitation(new JID(bareJID), null, senderRole, null);
257                             }
258                         }
259                         else if ("none".equals(targetAffiliation)) {
260                             // Set that this jid has a NONE affiliation
261
presences.addAll(room.addNone(bareJID, senderRole));
262                         }
263                     }
264                 }
265                 finally {
266                     room.lock.writeLock().unlock();
267                     room.lock.readLock().lock();
268                 }
269             }
270             finally {
271                 room.lock.readLock().unlock();
272             }
273
274             // Send the updated presences to the room occupants
275
for (Presence presence : presences) {
276                 room.send(presence);
277             }
278         }
279     }
280
281     /**
282      * Handles packets that includes a data form. The data form was sent using an element with name
283      * "x" and namespace "jabber:x:data".
284      *
285      * @param senderRole the role of the user that sent the data form.
286      * @param formElement the element that contains the data form specification.
287      * @throws ForbiddenException if the user does not have enough privileges.
288      * @throws ConflictException If the room was going to lose all of its owners.
289      */

290     private void handleDataFormElement(MUCRole senderRole, Element formElement)
291             throws ForbiddenException, ConflictException {
292         XDataFormImpl completedForm = new XDataFormImpl();
293         completedForm.parse(formElement);
294
295         if (DataForm.TYPE_CANCEL.equals(completedForm.getType())) {
296             // If the room was just created (i.e. is locked) and the owner cancels the configuration
297
// form then destroy the room
298
if (room.isLocked()) {
299                 room.destroyRoom(null, null);
300             }
301         }
302         else if (DataForm.TYPE_SUBMIT.equals(completedForm.getType())) {
303             // The owner is requesting an instant room
304
if (completedForm.getFieldsSize() == 0) {
305                 // Do nothing
306
}
307             // The owner is requesting a reserved room or is changing the current configuration
308
else {
309                 processConfigurationForm(completedForm, senderRole);
310             }
311             // If the room was locked, unlock it and send to the owner the "room is now unlocked"
312
// message
313
if (room.isLocked() && !room.isManuallyLocked()) {
314                 room.unlock(senderRole);
315             }
316         }
317     }
318
319     /**
320      * Processes the completed form sent by an owner of the room. This will modify the room's
321      * configuration as well as the list of owners and admins.
322      *
323      * @param completedForm the completed form sent by an owner of the room.
324      * @param senderRole the role of the user that sent the completed form.
325      * @throws ForbiddenException if the user does not have enough privileges.
326      * @throws ConflictException If the room was going to lose all of its owners.
327      */

328     private void processConfigurationForm(XDataFormImpl completedForm, MUCRole senderRole)
329             throws ForbiddenException, ConflictException {
330         Iterator<String JavaDoc> values;
331         String JavaDoc booleanValue;
332         List<String JavaDoc> list;
333         FormField field;
334
335         // Get the new list of admins
336
field = completedForm.getField("muc#roomconfig_roomadmins");
337         boolean adminsSent = field != null;
338         List<String JavaDoc> admins = new ArrayList<String JavaDoc>();
339         if (field != null) {
340             values = field.getValues();
341             while (values.hasNext()) {
342                 admins.add(values.next());
343             }
344         }
345
346         // Get the new list of owners
347
field = completedForm.getField("muc#roomconfig_roomowners");
348         boolean ownersSent = field != null;
349         List<String JavaDoc> owners = new ArrayList<String JavaDoc>();
350         if (field != null) {
351             values = field.getValues();
352             while (values.hasNext()) {
353                 owners.add(values.next());
354             }
355         }
356
357         // Answer a conflic error if all the current owners will be removed
358
if (ownersSent && owners.isEmpty()) {
359             throw new ConflictException();
360         }
361
362         // Keep a registry of the updated presences
363
List presences = new ArrayList(admins.size() + owners.size());
364
365         room.lock.writeLock().lock();
366         try {
367             field = completedForm.getField("muc#roomconfig_roomname");
368             if (field != null) {
369                 values = field.getValues();
370                 room.setNaturalLanguageName((values.hasNext() ? values.next() : " "));
371             }
372
373             field = completedForm.getField("muc#roomconfig_roomdesc");
374             if (field != null) {
375                 values = field.getValues();
376                 room.setDescription((values.hasNext() ? values.next() : " "));
377             }
378
379             field = completedForm.getField("muc#roomconfig_changesubject");
380             if (field != null) {
381                 values = field.getValues();
382                 booleanValue = (values.hasNext() ? values.next() : "1");
383                 room.setCanOccupantsChangeSubject(("1".equals(booleanValue) ? true : false));
384             }
385
386             field = completedForm.getField("muc#roomconfig_maxusers");
387             if (field != null) {
388                 values = field.getValues();
389                 room.setMaxUsers((values.hasNext() ? Integer.parseInt(values.next()) : 30));
390             }
391
392             field = completedForm.getField("muc#roomconfig_presencebroadcast");
393             if (field != null) {
394                 values = field.getValues();
395                 list = new ArrayList<String JavaDoc>();
396                 while (values.hasNext()) {
397                     list.add(values.next());
398                 }
399                 room.setRolesToBroadcastPresence(list);
400             }
401
402             field = completedForm.getField("muc#roomconfig_publicroom");
403             if (field != null) {
404                 values = field.getValues();
405                 booleanValue = (values.hasNext() ? values.next() : "1");
406                 room.setPublicRoom(("1".equals(booleanValue) ? true : false));
407             }
408
409             field = completedForm.getField("muc#roomconfig_persistentroom");
410             if (field != null) {
411                 values = field.getValues();
412                 booleanValue = (values.hasNext() ? values.next() : "1");
413                 boolean isPersistent = ("1".equals(booleanValue) ? true : false);
414                 // Delete the room from the DB if it's no longer persistent
415
if (room.isPersistent() && !isPersistent) {
416                     MUCPersistenceManager.deleteFromDB(room);
417                 }
418                 room.setPersistent(isPersistent);
419             }
420
421             field = completedForm.getField("muc#roomconfig_moderatedroom");
422             if (field != null) {
423                 values = field.getValues();
424                 booleanValue = (values.hasNext() ? values.next() : "1");
425                 room.setModerated(("1".equals(booleanValue) ? true : false));
426             }
427
428             field = completedForm.getField("muc#roomconfig_membersonly");
429             if (field != null) {
430                 values = field.getValues();
431                 booleanValue = (values.hasNext() ? values.next() : "1");
432                 presences.addAll(room.setMembersOnly(("1".equals(booleanValue) ?
433                         true : false)));
434             }
435
436             field = completedForm.getField("muc#roomconfig_allowinvites");
437             if (field != null) {
438                 values = field.getValues();
439                 booleanValue = (values.hasNext() ? values.next() : "1");
440                 room.setCanOccupantsInvite(("1".equals(booleanValue) ? true : false));
441             }
442
443             field = completedForm.getField("muc#roomconfig_passwordprotectedroom");
444             if (field != null) {
445                 values = field.getValues();
446                 booleanValue = (values.hasNext() ? values.next() : "1");
447                 boolean isPasswordProtected = "1".equals(booleanValue);
448                 if (isPasswordProtected) {
449                     // The room is password protected so set the new password
450
field = completedForm.getField("muc#roomconfig_roomsecret");
451                     if (field != null) {
452                         values = completedForm.getField("muc#roomconfig_roomsecret").getValues();
453                         room.setPassword((values.hasNext() ? values.next() : null));
454                     }
455                 }
456                 else {
457                     // The room is not password protected so remove any previous password
458
room.setPassword(null);
459                 }
460             }
461
462             field = completedForm.getField("muc#roomconfig_whois");
463             if (field != null) {
464                 values = field.getValues();
465                 booleanValue = (values.hasNext() ? values.next() : "1");
466                 room.setCanAnyoneDiscoverJID(("anyone".equals(booleanValue) ? true : false));
467             }
468
469             field = completedForm.getField("muc#roomconfig_enablelogging");
470             if (field != null) {
471                 values = field.getValues();
472                 booleanValue = (values.hasNext() ? values.next() : "1");
473                 room.setLogEnabled(("1".equals(booleanValue) ? true : false));
474             }
475
476             field = completedForm.getField("x-muc#roomconfig_reservednick");
477             if (field != null) {
478                 values = field.getValues();
479                 booleanValue = (values.hasNext() ? values.next() : "1");
480                 room.setLoginRestrictedToNickname(("1".equals(booleanValue) ? true : false));
481             }
482
483             field = completedForm.getField("x-muc#roomconfig_canchangenick");
484             if (field != null) {
485                 values = field.getValues();
486                 booleanValue = (values.hasNext() ? values.next() : "1");
487                 room.setChangeNickname(("1".equals(booleanValue) ? true : false));
488             }
489
490             field = completedForm.getField("x-muc#roomconfig_registration");
491             if (field != null) {
492                 values = field.getValues();
493                 booleanValue = (values.hasNext() ? values.next() : "1");
494                 room.setRegistrationEnabled(("1".equals(booleanValue) ? true : false));
495             }
496
497             // Update the modification date to reflect the last time when the room's configuration
498
// was modified
499
room.setModificationDate(new Date());
500
501             if (room.isPersistent()) {
502                 room.saveToDB();
503             }
504
505             // Set the new owners and admins of the room
506
presences.addAll(room.addOwners(owners, senderRole));
507             presences.addAll(room.addAdmins(admins, senderRole));
508
509             if (ownersSent) {
510                 // Change the affiliation to "member" for the current owners that won't be neither
511
// owner nor admin (if the form included the owners field)
512
List<String JavaDoc> ownersToRemove = new ArrayList<String JavaDoc>(room.owners);
513                 ownersToRemove.removeAll(admins);
514                 ownersToRemove.removeAll(owners);
515                 for (String JavaDoc jid : ownersToRemove) {
516                     presences.addAll(room.addMember(jid, null, senderRole));
517                 }
518             }
519
520             if (adminsSent) {
521                 // Change the affiliation to "member" for the current admins that won't be neither
522
// owner nor admin (if the form included the admins field)
523
List<String JavaDoc> adminsToRemove = new ArrayList<String JavaDoc>(room.admins);
524                 adminsToRemove.removeAll(admins);
525                 adminsToRemove.removeAll(owners);
526                 for (String JavaDoc jid : adminsToRemove) {
527                     presences.addAll(room.addMember(jid, null, senderRole));
528                 }
529             }
530
531             // Destroy the room if the room is no longer persistent and there are no occupants in
532
// the room
533
if (!room.isPersistent() && room.getOccupantsCount() == 0) {
534                 room.destroyRoom(null, null);
535             }
536
537         }
538         finally {
539             room.lock.writeLock().unlock();
540         }
541
542         // Send the updated presences to the room occupants
543
for (Iterator it = presences.iterator(); it.hasNext();) {
544             room.send((Presence)it.next());
545         }
546     }
547
548     private void refreshConfigurationFormValues() {
549         room.lock.readLock().lock();
550         try {
551             FormField field = configurationForm.getField("muc#roomconfig_roomname");
552             field.clearValues();
553             field.addValue(room.getNaturalLanguageName());
554
555             field = configurationForm.getField("muc#roomconfig_roomdesc");
556             field.clearValues();
557             field.addValue(room.getDescription());
558
559             field = configurationForm.getField("muc#roomconfig_changesubject");
560             field.clearValues();
561             field.addValue((room.canOccupantsChangeSubject() ? "1" : "0"));
562
563             field = configurationForm.getField("muc#roomconfig_maxusers");
564             field.clearValues();
565             field.addValue(Integer.toString(room.getMaxUsers()));
566
567             field = configurationForm.getField("muc#roomconfig_presencebroadcast");
568             field.clearValues();
569             for (String JavaDoc roleToBroadcast : room.getRolesToBroadcastPresence()) {
570                 field.addValue(roleToBroadcast);
571             }
572
573             field = configurationForm.getField("muc#roomconfig_publicroom");
574             field.clearValues();
575             field.addValue((room.isPublicRoom() ? "1" : "0"));
576
577             field = configurationForm.getField("muc#roomconfig_persistentroom");
578             field.clearValues();
579             field.addValue((room.isPersistent() ? "1" : "0"));
580
581             field = configurationForm.getField("muc#roomconfig_moderatedroom");
582             field.clearValues();
583             field.addValue((room.isModerated() ? "1" : "0"));
584
585             field = configurationForm.getField("muc#roomconfig_membersonly");
586             field.clearValues();
587             field.addValue((room.isMembersOnly() ? "1" : "0"));
588
589             field = configurationForm.getField("muc#roomconfig_allowinvites");
590             field.clearValues();
591             field.addValue((room.canOccupantsInvite() ? "1" : "0"));
592
593             field = configurationForm.getField("muc#roomconfig_passwordprotectedroom");
594             field.clearValues();
595             field.addValue((room.isPasswordProtected() ? "1" : "0"));
596
597             field = configurationForm.getField("muc#roomconfig_roomsecret");
598             field.clearValues();
599             field.addValue(room.getPassword());
600
601             field = configurationForm.getField("muc#roomconfig_whois");
602             field.clearValues();
603             field.addValue((room.canAnyoneDiscoverJID() ? "anyone" : "moderators"));
604
605             field = configurationForm.getField("muc#roomconfig_enablelogging");
606             field.clearValues();
607             field.addValue((room.isLogEnabled() ? "1" : "0"));
608
609             field = configurationForm.getField("x-muc#roomconfig_reservednick");
610             field.clearValues();
611             field.addValue((room.isLoginRestrictedToNickname() ? "1" : "0"));
612
613             field = configurationForm.getField("x-muc#roomconfig_canchangenick");
614             field.clearValues();
615             field.addValue((room.canChangeNickname() ? "1" : "0"));
616
617             field = configurationForm.getField("x-muc#roomconfig_registration");
618             field.clearValues();
619             field.addValue((room.isRegistrationEnabled() ? "1" : "0"));
620
621             field = configurationForm.getField("muc#roomconfig_roomadmins");
622             field.clearValues();
623             for (String JavaDoc jid : room.getAdmins()) {
624                 field.addValue(jid);
625             }
626
627             field = configurationForm.getField("muc#roomconfig_roomowners");
628             field.clearValues();
629             for (String JavaDoc jid : room.getOwners()) {
630                 field.addValue(jid);
631             }
632
633             // Remove the old element
634
probeResult.remove(probeResult.element(QName.get("x", "jabber:x:data")));
635             // Add the new representation of configurationForm as an element
636
probeResult.add(configurationForm.asXMLElement());
637
638         }
639         finally {
640             room.lock.readLock().unlock();
641         }
642     }
643
644     private void init() {
645         Element element = DocumentHelper.createElement(QName.get("query",
646                 "http://jabber.org/protocol/muc#owner"));
647
648         configurationForm = new XDataFormImpl(DataForm.TYPE_FORM);
649         configurationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.conf.title"));
650         List params = new ArrayList();
651         params.add(room.getName());
652         configurationForm.addInstruction(LocaleUtils.getLocalizedString("muc.form.conf.instruction", params));
653
654         XFormFieldImpl field = new XFormFieldImpl("FORM_TYPE");
655         field.setType(FormField.TYPE_HIDDEN);
656         field.addValue("http://jabber.org/protocol/muc#roomconfig");
657         configurationForm.addField(field);
658
659         field = new XFormFieldImpl("muc#roomconfig_roomname");
660         field.setType(FormField.TYPE_TEXT_SINGLE);
661         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_roomname"));
662         configurationForm.addField(field);
663
664         field = new XFormFieldImpl("muc#roomconfig_roomdesc");
665         field.setType(FormField.TYPE_TEXT_SINGLE);
666         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_roomdesc"));
667         configurationForm.addField(field);
668
669         field = new XFormFieldImpl("muc#roomconfig_changesubject");
670         field.setType(FormField.TYPE_BOOLEAN);
671         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_changesubject"));
672         configurationForm.addField(field);
673
674         field = new XFormFieldImpl("muc#roomconfig_maxusers");
675         field.setType(FormField.TYPE_LIST_SINGLE);
676         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_maxusers"));
677         field.addOption("10", "10");
678         field.addOption("20", "20");
679         field.addOption("30", "30");
680         field.addOption("40", "40");
681         field.addOption("50", "50");
682         field.addOption(LocaleUtils.getLocalizedString("muc.form.conf.none"), "0");
683         configurationForm.addField(field);
684
685         field = new XFormFieldImpl("muc#roomconfig_presencebroadcast");
686         field.setType(FormField.TYPE_LIST_MULTI);
687         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_presencebroadcast"));
688         field.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderator");
689         field.addOption(LocaleUtils.getLocalizedString("muc.form.conf.participant"), "participant");
690         field.addOption(LocaleUtils.getLocalizedString("muc.form.conf.visitor"), "visitor");
691         configurationForm.addField(field);
692
693         field = new XFormFieldImpl("muc#roomconfig_publicroom");
694         field.setType(FormField.TYPE_BOOLEAN);
695         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_publicroom"));
696         configurationForm.addField(field);
697
698         field = new XFormFieldImpl("muc#roomconfig_persistentroom");
699         field.setType(FormField.TYPE_BOOLEAN);
700         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_persistentroom"));
701         configurationForm.addField(field);
702
703         field = new XFormFieldImpl("muc#roomconfig_moderatedroom");
704         field.setType(FormField.TYPE_BOOLEAN);
705         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_moderatedroom"));
706         configurationForm.addField(field);
707
708         field = new XFormFieldImpl("muc#roomconfig_membersonly");
709         field.setType(FormField.TYPE_BOOLEAN);
710         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_membersonly"));
711         configurationForm.addField(field);
712
713         field = new XFormFieldImpl();
714         field.setType(FormField.TYPE_FIXED);
715         field.addValue(LocaleUtils.getLocalizedString("muc.form.conf.allowinvitesfixed"));
716         configurationForm.addField(field);
717
718         field = new XFormFieldImpl("muc#roomconfig_allowinvites");
719         field.setType(FormField.TYPE_BOOLEAN);
720         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_allowinvites"));
721         configurationForm.addField(field);
722
723         field = new XFormFieldImpl("muc#roomconfig_passwordprotectedroom");
724         field.setType(FormField.TYPE_BOOLEAN);
725         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_passwordprotectedroom"));
726         configurationForm.addField(field);
727
728         field = new XFormFieldImpl();
729         field.setType(FormField.TYPE_FIXED);
730         field.addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomsecretfixed"));
731         configurationForm.addField(field);
732
733         field = new XFormFieldImpl("muc#roomconfig_roomsecret");
734         field.setType(FormField.TYPE_TEXT_PRIVATE);
735         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_roomsecret"));
736         configurationForm.addField(field);
737
738         field = new XFormFieldImpl("muc#roomconfig_whois");
739         field.setType(FormField.TYPE_LIST_SINGLE);
740         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_whois"));
741         field.addOption(LocaleUtils.getLocalizedString("muc.form.conf.moderator"), "moderators");
742         field.addOption(LocaleUtils.getLocalizedString("muc.form.conf.anyone"), "anyone");
743         configurationForm.addField(field);
744
745         field = new XFormFieldImpl("muc#roomconfig_enablelogging");
746         field.setType(FormField.TYPE_BOOLEAN);
747         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_enablelogging"));
748         configurationForm.addField(field);
749
750         field = new XFormFieldImpl("x-muc#roomconfig_reservednick");
751         field.setType(FormField.TYPE_BOOLEAN);
752         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_reservednick"));
753         configurationForm.addField(field);
754
755         field = new XFormFieldImpl("x-muc#roomconfig_canchangenick");
756         field.setType(FormField.TYPE_BOOLEAN);
757         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_canchangenick"));
758         configurationForm.addField(field);
759
760         field = new XFormFieldImpl("x-muc#roomconfig_registration");
761         field.setType(FormField.TYPE_BOOLEAN);
762         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_registration"));
763         configurationForm.addField(field);
764
765         field = new XFormFieldImpl();
766         field.setType(FormField.TYPE_FIXED);
767         field.addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomadminsfixed"));
768         configurationForm.addField(field);
769
770         field = new XFormFieldImpl("muc#roomconfig_roomadmins");
771         field.setType(FormField.TYPE_JID_MULTI);
772         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_roomadmins"));
773         configurationForm.addField(field);
774
775         field = new XFormFieldImpl();
776         field.setType(FormField.TYPE_FIXED);
777         field.addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomownersfixed"));
778         configurationForm.addField(field);
779
780         field = new XFormFieldImpl("muc#roomconfig_roomowners");
781         field.setType(FormField.TYPE_JID_MULTI);
782         field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_roomowners"));
783         configurationForm.addField(field);
784
785         // Create the probeResult and add the basic info together with the configuration form
786
probeResult = element;
787         probeResult.add(configurationForm.asXMLElement());
788     }
789 }
Popular Tags