KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xmpp > muc > RoomConfiguration


1 /**
2  * $RCSfile: RoomConfiguration.java,v $
3  * $Revision: 1.1 $
4  * $Date: 2005/02/06 20:02:22 $
5  *
6  * Copyright 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.xmpp.muc;
22
23 import org.dom4j.Element;
24 import org.xmpp.packet.IQ;
25
26 import java.util.Collection JavaDoc;
27 import java.util.Map JavaDoc;
28
29 /**
30  * RoomConfiguration is a packet that helps to set the configuration of MUC rooms. RoomConfiguration
31  * is a speacial IQ packet whose child element contains a data form. The data form holds the fields
32  * to set together with a list of values.<p>
33  *
34  * Code example:
35  * <pre>
36  * // Set the fields and the values.
37  * Map<String,Collection<String>> fields = new HashMap<String,Collection<String>>();
38  * // Make a non-public room
39  * List<String> values = new ArrayList<String>();
40  * values.add("0");
41  * fields.put("muc#roomconfig_publicroom", values);
42  *
43  * // Create a RoomConfiguration with the fields and values
44  * RoomConfiguration conf = new RoomConfiguration(fields);
45  * conf.setTo("room@conference.jabber.org");
46  * conf.setFrom("john@jabber.org/notebook");
47  *
48  * component.sendPacket(conf);
49  * </pre>
50  *
51  * @author Gaston Dombiak
52  */

53 public class RoomConfiguration extends IQ {
54
55     /**
56      * Creates a new IQ packet that contains the field and values to send for setting the room
57      * configuration.
58      *
59      * @param fieldValues the list of fields associated with the list of values.
60      */

61     public RoomConfiguration(Map JavaDoc<String JavaDoc,Collection JavaDoc<String JavaDoc>> fieldValues) {
62         super();
63         setType(Type.set);
64         Element query = setChildElement("query", "http://jabber.org/protocol/muc#owner");
65         Element form = query.addElement("x", "jabber:x:data");
66         form.addAttribute("type", "submit");
67         // Add static field
68
Element field = form.addElement("field");
69         field.addAttribute("var", "FORM_TYPE");
70         field.addElement("value").setText("http://jabber.org/protocol/muc#roomconfig");
71         // Add the specified fields and their corresponding values
72
for (String JavaDoc variable : fieldValues.keySet()) {
73             field = form.addElement("field");
74             field.addAttribute("var", variable);
75             for (String JavaDoc value : fieldValues.get(variable)) {
76                 field.addElement("value").setText(value);
77             }
78         }
79     }
80 }
81
Popular Tags