01: /**
02: * Copyright (C) 2004-2007 Jive Software. All rights reserved.
03: *
04: * This software is published under the terms of the GNU Public License (GPL),
05: * a copy of which is included in this distribution.
06: */package org.xmpp.muc;
07:
08: import org.dom4j.Element;
09: import org.xmpp.packet.IQ;
10:
11: import java.util.Collection;
12: import java.util.Map;
13:
14: /**
15: * RoomConfiguration is a packet that helps to set the configuration of MUC rooms. RoomConfiguration
16: * is a speacial IQ packet whose child element contains a data form. The data form holds the fields
17: * to set together with a list of values.<p>
18: *
19: * Code example:
20: * <pre>
21: * // Set the fields and the values.
22: * Map<String,Collection<String>> fields = new HashMap<String,Collection<String>>();
23: * // Make a non-public room
24: * List<String> values = new ArrayList<String>();
25: * values.add("0");
26: * fields.put("muc#roomconfig_publicroom", values);
27: *
28: * // Create a RoomConfiguration with the fields and values
29: * RoomConfiguration conf = new RoomConfiguration(fields);
30: * conf.setTo("room@conference.jabber.org");
31: * conf.setFrom("john@jabber.org/notebook");
32: *
33: * component.sendPacket(conf);
34: * </pre>
35: *
36: * @author Gaston Dombiak
37: */
38: public class RoomConfiguration extends IQ {
39:
40: /**
41: * Creates a new IQ packet that contains the field and values to send for setting the room
42: * configuration.
43: *
44: * @param fieldValues the list of fields associated with the list of values.
45: */
46: public RoomConfiguration(Map<String, Collection<String>> fieldValues) {
47: super ();
48: setType(Type.set);
49: Element query = setChildElement("query",
50: "http://jabber.org/protocol/muc#owner");
51: Element form = query.addElement("x", "jabber:x:data");
52: form.addAttribute("type", "submit");
53: // Add static field
54: Element field = form.addElement("field");
55: field.addAttribute("var", "FORM_TYPE");
56: field.addElement("value").setText(
57: "http://jabber.org/protocol/muc#roomconfig");
58: // Add the specified fields and their corresponding values
59: for (String variable : fieldValues.keySet()) {
60: field = form.addElement("field");
61: field.addAttribute("var", variable);
62: for (String value : fieldValues.get(variable)) {
63: field.addElement("value").setText(value);
64: }
65: }
66: }
67: }
|