001: /**
002: * $RCSfile$
003: * $Revision: 1623 $
004: * $Date: 2005-07-12 18:40:57 -0300 (Tue, 12 Jul 2005) $
005: *
006: * Copyright (C) 2004 Jive Software. All rights reserved.
007: *
008: * This software is published under the terms of the GNU Public License (GPL),
009: * a copy of which is included in this distribution.
010: */package org.jivesoftware.openfire.muc.spi;
011:
012: import org.dom4j.DocumentHelper;
013: import org.dom4j.Element;
014: import org.dom4j.QName;
015: import org.jivesoftware.openfire.PacketRouter;
016: import org.jivesoftware.openfire.forms.DataForm;
017: import org.jivesoftware.openfire.forms.FormField;
018: import org.jivesoftware.openfire.forms.spi.XDataFormImpl;
019: import org.jivesoftware.openfire.forms.spi.XFormFieldImpl;
020: import org.jivesoftware.openfire.muc.ConflictException;
021: import org.jivesoftware.openfire.muc.ForbiddenException;
022: import org.jivesoftware.openfire.muc.MUCRole;
023: import org.jivesoftware.openfire.muc.cluster.RoomUpdatedEvent;
024: import org.jivesoftware.openfire.user.UserNotFoundException;
025: import org.jivesoftware.util.LocaleUtils;
026: import org.jivesoftware.util.cache.CacheFactory;
027: import org.xmpp.packet.IQ;
028: import org.xmpp.packet.JID;
029: import org.xmpp.packet.PacketError;
030: import org.xmpp.packet.Presence;
031:
032: import java.util.*;
033:
034: /**
035: * A handler for the IQ packet with namespace http://jabber.org/protocol/muc#owner. This kind of
036: * packets are usually sent by room owners. So this handler provides the necessary functionality
037: * to support owner requirements such as: room configuration and room destruction.
038: *
039: * @author Gaston Dombiak
040: */
041: public class IQOwnerHandler {
042: private LocalMUCRoom room;
043:
044: private PacketRouter router;
045:
046: private XDataFormImpl configurationForm;
047:
048: private Element probeResult;
049:
050: public IQOwnerHandler(LocalMUCRoom chatroom,
051: PacketRouter packetRouter) {
052: this .room = chatroom;
053: this .router = packetRouter;
054: init();
055: }
056:
057: /**
058: * Handles the IQ packet sent by an owner of the room. Possible actions are:
059: * <ul>
060: * <li>Return the list of owners</li>
061: * <li>Return the list of admins</li>
062: * <li>Change user's affiliation to owner</li>
063: * <li>Change user's affiliation to admin</li>
064: * <li>Change user's affiliation to member</li>
065: * <li>Change user's affiliation to none</li>
066: * <li>Destroy the room</li>
067: * <li>Return the room configuration within a dataform</li>
068: * <li>Update the room configuration based on the sent dataform</li>
069: * </ul>
070: *
071: * @param packet the IQ packet sent by an owner of the room.
072: * @param role the role of the user that sent the packet.
073: * @throws ForbiddenException if the user does not have enough permissions (ie. is not an owner).
074: * @throws ConflictException If the room was going to lose all of its owners.
075: */
076: public void handleIQ(IQ packet, MUCRole role)
077: throws ForbiddenException, ConflictException {
078: // Only owners can send packets with the namespace "http://jabber.org/protocol/muc#owner"
079: if (MUCRole.Affiliation.owner != role.getAffiliation()) {
080: throw new ForbiddenException();
081: }
082:
083: IQ reply = IQ.createResultIQ(packet);
084: Element element = packet.getChildElement();
085:
086: // Analyze the action to perform based on the included element
087: Element formElement = element.element(QName.get("x",
088: "jabber:x:data"));
089: if (formElement != null) {
090: handleDataFormElement(role, formElement);
091: } else {
092: Element destroyElement = element.element("destroy");
093: if (destroyElement != null) {
094: room.destroyRoom(destroyElement.attributeValue("jid"),
095: destroyElement.elementTextTrim("reason"));
096: } else {
097: List itemsList = element.elements("item");
098: if (!itemsList.isEmpty()) {
099: handleItemsElement(itemsList, role, reply);
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()
111: .createCopy());
112: reply
113: .setError(PacketError.Condition.bad_request);
114: }
115: }
116: }
117: }
118: if (reply.getTo() != null) {
119: // Send a reply only if the sender of the original packet was from a real JID. (i.e. not
120: // a packet generated locally)
121: router.route(reply);
122: }
123: }
124:
125: /**
126: * Handles packets that includes item elements. Depending on the item's attributes the
127: * interpretation of the request may differ. For example, an item that only contains the
128: * "affiliation" attribute is requesting the list of owners or admins. Whilst if the item
129: * contains the affiliation together with a jid means that the client is changing the
130: * affiliation of the requested jid.
131: *
132: * @param itemsList the list of items sent by the client.
133: * @param senderRole the role of the user that sent the items.
134: * @param reply the iq packet that will be sent back as a reply to the client's request.
135: * @throws ForbiddenException if the user does not have enough permissions.
136: * @throws ConflictException If the room was going to lose all of its owners.
137: */
138: private void handleItemsElement(List itemsList, MUCRole senderRole,
139: IQ reply) throws ForbiddenException, ConflictException {
140: Element item;
141: String affiliation = null;
142: boolean hasJID = ((Element) itemsList.get(0))
143: .attributeValue("jid") != null;
144: boolean hasNick = ((Element) itemsList.get(0))
145: .attributeValue("nick") != null;
146: // Check if the client is requesting or changing the list of owners/admin
147: if (!hasJID && !hasNick) {
148: // The client is requesting the list of owners or admins
149: for (Iterator items = itemsList.iterator(); items.hasNext();) {
150: item = (Element) items.next();
151: affiliation = item.attributeValue("affiliation");
152: // Create the result that will hold an item for each owner or admin
153: Element result = reply.setChildElement("query",
154: "http://jabber.org/protocol/muc#owner");
155:
156: if ("owner".equals(affiliation)) {
157: // The client is requesting the list of owners
158: Element ownerMetaData;
159: MUCRole role;
160: for (String jid : room.getOwners()) {
161: ownerMetaData = result.addElement("item",
162: "http://jabber.org/protocol/muc#owner");
163: ownerMetaData.addAttribute("affiliation",
164: "owner");
165: ownerMetaData.addAttribute("jid", jid);
166: // Add role and nick to the metadata if the user is in the room
167: try {
168: List<MUCRole> roles = room
169: .getOccupantsByBareJID(jid);
170: role = roles.get(0);
171: ownerMetaData.addAttribute("role", role
172: .getRole().toString());
173: ownerMetaData.addAttribute("nick", role
174: .getNickname());
175: } catch (UserNotFoundException e) {
176: // Do nothing
177: }
178: }
179: } else if ("admin".equals(affiliation)) {
180: // The client is requesting the list of admins
181: Element adminMetaData;
182: MUCRole role;
183: for (String jid : room.getAdmins()) {
184: adminMetaData = result.addElement("item",
185: "http://jabber.org/protocol/muc#owner");
186: adminMetaData.addAttribute("affiliation",
187: "admin");
188: adminMetaData.addAttribute("jid", jid);
189: // Add role and nick to the metadata if the user is in the room
190: try {
191: List<MUCRole> roles = room
192: .getOccupantsByBareJID(jid);
193: role = roles.get(0);
194: adminMetaData.addAttribute("role", role
195: .getRole().toString());
196: adminMetaData.addAttribute("nick", role
197: .getNickname());
198: } catch (UserNotFoundException e) {
199: // Do nothing
200: }
201: }
202: } else {
203: reply.setError(PacketError.Condition.bad_request);
204: }
205: }
206: } else {
207: // The client is modifying the list of owners or admins
208: Map<String, String> jids = new HashMap<String, String>();
209: String bareJID = null;
210: String nick;
211: // Collect the new affiliations for the specified jids
212: for (Iterator items = itemsList.iterator(); items.hasNext();) {
213: try {
214: item = (Element) items.next();
215: affiliation = item.attributeValue("affiliation");
216: if (hasJID) {
217: bareJID = new JID(item.attributeValue("jid"))
218: .toBareJID();
219: } else {
220: // Get the bare JID based on the requested nick
221: nick = item.attributeValue("nick");
222: bareJID = room.getOccupant(nick)
223: .getUserAddress().toBareJID();
224: }
225: jids.put(bareJID, affiliation);
226: } catch (UserNotFoundException e) {
227: // Do nothing
228: }
229: }
230:
231: // Keep a registry of the updated presences
232: List<Presence> presences = new ArrayList<Presence>(jids
233: .size());
234:
235: room.lock.readLock().lock();
236: try {
237: // Check if all the existing owners are being removed
238: if (jids.keySet().containsAll(room.owners)) {
239: // Answer a conflict error if we are only removing ALL the owners
240: if (!jids.containsValue("owner")) {
241: throw new ConflictException();
242: }
243: }
244:
245: room.lock.readLock().unlock();
246: room.lock.writeLock().lock();
247: try {
248: String targetAffiliation = null;
249: for (Iterator<String> it = jids.keySet().iterator(); it
250: .hasNext();) {
251: bareJID = it.next();
252: targetAffiliation = jids.get(bareJID);
253: if ("owner".equals(targetAffiliation)) {
254: // Add the new user as an owner of the room
255: presences.addAll(room.addOwner(bareJID,
256: senderRole));
257: } else if ("admin".equals(targetAffiliation)) {
258: // Add the new user as an admin of the room
259: presences.addAll(room.addAdmin(bareJID,
260: senderRole));
261: } else if ("member".equals(targetAffiliation)) {
262: // Add the new user as a member of the room
263: boolean hadAffiliation = room
264: .getAffiliation(bareJID) != MUCRole.Affiliation.none;
265: presences.addAll(room.addMember(bareJID,
266: null, senderRole));
267: // If the user had an affiliation don't send an invitation. Otherwise
268: // send an invitation if the room is members-only
269: if (!hadAffiliation && room.isMembersOnly()) {
270: room.sendInvitation(new JID(bareJID),
271: null, senderRole, null);
272: }
273: } else if ("none".equals(targetAffiliation)) {
274: // Set that this jid has a NONE affiliation
275: presences.addAll(room.addNone(bareJID,
276: senderRole));
277: }
278: }
279: } finally {
280: room.lock.writeLock().unlock();
281: room.lock.readLock().lock();
282: }
283: } finally {
284: room.lock.readLock().unlock();
285: }
286:
287: // Send the updated presences to the room occupants
288: for (Presence presence : presences) {
289: room.send(presence);
290: }
291: }
292: }
293:
294: /**
295: * Handles packets that includes a data form. The data form was sent using an element with name
296: * "x" and namespace "jabber:x:data".
297: *
298: * @param senderRole the role of the user that sent the data form.
299: * @param formElement the element that contains the data form specification.
300: * @throws ForbiddenException if the user does not have enough privileges.
301: * @throws ConflictException If the room was going to lose all of its owners.
302: */
303: private void handleDataFormElement(MUCRole senderRole,
304: Element formElement) throws ForbiddenException,
305: ConflictException {
306: XDataFormImpl completedForm = new XDataFormImpl();
307: completedForm.parse(formElement);
308:
309: if (DataForm.TYPE_CANCEL.equals(completedForm.getType())) {
310: // If the room was just created (i.e. is locked) and the owner cancels the configuration
311: // form then destroy the room
312: if (room.isLocked()) {
313: room.destroyRoom(null, null);
314: }
315: } else if (DataForm.TYPE_SUBMIT.equals(completedForm.getType())) {
316: // The owner is requesting an instant room
317: if (completedForm.getFieldsSize() == 0) {
318: // Do nothing
319: }
320: // The owner is requesting a reserved room or is changing the current configuration
321: else {
322: processConfigurationForm(completedForm, senderRole);
323: }
324: // If the room was locked, unlock it and send to the owner the "room is now unlocked"
325: // message
326: if (room.isLocked() && !room.isManuallyLocked()) {
327: room.unlock(senderRole);
328: }
329: if (!room.isDestroyed) {
330: // Let other cluster nodes that the room has been updated
331: CacheFactory.doClusterTask(new RoomUpdatedEvent(room));
332: }
333: }
334: }
335:
336: /**
337: * Processes the completed form sent by an owner of the room. This will modify the room's
338: * configuration as well as the list of owners and admins.
339: *
340: * @param completedForm the completed form sent by an owner of the room.
341: * @param senderRole the role of the user that sent the completed form.
342: * @throws ForbiddenException if the user does not have enough privileges.
343: * @throws ConflictException If the room was going to lose all of its owners.
344: */
345: private void processConfigurationForm(XDataFormImpl completedForm,
346: MUCRole senderRole) throws ForbiddenException,
347: ConflictException {
348: Iterator<String> values;
349: String booleanValue;
350: List<String> list;
351: FormField field;
352:
353: // Get the new list of admins
354: field = completedForm.getField("muc#roomconfig_roomadmins");
355: boolean adminsSent = field != null;
356: List<String> admins = new ArrayList<String>();
357: if (field != null) {
358: values = field.getValues();
359: while (values.hasNext()) {
360: admins.add(values.next());
361: }
362: }
363:
364: // Get the new list of owners
365: field = completedForm.getField("muc#roomconfig_roomowners");
366: boolean ownersSent = field != null;
367: List<String> owners = new ArrayList<String>();
368: if (field != null) {
369: values = field.getValues();
370: while (values.hasNext()) {
371: owners.add(values.next());
372: }
373: }
374:
375: // Answer a conflic error if all the current owners will be removed
376: if (ownersSent && owners.isEmpty()) {
377: throw new ConflictException();
378: }
379:
380: // Keep a registry of the updated presences
381: List presences = new ArrayList(admins.size() + owners.size());
382:
383: room.lock.writeLock().lock();
384: try {
385: field = completedForm.getField("muc#roomconfig_roomname");
386: if (field != null) {
387: values = field.getValues();
388: room.setNaturalLanguageName((values.hasNext() ? values
389: .next() : " "));
390: }
391:
392: field = completedForm.getField("muc#roomconfig_roomdesc");
393: if (field != null) {
394: values = field.getValues();
395: room.setDescription((values.hasNext() ? values.next()
396: : " "));
397: }
398:
399: field = completedForm
400: .getField("muc#roomconfig_changesubject");
401: if (field != null) {
402: values = field.getValues();
403: booleanValue = (values.hasNext() ? values.next() : "1");
404: room.setCanOccupantsChangeSubject(("1"
405: .equals(booleanValue) ? true : false));
406: }
407:
408: field = completedForm.getField("muc#roomconfig_maxusers");
409: if (field != null) {
410: values = field.getValues();
411: room.setMaxUsers((values.hasNext() ? Integer
412: .parseInt(values.next()) : 30));
413: }
414:
415: field = completedForm
416: .getField("muc#roomconfig_presencebroadcast");
417: if (field != null) {
418: values = field.getValues();
419: list = new ArrayList<String>();
420: while (values.hasNext()) {
421: list.add(values.next());
422: }
423: room.setRolesToBroadcastPresence(list);
424: }
425:
426: field = completedForm.getField("muc#roomconfig_publicroom");
427: if (field != null) {
428: values = field.getValues();
429: booleanValue = (values.hasNext() ? values.next() : "1");
430: room.setPublicRoom(("1".equals(booleanValue) ? true
431: : false));
432: }
433:
434: field = completedForm
435: .getField("muc#roomconfig_persistentroom");
436: if (field != null) {
437: values = field.getValues();
438: booleanValue = (values.hasNext() ? values.next() : "1");
439: boolean isPersistent = ("1".equals(booleanValue) ? true
440: : false);
441: // Delete the room from the DB if it's no longer persistent
442: if (room.isPersistent() && !isPersistent) {
443: MUCPersistenceManager.deleteFromDB(room);
444: }
445: room.setPersistent(isPersistent);
446: }
447:
448: field = completedForm
449: .getField("muc#roomconfig_moderatedroom");
450: if (field != null) {
451: values = field.getValues();
452: booleanValue = (values.hasNext() ? values.next() : "1");
453: room.setModerated(("1".equals(booleanValue) ? true
454: : false));
455: }
456:
457: field = completedForm
458: .getField("muc#roomconfig_membersonly");
459: if (field != null) {
460: values = field.getValues();
461: booleanValue = (values.hasNext() ? values.next() : "1");
462: presences.addAll(room.setMembersOnly(("1"
463: .equals(booleanValue) ? true : false)));
464: }
465:
466: field = completedForm
467: .getField("muc#roomconfig_allowinvites");
468: if (field != null) {
469: values = field.getValues();
470: booleanValue = (values.hasNext() ? values.next() : "1");
471: room
472: .setCanOccupantsInvite(("1"
473: .equals(booleanValue) ? true : false));
474: }
475:
476: field = completedForm
477: .getField("muc#roomconfig_passwordprotectedroom");
478: if (field != null) {
479: values = field.getValues();
480: booleanValue = (values.hasNext() ? values.next() : "1");
481: boolean isPasswordProtected = "1".equals(booleanValue);
482: if (isPasswordProtected) {
483: // The room is password protected so set the new password
484: field = completedForm
485: .getField("muc#roomconfig_roomsecret");
486: if (field != null) {
487: values = completedForm.getField(
488: "muc#roomconfig_roomsecret")
489: .getValues();
490: room.setPassword((values.hasNext() ? values
491: .next() : null));
492: }
493: } else {
494: // The room is not password protected so remove any previous password
495: room.setPassword(null);
496: }
497: }
498:
499: field = completedForm.getField("muc#roomconfig_whois");
500: if (field != null) {
501: values = field.getValues();
502: booleanValue = (values.hasNext() ? values.next() : "1");
503: room.setCanAnyoneDiscoverJID(("anyone"
504: .equals(booleanValue) ? true : false));
505: }
506:
507: field = completedForm
508: .getField("muc#roomconfig_enablelogging");
509: if (field != null) {
510: values = field.getValues();
511: booleanValue = (values.hasNext() ? values.next() : "1");
512: room.setLogEnabled(("1".equals(booleanValue) ? true
513: : false));
514: }
515:
516: field = completedForm
517: .getField("x-muc#roomconfig_reservednick");
518: if (field != null) {
519: values = field.getValues();
520: booleanValue = (values.hasNext() ? values.next() : "1");
521: room.setLoginRestrictedToNickname(("1"
522: .equals(booleanValue) ? true : false));
523: }
524:
525: field = completedForm
526: .getField("x-muc#roomconfig_canchangenick");
527: if (field != null) {
528: values = field.getValues();
529: booleanValue = (values.hasNext() ? values.next() : "1");
530: room.setChangeNickname(("1".equals(booleanValue) ? true
531: : false));
532: }
533:
534: field = completedForm
535: .getField("x-muc#roomconfig_registration");
536: if (field != null) {
537: values = field.getValues();
538: booleanValue = (values.hasNext() ? values.next() : "1");
539: room
540: .setRegistrationEnabled(("1"
541: .equals(booleanValue) ? true : false));
542: }
543:
544: // Update the modification date to reflect the last time when the room's configuration
545: // was modified
546: room.setModificationDate(new Date());
547:
548: if (room.isPersistent()) {
549: room.saveToDB();
550: }
551:
552: // Set the new owners and admins of the room
553: presences.addAll(room.addOwners(owners, senderRole));
554: presences.addAll(room.addAdmins(admins, senderRole));
555:
556: if (ownersSent) {
557: // Change the affiliation to "member" for the current owners that won't be neither
558: // owner nor admin (if the form included the owners field)
559: List<String> ownersToRemove = new ArrayList<String>(
560: room.owners);
561: ownersToRemove.removeAll(admins);
562: ownersToRemove.removeAll(owners);
563: for (String jid : ownersToRemove) {
564: presences.addAll(room.addMember(jid, null,
565: senderRole));
566: }
567: }
568:
569: if (adminsSent) {
570: // Change the affiliation to "member" for the current admins that won't be neither
571: // owner nor admin (if the form included the admins field)
572: List<String> adminsToRemove = new ArrayList<String>(
573: room.admins);
574: adminsToRemove.removeAll(admins);
575: adminsToRemove.removeAll(owners);
576: for (String jid : adminsToRemove) {
577: presences.addAll(room.addMember(jid, null,
578: senderRole));
579: }
580: }
581:
582: // Destroy the room if the room is no longer persistent and there are no occupants in
583: // the room
584: if (!room.isPersistent() && room.getOccupantsCount() == 0) {
585: room.destroyRoom(null, null);
586: }
587:
588: } finally {
589: room.lock.writeLock().unlock();
590: }
591:
592: // Send the updated presences to the room occupants
593: for (Iterator it = presences.iterator(); it.hasNext();) {
594: room.send((Presence) it.next());
595: }
596: }
597:
598: private void refreshConfigurationFormValues() {
599: room.lock.readLock().lock();
600: try {
601: FormField field = configurationForm
602: .getField("muc#roomconfig_roomname");
603: field.clearValues();
604: field.addValue(room.getNaturalLanguageName());
605:
606: field = configurationForm
607: .getField("muc#roomconfig_roomdesc");
608: field.clearValues();
609: field.addValue(room.getDescription());
610:
611: field = configurationForm
612: .getField("muc#roomconfig_changesubject");
613: field.clearValues();
614: field.addValue((room.canOccupantsChangeSubject() ? "1"
615: : "0"));
616:
617: field = configurationForm
618: .getField("muc#roomconfig_maxusers");
619: field.clearValues();
620: field.addValue(Integer.toString(room.getMaxUsers()));
621:
622: field = configurationForm
623: .getField("muc#roomconfig_presencebroadcast");
624: field.clearValues();
625: for (String roleToBroadcast : room
626: .getRolesToBroadcastPresence()) {
627: field.addValue(roleToBroadcast);
628: }
629:
630: field = configurationForm
631: .getField("muc#roomconfig_publicroom");
632: field.clearValues();
633: field.addValue((room.isPublicRoom() ? "1" : "0"));
634:
635: field = configurationForm
636: .getField("muc#roomconfig_persistentroom");
637: field.clearValues();
638: field.addValue((room.isPersistent() ? "1" : "0"));
639:
640: field = configurationForm
641: .getField("muc#roomconfig_moderatedroom");
642: field.clearValues();
643: field.addValue((room.isModerated() ? "1" : "0"));
644:
645: field = configurationForm
646: .getField("muc#roomconfig_membersonly");
647: field.clearValues();
648: field.addValue((room.isMembersOnly() ? "1" : "0"));
649:
650: field = configurationForm
651: .getField("muc#roomconfig_allowinvites");
652: field.clearValues();
653: field.addValue((room.canOccupantsInvite() ? "1" : "0"));
654:
655: field = configurationForm
656: .getField("muc#roomconfig_passwordprotectedroom");
657: field.clearValues();
658: field.addValue((room.isPasswordProtected() ? "1" : "0"));
659:
660: field = configurationForm
661: .getField("muc#roomconfig_roomsecret");
662: field.clearValues();
663: field.addValue(room.getPassword());
664:
665: field = configurationForm.getField("muc#roomconfig_whois");
666: field.clearValues();
667: field.addValue((room.canAnyoneDiscoverJID() ? "anyone"
668: : "moderators"));
669:
670: field = configurationForm
671: .getField("muc#roomconfig_enablelogging");
672: field.clearValues();
673: field.addValue((room.isLogEnabled() ? "1" : "0"));
674:
675: field = configurationForm
676: .getField("x-muc#roomconfig_reservednick");
677: field.clearValues();
678: field.addValue((room.isLoginRestrictedToNickname() ? "1"
679: : "0"));
680:
681: field = configurationForm
682: .getField("x-muc#roomconfig_canchangenick");
683: field.clearValues();
684: field.addValue((room.canChangeNickname() ? "1" : "0"));
685:
686: field = configurationForm
687: .getField("x-muc#roomconfig_registration");
688: field.clearValues();
689: field.addValue((room.isRegistrationEnabled() ? "1" : "0"));
690:
691: field = configurationForm
692: .getField("muc#roomconfig_roomadmins");
693: field.clearValues();
694: for (String jid : room.getAdmins()) {
695: field.addValue(jid);
696: }
697:
698: field = configurationForm
699: .getField("muc#roomconfig_roomowners");
700: field.clearValues();
701: for (String jid : room.getOwners()) {
702: field.addValue(jid);
703: }
704:
705: // Remove the old element
706: probeResult.remove(probeResult.element(QName.get("x",
707: "jabber:x:data")));
708: // Add the new representation of configurationForm as an element
709: probeResult.add(configurationForm.asXMLElement());
710:
711: } finally {
712: room.lock.readLock().unlock();
713: }
714: }
715:
716: private void init() {
717: Element element = DocumentHelper.createElement(QName.get(
718: "query", "http://jabber.org/protocol/muc#owner"));
719:
720: configurationForm = new XDataFormImpl(DataForm.TYPE_FORM);
721: configurationForm.setTitle(LocaleUtils
722: .getLocalizedString("muc.form.conf.title"));
723: List params = new ArrayList();
724: params.add(room.getName());
725: configurationForm
726: .addInstruction(LocaleUtils.getLocalizedString(
727: "muc.form.conf.instruction", params));
728:
729: XFormFieldImpl field = new XFormFieldImpl("FORM_TYPE");
730: field.setType(FormField.TYPE_HIDDEN);
731: field.addValue("http://jabber.org/protocol/muc#roomconfig");
732: configurationForm.addField(field);
733:
734: field = new XFormFieldImpl("muc#roomconfig_roomname");
735: field.setType(FormField.TYPE_TEXT_SINGLE);
736: field.setLabel(LocaleUtils
737: .getLocalizedString("muc.form.conf.owner_roomname"));
738: configurationForm.addField(field);
739:
740: field = new XFormFieldImpl("muc#roomconfig_roomdesc");
741: field.setType(FormField.TYPE_TEXT_SINGLE);
742: field.setLabel(LocaleUtils
743: .getLocalizedString("muc.form.conf.owner_roomdesc"));
744: configurationForm.addField(field);
745:
746: field = new XFormFieldImpl("muc#roomconfig_changesubject");
747: field.setType(FormField.TYPE_BOOLEAN);
748: field
749: .setLabel(LocaleUtils
750: .getLocalizedString("muc.form.conf.owner_changesubject"));
751: configurationForm.addField(field);
752:
753: field = new XFormFieldImpl("muc#roomconfig_maxusers");
754: field.setType(FormField.TYPE_LIST_SINGLE);
755: field.setLabel(LocaleUtils
756: .getLocalizedString("muc.form.conf.owner_maxusers"));
757: field.addOption("10", "10");
758: field.addOption("20", "20");
759: field.addOption("30", "30");
760: field.addOption("40", "40");
761: field.addOption("50", "50");
762: field.addOption(LocaleUtils
763: .getLocalizedString("muc.form.conf.none"), "0");
764: configurationForm.addField(field);
765:
766: field = new XFormFieldImpl("muc#roomconfig_presencebroadcast");
767: field.setType(FormField.TYPE_LIST_MULTI);
768: field
769: .setLabel(LocaleUtils
770: .getLocalizedString("muc.form.conf.owner_presencebroadcast"));
771: field.addOption(LocaleUtils
772: .getLocalizedString("muc.form.conf.moderator"),
773: "moderator");
774: field.addOption(LocaleUtils
775: .getLocalizedString("muc.form.conf.participant"),
776: "participant");
777: field
778: .addOption(LocaleUtils
779: .getLocalizedString("muc.form.conf.visitor"),
780: "visitor");
781: configurationForm.addField(field);
782:
783: field = new XFormFieldImpl("muc#roomconfig_publicroom");
784: field.setType(FormField.TYPE_BOOLEAN);
785: field.setLabel(LocaleUtils
786: .getLocalizedString("muc.form.conf.owner_publicroom"));
787: configurationForm.addField(field);
788:
789: field = new XFormFieldImpl("muc#roomconfig_persistentroom");
790: field.setType(FormField.TYPE_BOOLEAN);
791: field
792: .setLabel(LocaleUtils
793: .getLocalizedString("muc.form.conf.owner_persistentroom"));
794: configurationForm.addField(field);
795:
796: field = new XFormFieldImpl("muc#roomconfig_moderatedroom");
797: field.setType(FormField.TYPE_BOOLEAN);
798: field
799: .setLabel(LocaleUtils
800: .getLocalizedString("muc.form.conf.owner_moderatedroom"));
801: configurationForm.addField(field);
802:
803: field = new XFormFieldImpl("muc#roomconfig_membersonly");
804: field.setType(FormField.TYPE_BOOLEAN);
805: field.setLabel(LocaleUtils
806: .getLocalizedString("muc.form.conf.owner_membersonly"));
807: configurationForm.addField(field);
808:
809: field = new XFormFieldImpl();
810: field.setType(FormField.TYPE_FIXED);
811: field.addValue(LocaleUtils
812: .getLocalizedString("muc.form.conf.allowinvitesfixed"));
813: configurationForm.addField(field);
814:
815: field = new XFormFieldImpl("muc#roomconfig_allowinvites");
816: field.setType(FormField.TYPE_BOOLEAN);
817: field
818: .setLabel(LocaleUtils
819: .getLocalizedString("muc.form.conf.owner_allowinvites"));
820: configurationForm.addField(field);
821:
822: field = new XFormFieldImpl(
823: "muc#roomconfig_passwordprotectedroom");
824: field.setType(FormField.TYPE_BOOLEAN);
825: field
826: .setLabel(LocaleUtils
827: .getLocalizedString("muc.form.conf.owner_passwordprotectedroom"));
828: configurationForm.addField(field);
829:
830: field = new XFormFieldImpl();
831: field.setType(FormField.TYPE_FIXED);
832: field.addValue(LocaleUtils
833: .getLocalizedString("muc.form.conf.roomsecretfixed"));
834: configurationForm.addField(field);
835:
836: field = new XFormFieldImpl("muc#roomconfig_roomsecret");
837: field.setType(FormField.TYPE_TEXT_PRIVATE);
838: field.setLabel(LocaleUtils
839: .getLocalizedString("muc.form.conf.owner_roomsecret"));
840: configurationForm.addField(field);
841:
842: field = new XFormFieldImpl("muc#roomconfig_whois");
843: field.setType(FormField.TYPE_LIST_SINGLE);
844: field.setLabel(LocaleUtils
845: .getLocalizedString("muc.form.conf.owner_whois"));
846: field.addOption(LocaleUtils
847: .getLocalizedString("muc.form.conf.moderator"),
848: "moderators");
849: field.addOption(LocaleUtils
850: .getLocalizedString("muc.form.conf.anyone"), "anyone");
851: configurationForm.addField(field);
852:
853: field = new XFormFieldImpl("muc#roomconfig_enablelogging");
854: field.setType(FormField.TYPE_BOOLEAN);
855: field
856: .setLabel(LocaleUtils
857: .getLocalizedString("muc.form.conf.owner_enablelogging"));
858: configurationForm.addField(field);
859:
860: field = new XFormFieldImpl("x-muc#roomconfig_reservednick");
861: field.setType(FormField.TYPE_BOOLEAN);
862: field
863: .setLabel(LocaleUtils
864: .getLocalizedString("muc.form.conf.owner_reservednick"));
865: configurationForm.addField(field);
866:
867: field = new XFormFieldImpl("x-muc#roomconfig_canchangenick");
868: field.setType(FormField.TYPE_BOOLEAN);
869: field
870: .setLabel(LocaleUtils
871: .getLocalizedString("muc.form.conf.owner_canchangenick"));
872: configurationForm.addField(field);
873:
874: field = new XFormFieldImpl("x-muc#roomconfig_registration");
875: field.setType(FormField.TYPE_BOOLEAN);
876: field
877: .setLabel(LocaleUtils
878: .getLocalizedString("muc.form.conf.owner_registration"));
879: configurationForm.addField(field);
880:
881: field = new XFormFieldImpl();
882: field.setType(FormField.TYPE_FIXED);
883: field.addValue(LocaleUtils
884: .getLocalizedString("muc.form.conf.roomadminsfixed"));
885: configurationForm.addField(field);
886:
887: field = new XFormFieldImpl("muc#roomconfig_roomadmins");
888: field.setType(FormField.TYPE_JID_MULTI);
889: field.setLabel(LocaleUtils
890: .getLocalizedString("muc.form.conf.owner_roomadmins"));
891: configurationForm.addField(field);
892:
893: field = new XFormFieldImpl();
894: field.setType(FormField.TYPE_FIXED);
895: field.addValue(LocaleUtils
896: .getLocalizedString("muc.form.conf.roomownersfixed"));
897: configurationForm.addField(field);
898:
899: field = new XFormFieldImpl("muc#roomconfig_roomowners");
900: field.setType(FormField.TYPE_JID_MULTI);
901: field.setLabel(LocaleUtils
902: .getLocalizedString("muc.form.conf.owner_roomowners"));
903: configurationForm.addField(field);
904:
905: // Create the probeResult and add the basic info together with the configuration form
906: probeResult = element;
907: probeResult.add(configurationForm.asXMLElement());
908: }
909: }
|