KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jivesoftware > smackx > muc > RoomInfo


1 /**
2  * $RCSfile$
3  * $Revision: 2493 $
4  * $Date: 2005-05-27 15:12:52 -0300 (Fri, 27 May 2005) $
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.muc;
22
23 import org.jivesoftware.smackx.packet.DiscoverInfo;
24 import org.jivesoftware.smackx.Form;
25
26 /**
27  * Represents the room information that was discovered using Service Discovery. It's possible to
28  * obtain information about a room before joining the room but only for rooms that are public (i.e.
29  * rooms that may be discovered).
30  *
31  * @author Gaston Dombiak
32  */

33 public class RoomInfo {
34
35     /**
36      * JID of the room. The node of the JID is commonly used as the ID of the room or name.
37      */

38     private String JavaDoc room;
39     /**
40      * Description of the room.
41      */

42     private String JavaDoc description = "";
43     /**
44      * Last known subject of the room.
45      */

46     private String JavaDoc subject = "";
47     /**
48      * Current number of occupants in the room.
49      */

50     private int occupantsCount = -1;
51     /**
52      * A room is considered members-only if an invitation is required in order to enter the room.
53      * Any user that is not a member of the room won't be able to join the room unless the user
54      * decides to register with the room (thus becoming a member).
55      */

56     private boolean membersOnly;
57     /**
58      * Moderated rooms enable only participants to speak. Users that join the room and aren't
59      * participants can't speak (they are just visitors).
60      */

61     private boolean moderated;
62     /**
63      * Every presence packet can include the JID of every occupant unless the owner deactives this
64      * configuration.
65      */

66     private boolean nonanonymous;
67     /**
68      * Indicates if users must supply a password to join the room.
69      */

70     private boolean passwordProtected;
71     /**
72      * Persistent rooms are saved to the database to make sure that rooms configurations can be
73      * restored in case the server goes down.
74      */

75     private boolean persistent;
76
77     RoomInfo(DiscoverInfo info) {
78         super();
79         this.room = info.getFrom();
80         // Get the information based on the discovered features
81
this.membersOnly = info.containsFeature("muc_membersonly");
82         this.moderated = info.containsFeature("muc_moderated");
83         this.nonanonymous = info.containsFeature("muc_nonanonymous");
84         this.passwordProtected = info.containsFeature("muc_passwordprotected");
85         this.persistent = info.containsFeature("muc_persistent");
86         // Get the information based on the discovered extended information
87
Form form = Form.getFormFrom(info);
88         if (form != null) {
89             this.description =
90                     (String JavaDoc) form.getField("muc#roominfo_description").getValues().next();
91             this.subject = (String JavaDoc) form.getField("muc#roominfo_subject").getValues().next();
92             this.occupantsCount =
93                     Integer.parseInt((String JavaDoc) form.getField("muc#roominfo_occupants").getValues()
94                     .next());
95         }
96     }
97
98     /**
99      * Returns the JID of the room whose information was discovered.
100      *
101      * @return the JID of the room whose information was discovered.
102      */

103     public String JavaDoc getRoom() {
104         return room;
105     }
106
107     /**
108      * Returns the discovered description of the room.
109      *
110      * @return the discovered description of the room.
111      */

112     public String JavaDoc getDescription() {
113         return description;
114     }
115
116     /**
117      * Returns the discovered subject of the room. The subject may be empty if the room does not
118      * have a subject.
119      *
120      * @return the discovered subject of the room.
121      */

122     public String JavaDoc getSubject() {
123         return subject;
124     }
125
126     /**
127      * Returns the discovered number of occupants that are currently in the room. If this
128      * information was not discovered (i.e. the server didn't send it) then a value of -1 will be
129      * returned.
130      *
131      * @return the number of occupants that are currently in the room or -1 if that information was
132      * not provided by the server.
133      */

134     public int getOccupantsCount() {
135         return occupantsCount;
136     }
137
138     /**
139      * Returns true if the room has restricted the access so that only members may enter the room.
140      *
141      * @return true if the room has restricted the access so that only members may enter the room.
142      */

143     public boolean isMembersOnly() {
144         return membersOnly;
145     }
146
147     /**
148      * Returns true if the room enabled only participants to speak. Occupants with a role of
149      * visitor won't be able to speak in the room.
150      *
151      * @return true if the room enabled only participants to speak.
152      */

153     public boolean isModerated() {
154         return moderated;
155     }
156
157     /**
158      * Returns true if presence packets will include the JID of every occupant.
159      *
160      * @return true if presence packets will include the JID of every occupant.
161      */

162     public boolean isNonanonymous() {
163         return nonanonymous;
164     }
165
166     /**
167      * Returns true if users musy provide a valid password in order to join the room.
168      *
169      * @return true if users musy provide a valid password in order to join the room.
170      */

171     public boolean isPasswordProtected() {
172         return passwordProtected;
173     }
174
175     /**
176      * Returns true if the room will persist after the last occupant have left the room.
177      *
178      * @return true if the room will persist after the last occupant have left the room.
179      */

180     public boolean isPersistent() {
181         return persistent;
182     }
183
184 }
185
Popular Tags