Jitsi: the OpenSource Java VoIP and Instant Messaging client.

net.java.sip.communicator.impl.protocol.jabber
Class ChatRoomJabberImpl

java.lang.Object
  extended by net.java.sip.communicator.impl.protocol.jabber.ChatRoomJabberImpl
All Implemented Interfaces:
ChatRoom

public class ChatRoomJabberImpl
extends Object
implements ChatRoom

Implements chat rooms for jabber. The class encapsulates instances of the jive software MultiUserChat.

Author:
Emil Ivov, Yana Stamcheva, Valentin Martinet

Constructor Summary
ChatRoomJabberImpl(org.jivesoftware.smackx.muc.MultiUserChat multiUserChat, ProtocolProviderServiceJabberImpl provider)
          Creates an instance of a chat room that has been.
 
Method Summary
 void addLocalUserRoleListener(ChatRoomLocalUserRoleListener listener)
          Adds a listener that will be notified of changes in our role in the room such as us being granded operator.
 void addMemberPresenceListener(ChatRoomMemberPresenceListener listener)
          Adds a listener that will be notified of changes in our status in the room such as us being kicked, banned, or granted admin permissions.
 void addMemberPropertyChangeListener(ChatRoomMemberPropertyChangeListener listener)
          Adds the given listener to the list of listeners registered to receive events upon modification of chat room member properties such as its nickname being changed for example.
 void addMemberRoleListener(ChatRoomMemberRoleListener listener)
          Adds a listener that will be notified of changes of a member role in the room such as being granded operator.
 void addMessageListener(ChatRoomMessageListener listener)
          Registers listener so that it would receive events every time a new message is received on this chat room.
 void addPropertyChangeListener(ChatRoomPropertyChangeListener listener)
          Adds listener to the list of listeners registered to receive events upon modification of chat room properties such as its subject for example.
 void banParticipant(ChatRoomMember chatRoomMember, String reason)
          Bans a user from the room.
 Message createMessage(byte[] content, String contentType, String contentEncoding, String subject)
          Create a Message instance for sending arbitrary MIME-encoding content.
 Message createMessage(String messageText)
          Create a Message instance for sending a simple text messages with default (text/plain) content type and encoding.
 ChatRoomMemberJabberImpl findMemberForNickName(String jabberID)
          Finds the member of this chat room corresponding to the given nick name.
 void fireMemberPropertyChangeEvent(ChatRoomMemberPropertyChangeEvent evt)
          Delivers the specified event to all registered property change listeners.
 Iterator<ChatRoomMember> getBanList()
          Returns the list of banned users.
 ChatRoomConfigurationForm getConfigurationForm()
          Returns the ChatRoomConfigurationForm containing all configuration properties for this chat room.
 String getIdentifier()
          Returns the identifier of this ChatRoom.
 List<ChatRoomMember> getMembers()
          Returns a List of Members corresponding to all members currently participating in this room.
 int getMembersCount()
          Returns the number of participants that are currently in this chat room.
(package private)  org.jivesoftware.smackx.muc.MultiUserChat getMultiUserChat()
          Returns the internal stack used chat room instance.
 String getName()
          Returns the name of this ChatRoom.
(package private) static String getNickName(String participantAddress)
          Returns the nickname of the given participant name.
 ProtocolProviderService getParentProvider()
          Returns a reference to the provider that created this room.
 String getSubject()
          Returns the last known room subject/theme or null if the user hasn't joined the room or the room does not have a subject yet.
 String getUserNickname()
          Returns the local user's nickname in the context of this chat room or null if not currently joined.
 ChatRoomMemberRole getUserRole()
          Returns local user role in the context of this chatroom.
 void grantAdmin(String jid)
          Grants administrator privileges to another user.
 void grantMembership(String jid)
          Grants membership to a user.
 void grantModerator(String nickname)
          Grants moderator privileges to a participant or visitor.
 void grantOwnership(String jid)
          Grants ownership privileges to another user.
 void grantVoice(String nickname)
          Grants voice to a visitor in the room.
 void invite(String userAddress, String reason)
          Invites another user to this room.
 boolean isJoined()
          Returns true if the local user is currently in the multi user chat (after calling one of the join() methods).
 boolean isPersistent()
          Determines whether this chat room should be stored in the configuration file or not.
 boolean isSystem()
          The Jabber multi user chat implementation doesn't support system rooms.
 void join()
          Joins this chat room with the nickname of the local user so that the user would start receiving events and messages for it.
 void join(byte[] password)
          Joins this chat room so that the user would start receiving events and messages for it.
 void joinAs(String nickname)
          Joins this chat room with the specified nickname so that the user would start receiving events and messages for it.
 void joinAs(String nickname, byte[] password)
          Joins this chat room with the specified nickname and password so that the user would start receiving events and messages for it.
 void kickParticipant(ChatRoomMember member, String reason)
          Kicks a participant from the room.
 void leave()
          Leave this chat room.
 void removelocalUserRoleListener(ChatRoomLocalUserRoleListener listener)
          Removes a listener that was being notified of changes in our role in this chat room such as us being granded operator.
 void removeMemberPresenceListener(ChatRoomMemberPresenceListener listener)
          Removes a listener that was being notified of changes in the status of other chat room participants such as users being kicked, banned, or granted admin permissions.
 void removeMemberPropertyChangeListener(ChatRoomMemberPropertyChangeListener listener)
          Removes the given listener from the list of listeners currently registered for chat room member property change events.
 void removeMemberRoleListener(ChatRoomMemberRoleListener listener)
          Removes a listener that was being notified of changes of a member role in this chat room such as us being granded operator.
 void removeMessageListener(ChatRoomMessageListener listener)
          Removes listener so that it won't receive any further message events from this room.
 void removePropertyChangeListener(ChatRoomPropertyChangeListener listener)
          Removes listener from the list of listeneres current registered for chat room modification events.
 void revokeAdmin(String jid)
          Revokes administrator privileges from a user.
 void revokeMembership(String jid)
          Revokes a user's membership.
 void revokeModerator(String nickname)
          Revokes moderator privileges from another user.
 void revokeOwnership(String jid)
          Revokes ownership privileges from another user.
 void revokeVoice(String nickname)
          Revokes voice from a participant in the room.
 void sendMessage(Message message)
          Sends the message to the destination indicated by the to contact.
 void setLocalUserRole(ChatRoomMemberRole role)
          Sets the new rolefor the local user in the context of this chatroom.
 void setSubject(String subject)
          Sets the subject of this chat room.
 void setUserNickname(String nickname)
          Changes the local user nickname.
 ChatRoomMemberJabberImpl smackParticipantToScMember(String participant)
          Returns the ChatRoomMember corresponding to the given smack participant.
(package private) static ChatRoomMemberRole smackRoleToScRole(String smackRole)
          Returns that ChatRoomJabberRole instance corresponding to the smackRole string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChatRoomJabberImpl

public ChatRoomJabberImpl(org.jivesoftware.smackx.muc.MultiUserChat multiUserChat,
                          ProtocolProviderServiceJabberImpl provider)
Creates an instance of a chat room that has been.

Parameters:
multiUserChat - MultiUserChat
provider - a reference to the currently valid jabber protocol provider.
Method Detail

addPropertyChangeListener

public void addPropertyChangeListener(ChatRoomPropertyChangeListener listener)
Adds listener to the list of listeners registered to receive events upon modification of chat room properties such as its subject for example.

Specified by:
addPropertyChangeListener in interface ChatRoom
Parameters:
listener - the ChatRoomChangeListener that is to be registered for ChatRoomChangeEvent-s.

removePropertyChangeListener

public void removePropertyChangeListener(ChatRoomPropertyChangeListener listener)
Removes listener from the list of listeneres current registered for chat room modification events.

Specified by:
removePropertyChangeListener in interface ChatRoom
Parameters:
listener - the ChatRoomChangeListener to remove.

addMemberPropertyChangeListener

public void addMemberPropertyChangeListener(ChatRoomMemberPropertyChangeListener listener)
Adds the given listener to the list of listeners registered to receive events upon modification of chat room member properties such as its nickname being changed for example.

Specified by:
addMemberPropertyChangeListener in interface ChatRoom
Parameters:
listener - the ChatRoomMemberPropertyChangeListener that is to be registered for ChatRoomMemberPropertyChangeEvents.

removeMemberPropertyChangeListener

public void removeMemberPropertyChangeListener(ChatRoomMemberPropertyChangeListener listener)
Removes the given listener from the list of listeners currently registered for chat room member property change events.

Specified by:
removeMemberPropertyChangeListener in interface ChatRoom
Parameters:
listener - the ChatRoomMemberPropertyChangeListener to remove.

addMessageListener

public void addMessageListener(ChatRoomMessageListener listener)
Registers listener so that it would receive events every time a new message is received on this chat room.

Specified by:
addMessageListener in interface ChatRoom
Parameters:
listener - a MessageListener that would be notified every time a new message is received on this chat room.

removeMessageListener

public void removeMessageListener(ChatRoomMessageListener listener)
Removes listener so that it won't receive any further message events from this room.

Specified by:
removeMessageListener in interface ChatRoom
Parameters:
listener - the MessageListener to remove from this room

addMemberPresenceListener

public void addMemberPresenceListener(ChatRoomMemberPresenceListener listener)
Adds a listener that will be notified of changes in our status in the room such as us being kicked, banned, or granted admin permissions.

Specified by:
addMemberPresenceListener in interface ChatRoom
Parameters:
listener - a participant status listener.

removeMemberPresenceListener

public void removeMemberPresenceListener(ChatRoomMemberPresenceListener listener)
Removes a listener that was being notified of changes in the status of other chat room participants such as users being kicked, banned, or granted admin permissions.

Specified by:
removeMemberPresenceListener in interface ChatRoom
Parameters:
listener - a participant status listener.

createMessage

public Message createMessage(byte[] content,
                             String contentType,
                             String contentEncoding,
                             String subject)
Create a Message instance for sending arbitrary MIME-encoding content.

Specified by:
createMessage in interface ChatRoom
Parameters:
content - content value
contentType - the MIME-type for content
contentEncoding - encoding used for content
subject - a String subject or null for now subject.
Returns:
the newly created message.

createMessage

public Message createMessage(String messageText)
Create a Message instance for sending a simple text messages with default (text/plain) content type and encoding.

Specified by:
createMessage in interface ChatRoom
Parameters:
messageText - the string content of the message.
Returns:
Message the newly created message

getMembers

public List<ChatRoomMember> getMembers()
Returns a List of Members corresponding to all members currently participating in this room.

Specified by:
getMembers in interface ChatRoom
Returns:
a List of Member corresponding to all room members.

getMembersCount

public int getMembersCount()
Returns the number of participants that are currently in this chat room.

Specified by:
getMembersCount in interface ChatRoom
Returns:
int the number of Contacts, currently participating in this room.

getName

public String getName()
Returns the name of this ChatRoom.

Specified by:
getName in interface ChatRoom
Returns:
a String containing the name of this ChatRoom.

getIdentifier

public String getIdentifier()
Returns the identifier of this ChatRoom.

Specified by:
getIdentifier in interface ChatRoom
Returns:
a String containing the identifier of this ChatRoom.

getUserNickname

public String getUserNickname()
Returns the local user's nickname in the context of this chat room or null if not currently joined.

Specified by:
getUserNickname in interface ChatRoom
Returns:
the nickname currently being used by the local user in the context of the local chat room.

getSubject

public String getSubject()
Returns the last known room subject/theme or null if the user hasn't joined the room or the room does not have a subject yet.

Specified by:
getSubject in interface ChatRoom
Returns:
the room subject or null if the user hasn't joined the room or the room does not have a subject yet.

invite

public void invite(String userAddress,
                   String reason)
Invites another user to this room.

Specified by:
invite in interface ChatRoom
Parameters:
userAddress - the address of the user to invite to the room.(one may also invite users not on their contact list).
reason - a reason, subject, or welcome message that would tell the the user why they are being invited.

isJoined

public boolean isJoined()
Returns true if the local user is currently in the multi user chat (after calling one of the join() methods).

Specified by:
isJoined in interface ChatRoom
Returns:
true if currently we're currently in this chat room and false otherwise.

join

public void join(byte[] password)
          throws OperationFailedException
Joins this chat room so that the user would start receiving events and messages for it.

Specified by:
join in interface ChatRoom
Parameters:
password - the password to use when authenticating on the chatroom.
Throws:
OperationFailedException - with the corresponding code if an error occurs while joining the room.

join

public void join()
          throws OperationFailedException
Joins this chat room with the nickname of the local user so that the user would start receiving events and messages for it.

Specified by:
join in interface ChatRoom
Throws:
OperationFailedException - with the corresponding code if an error occurs while joining the room.

joinAs

public void joinAs(String nickname,
                   byte[] password)
            throws OperationFailedException
Joins this chat room with the specified nickname and password so that the user would start receiving events and messages for it.

Specified by:
joinAs in interface ChatRoom
Parameters:
nickname - the nickname to use.
password - a password necessary to authenticate when joining the room.
Throws:
OperationFailedException - with the corresponding code if an error occurs while joining the room.

joinAs

public void joinAs(String nickname)
            throws OperationFailedException
Joins this chat room with the specified nickname so that the user would start receiving events and messages for it.

Specified by:
joinAs in interface ChatRoom
Parameters:
nickname - the nickname to use.
Throws:
OperationFailedException - with the corresponding code if an error occurs while joining the room.

smackRoleToScRole

static ChatRoomMemberRole smackRoleToScRole(String smackRole)
Returns that ChatRoomJabberRole instance corresponding to the smackRole string.

Parameters:
smackRole - the smack role as returned by Occupant.getRole().
Returns:
ChatRoomMemberRole

smackParticipantToScMember

public ChatRoomMemberJabberImpl smackParticipantToScMember(String participant)
Returns the ChatRoomMember corresponding to the given smack participant.

Parameters:
participant - the full participant name (e.g. sc-testroom@conference.voipgw.u-strasbg.fr/testuser)
Returns:
the ChatRoomMember corresponding to the given smack participant

leave

public void leave()
Leave this chat room.

Specified by:
leave in interface ChatRoom

sendMessage

public void sendMessage(Message message)
                 throws OperationFailedException
Sends the message to the destination indicated by the to contact.

Specified by:
sendMessage in interface ChatRoom
Parameters:
message - the Message to send.
Throws:
OperationFailedException - if sending the message fails for some reason.

setSubject

public void setSubject(String subject)
                throws OperationFailedException
Sets the subject of this chat room.

Specified by:
setSubject in interface ChatRoom
Parameters:
subject - the new subject that we'd like this room to have
Throws:
OperationFailedException

getParentProvider

public ProtocolProviderService getParentProvider()
Returns a reference to the provider that created this room.

Specified by:
getParentProvider in interface ChatRoom
Returns:
a reference to the ProtocolProviderService instance that created this room.

getUserRole

public ChatRoomMemberRole getUserRole()
Returns local user role in the context of this chatroom.

Specified by:
getUserRole in interface ChatRoom
Returns:
ChatRoomMemberRole

setLocalUserRole

public void setLocalUserRole(ChatRoomMemberRole role)
Sets the new rolefor the local user in the context of this chatroom.

Specified by:
setLocalUserRole in interface ChatRoom
Parameters:
role - the new role to be set for the local user

addLocalUserRoleListener

public void addLocalUserRoleListener(ChatRoomLocalUserRoleListener listener)
Adds a listener that will be notified of changes in our role in the room such as us being granded operator.

Specified by:
addLocalUserRoleListener in interface ChatRoom
Parameters:
listener - a local user role listener.

removelocalUserRoleListener

public void removelocalUserRoleListener(ChatRoomLocalUserRoleListener listener)
Removes a listener that was being notified of changes in our role in this chat room such as us being granded operator.

Specified by:
removelocalUserRoleListener in interface ChatRoom
Parameters:
listener - a local user role listener.

addMemberRoleListener

public void addMemberRoleListener(ChatRoomMemberRoleListener listener)
Adds a listener that will be notified of changes of a member role in the room such as being granded operator.

Specified by:
addMemberRoleListener in interface ChatRoom
Parameters:
listener - a member role listener.

removeMemberRoleListener

public void removeMemberRoleListener(ChatRoomMemberRoleListener listener)
Removes a listener that was being notified of changes of a member role in this chat room such as us being granded operator.

Specified by:
removeMemberRoleListener in interface ChatRoom
Parameters:
listener - a member role listener.

getBanList

public Iterator<ChatRoomMember> getBanList()
                                    throws OperationFailedException
Returns the list of banned users.

Specified by:
getBanList in interface ChatRoom
Returns:
a list of all banned participants
Throws:
OperationFailedException - if we could not obtain the ban list

setUserNickname

public void setUserNickname(String nickname)
                     throws OperationFailedException
Changes the local user nickname. If the new nickname already exist in the chat room throws an OperationFailedException.

Specified by:
setUserNickname in interface ChatRoom
Parameters:
nickname - the new nickname within the room.
Throws:
OperationFailedException - if the new nickname already exist in this room

banParticipant

public void banParticipant(ChatRoomMember chatRoomMember,
                           String reason)
                    throws OperationFailedException
Bans a user from the room. An admin or owner of the room can ban users from a room.

Specified by:
banParticipant in interface ChatRoom
Parameters:
chatRoomMember - the ChatRoomMember to be banned.
reason - the reason why the user was banned.
Throws:
OperationFailedException - if an error occurs while banning a user. In particular, an error can occur if a moderator or a user with an affiliation of "owner" or "admin" was tried to be banned or if the user that is banning have not enough permissions to ban.

kickParticipant

public void kickParticipant(ChatRoomMember member,
                            String reason)
                     throws OperationFailedException
Kicks a participant from the room.

Specified by:
kickParticipant in interface ChatRoom
Parameters:
member - the ChatRoomMember to kick from the room
reason - the reason why the participant is being kicked from the room
Throws:
OperationFailedException - if an error occurs while kicking the participant. In particular, an error can occur if a moderator or a user with an affiliation of "owner" or "admin" was intended to be kicked; or if the participant that intended to kick another participant does not have kicking privileges;

fireMemberPropertyChangeEvent

public void fireMemberPropertyChangeEvent(ChatRoomMemberPropertyChangeEvent evt)
Delivers the specified event to all registered property change listeners.

Parameters:
evt - the ChatRoomMemberPropertyChangeEvent that we'd like deliver to all registered member property change listeners.

getConfigurationForm

public ChatRoomConfigurationForm getConfigurationForm()
                                               throws OperationFailedException
Returns the ChatRoomConfigurationForm containing all configuration properties for this chat room. If the user doesn't have permissions to see and change chat room configuration an OperationFailedException is thrown.

Specified by:
getConfigurationForm in interface ChatRoom
Returns:
the ChatRoomConfigurationForm containing all configuration properties for this chat room
Throws:
OperationFailedException - if the user doesn't have permissions to see and change chat room configuration

isSystem

public boolean isSystem()
The Jabber multi user chat implementation doesn't support system rooms.

Specified by:
isSystem in interface ChatRoom
Returns:
false to indicate that the Jabber protocol implementation doesn't support system rooms.

isPersistent

public boolean isPersistent()
Determines whether this chat room should be stored in the configuration file or not. If the chat room is persistent it still will be shown after a restart in the chat room list. A non-persistent chat room will be only in the chat room list until the the program is running.

Specified by:
isPersistent in interface ChatRoom
Returns:
true if this chat room is persistent, false otherwise

findMemberForNickName

public ChatRoomMemberJabberImpl findMemberForNickName(String jabberID)
Finds the member of this chat room corresponding to the given nick name.

Parameters:
jabberID - the nick name to search for.
Returns:
the member of this chat room corresponding to the given nick name.

grantAdmin

public void grantAdmin(String jid)
Grants administrator privileges to another user. Room owners may grant administrator privileges to a member or un-affiliated user. An administrator is allowed to perform administrative functions such as banning users and edit moderator list.

Specified by:
grantAdmin in interface ChatRoom
Parameters:
jid - the bare XMPP user ID of the user to grant administrator privileges (e.g. "user@host.org").

grantMembership

public void grantMembership(String jid)
Grants membership to a user. Only administrators are able to grant membership. A user that becomes a room member will be able to enter a room of type Members-Only (i.e. a room that a user cannot enter without being on the member list).

Specified by:
grantMembership in interface ChatRoom
Parameters:
jid - the bare XMPP user ID of the user to grant membership privileges (e.g. "user@host.org").

grantModerator

public void grantModerator(String nickname)
Grants moderator privileges to a participant or visitor. Room administrators may grant moderator privileges. A moderator is allowed to kick users, grant and revoke voice, invite other users, modify room's subject plus all the partcipants privileges.

Specified by:
grantModerator in interface ChatRoom
Parameters:
nickname - the nickname of the occupant to grant moderator privileges.

grantOwnership

public void grantOwnership(String jid)
Grants ownership privileges to another user. Room owners may grant ownership privileges. Some room implementations will not allow to grant ownership privileges to other users. An owner is allowed to change defining room features as well as perform all administrative functions.

Specified by:
grantOwnership in interface ChatRoom
Parameters:
jid - the bare XMPP user ID of the user to grant ownership privileges (e.g. "user@host.org").

grantVoice

public void grantVoice(String nickname)
Grants voice to a visitor in the room. In a moderated room, a moderator may want to manage who does and does not have "voice" in the room. To have voice means that a room occupant is able to send messages to the room occupants.

Specified by:
grantVoice in interface ChatRoom
Parameters:
nickname - the nickname of the visitor to grant voice in the room (e.g. "john"). XMPPException if an error occurs granting voice to a visitor. In particular, a 403 error can occur if the occupant that intended to grant voice is not a moderator in this room (i.e. Forbidden error); or a 400 error can occur if the provided nickname is not present in the room.

revokeAdmin

public void revokeAdmin(String jid)
Revokes administrator privileges from a user. The occupant that loses administrator privileges will become a member. Room owners may revoke administrator privileges from a member or unaffiliated user.

Specified by:
revokeAdmin in interface ChatRoom
Parameters:
jid - the bare XMPP user ID of the user to grant administrator privileges (e.g. "user@host.org").

revokeMembership

public void revokeMembership(String jid)
Revokes a user's membership. Only administrators are able to revoke membership. A user that becomes a room member will be able to enter a room of type Members-Only (i.e. a room that a user cannot enter without being on the member list). If the user is in the room and the room is of type members-only then the user will be removed from the room.

Specified by:
revokeMembership in interface ChatRoom
Parameters:
jid - the bare XMPP user ID of the user to revoke membership (e.g. "user@host.org").

revokeModerator

public void revokeModerator(String nickname)
Revokes moderator privileges from another user. The occupant that loses moderator privileges will become a participant. Room administrators may revoke moderator privileges only to occupants whose affiliation is member or none. This means that an administrator is not allowed to revoke moderator privileges from other room administrators or owners.

Specified by:
revokeModerator in interface ChatRoom
Parameters:
nickname - the nickname of the occupant to revoke moderator privileges.

revokeOwnership

public void revokeOwnership(String jid)
Revokes ownership privileges from another user. The occupant that loses ownership privileges will become an administrator. Room owners may revoke ownership privileges. Some room implementations will not allow to grant ownership privileges to other users.

Specified by:
revokeOwnership in interface ChatRoom
Parameters:
jid - the bare XMPP user ID of the user to revoke ownership (e.g. "user@host.org").

revokeVoice

public void revokeVoice(String nickname)
Revokes voice from a participant in the room. In a moderated room, a moderator may want to revoke an occupant's privileges to speak. To have voice means that a room occupant is able to send messages to the room occupants.

Specified by:
revokeVoice in interface ChatRoom
Parameters:
nickname - the nickname of the participant to revoke voice (e.g. "john"). XMPPException if an error occurs revoking voice from a participant. In particular, a 405 error can occur if a moderator or a user with an affiliation of "owner" or "admin" was tried to revoke his voice (i.e. Not Allowed error); or a 400 error can occur if the provided nickname is not present in the room.

getNickName

static String getNickName(String participantAddress)
Returns the nickname of the given participant name. For example, for the address "john@xmppservice.com", "john" would be returned. If no @ is found in the address we return the given name.

Parameters:
participantAddress - the address of the participant
Returns:
the nickname part of the given participant address

getMultiUserChat

org.jivesoftware.smackx.muc.MultiUserChat getMultiUserChat()
Returns the internal stack used chat room instance.

Returns:
the chat room used in the protocol stack.

Jitsi: the OpenSource Java VoIP and Instant Messaging client.

Jitsi, the OpenSource Java VoIP and Instant Messaging client.
Distributable under LGPL license.