Commit a20374c6 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

1) Modified methods that were returning an Iterator to return a Collection.

2) Removed UnauthorizedException as a thrown exception in methods that was being used for ACL.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@492 b35dd754-fafc-0310-a699-88a17e54d16e
parent 91a56a59
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
package org.jivesoftware.messenger.muc; package org.jivesoftware.messenger.muc;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Date; import java.util.Date;
import java.util.Collection;
import org.jivesoftware.messenger.muc.spi.IQAdminHandler; import org.jivesoftware.messenger.muc.spi.IQAdminHandler;
import org.jivesoftware.messenger.muc.spi.IQOwnerHandler; import org.jivesoftware.messenger.muc.spi.IQOwnerHandler;
...@@ -128,9 +128,9 @@ public interface MUCRoom extends ChatDeliverer { ...@@ -128,9 +128,9 @@ public interface MUCRoom extends ChatDeliverer {
/** /**
* Obtain the roles of all users in the chatroom. * Obtain the roles of all users in the chatroom.
* *
* @return Iterator over all users in the chatroom * @return a collection with all users in the chatroom
*/ */
Iterator<MUCRole> getOccupants(); Collection<MUCRole> getOccupants();
/** /**
* Returns the number of occupants in the chatroom at the moment. * Returns the number of occupants in the chatroom at the moment.
...@@ -399,11 +399,9 @@ public interface MUCRoom extends ChatDeliverer { ...@@ -399,11 +399,9 @@ public interface MUCRoom extends ChatDeliverer {
* *
* @param packet the sent packet to change the room's subject. * @param packet the sent packet to change the room's subject.
* @param role the role of the user that is trying to change the subject. * @param role the role of the user that is trying to change the subject.
* @throws UnauthorizedException If the user doesn't have permision to change the subject.
* @throws ForbiddenException If the user is not allowed to change the subject. * @throws ForbiddenException If the user is not allowed to change the subject.
*/ */
public void changeSubject(Message packet, MUCRole role) throws UnauthorizedException, public void changeSubject(Message packet, MUCRole role) throws ForbiddenException;
ForbiddenException;
/** /**
* Returns the last subject that some occupant set to the room. * Returns the last subject that some occupant set to the room.
...@@ -427,12 +425,10 @@ public interface MUCRoom extends ChatDeliverer { ...@@ -427,12 +425,10 @@ public interface MUCRoom extends ChatDeliverer {
* *
* @param message The message to send. * @param message The message to send.
* @param senderRole the role of the user that is trying to send a public message. * @param senderRole the role of the user that is trying to send a public message.
* @throws UnauthorizedException Thrown if unauthorized
* @throws ForbiddenException If the user is not allowed to send a public message (i.e. does not * @throws ForbiddenException If the user is not allowed to send a public message (i.e. does not
* have voice in the room). * have voice in the room).
*/ */
public void sendPublicMessage(Message message, MUCRole senderRole) throws UnauthorizedException, public void sendPublicMessage(Message message, MUCRole senderRole) throws ForbiddenException;
ForbiddenException;
/** /**
* Sends a private message to a selected occupant. * Sends a private message to a selected occupant.
...@@ -461,54 +457,55 @@ public interface MUCRoom extends ChatDeliverer { ...@@ -461,54 +457,55 @@ public interface MUCRoom extends ChatDeliverer {
public IQAdminHandler getIQAdminHandler(); public IQAdminHandler getIQAdminHandler();
/** /**
* Returns an iterator over the current list of owners. The iterator contains the bareJID of the * Returns a collection with the current list of owners. The collection contains the bareJID of
* users with owner affiliation. * the users with owner affiliation.
* *
* @return an iterator over the current list of owners. * @return a collection with the current list of owners.
*/ */
public Iterator<String> getOwners(); public Collection<String> getOwners();
/** /**
* Returns an iterator over the current list of admins. The iterator contains the bareJID of the * Returns a collection with the current list of admins. The collection contains the bareJID of
* users with admin affiliation. * the users with admin affiliation.
* *
* @return an iterator over the current list of admins. * @return a collection with the current list of admins.
*/ */
public Iterator<String> getAdmins(); public Collection<String> getAdmins();
/** /**
* Returns an iterator over the current list of room members. The iterator contains the bareJID * Returns a collection with the current list of room members. The collection contains the
* of the users with member affiliation. If the room is not members-only then the list will * bareJID of the users with member affiliation. If the room is not members-only then the list
* contain the users that registered with the room and therefore they may have reserved a * will contain the users that registered with the room and therefore they may have reserved a
* nickname. * nickname.
* *
* @return an iterator over the current list of members. * @return a collection with the current list of members.
*/ */
public Iterator<String> getMembers(); public Collection<String> getMembers();
/** /**
* Returns an iterator over the current list of outcast users. An outcast user is not allowed to * Returns a collection with the current list of outcast users. An outcast user is not allowed
* join the room again. The iterator contains the bareJID of the users with outcast affiliation. * to join the room again. The collection contains the bareJID of the users with outcast
* affiliation.
* *
* @return an iterator over the current list of outcast users. * @return a collection with the current list of outcast users.
*/ */
public Iterator<String> getOutcasts(); public Collection<String> getOutcasts();
/** /**
* Returns an iterator over the current list of room moderators. The iterator contains the * Returns a collection with the current list of room moderators. The collection contains the
* MUCRole of the occupants with moderator role. * MUCRole of the occupants with moderator role.
* *
* @return an iterator over the current list of moderators. * @return a collection with the current list of moderators.
*/ */
public Iterator<MUCRole> getModerators(); public Collection<MUCRole> getModerators();
/** /**
* Returns an iterator over the current list of room participants. The iterator contains the * Returns a collection with the current list of room participants. The collection contains the
* MUCRole of the occupants with participant role. * MUCRole of the occupants with participant role.
* *
* @return an iterator over the current list of moderators. * @return a collection with the current list of moderators.
*/ */
public Iterator<MUCRole> getParticipants(); public Collection<MUCRole> getParticipants();
/** /**
* Returns true if every presence packet will include the JID of every occupant. This * Returns true if every presence packet will include the JID of every occupant. This
...@@ -746,7 +743,7 @@ public interface MUCRoom extends ChatDeliverer { ...@@ -746,7 +743,7 @@ public interface MUCRoom extends ChatDeliverer {
* *
* @return the list of roles of which presence will be broadcasted to the rest of the occupants. * @return the list of roles of which presence will be broadcasted to the rest of the occupants.
*/ */
public Iterator getRolesToBroadcastPresence(); public List<String> getRolesToBroadcastPresence();
/** /**
* Sets the list of roles of which presence will be broadcasted to the rest of the occupants. * Sets the list of roles of which presence will be broadcasted to the rest of the occupants.
...@@ -755,7 +752,7 @@ public interface MUCRoom extends ChatDeliverer { ...@@ -755,7 +752,7 @@ public interface MUCRoom extends ChatDeliverer {
* @param rolesToBroadcastPresence the list of roles of which presence will be broadcasted to * @param rolesToBroadcastPresence the list of roles of which presence will be broadcasted to
* the rest of the occupants. * the rest of the occupants.
*/ */
public void setRolesToBroadcastPresence(List rolesToBroadcastPresence); public void setRolesToBroadcastPresence(List<String> rolesToBroadcastPresence);
/** /**
* Returns true if the presences of the requested role will be broadcasted. * Returns true if the presences of the requested role will be broadcasted.
......
...@@ -163,7 +163,7 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -163,7 +163,7 @@ public class MUCRoomImpl implements MUCRoom {
* List of roles of which presence will be broadcasted to the rest of the occupants. This * List of roles of which presence will be broadcasted to the rest of the occupants. This
* feature is useful for implementing "invisible" occupants. * feature is useful for implementing "invisible" occupants.
*/ */
private List rolesToBroadcastPresence = new ArrayList(); private List<String> rolesToBroadcastPresence = new ArrayList<String>();
/** /**
* A public room means that the room is searchable and visible. This means that the room can be * A public room means that the room is searchable and visible. This means that the room can be
...@@ -345,8 +345,8 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -345,8 +345,8 @@ public class MUCRoomImpl implements MUCRoom {
throw new UserNotFoundException(); throw new UserNotFoundException();
} }
public Iterator<MUCRole> getOccupants() { public Collection<MUCRole> getOccupants() {
return occupants.values().iterator(); return Collections.unmodifiableCollection(occupants.values());
} }
public int getOccupantsCount() { public int getOccupantsCount() {
...@@ -696,8 +696,7 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -696,8 +696,7 @@ public class MUCRoomImpl implements MUCRoom {
broadcast(message); broadcast(message);
} }
public void sendPublicMessage(Message message, MUCRole senderRole) public void sendPublicMessage(Message message, MUCRole senderRole) throws ForbiddenException {
throws UnauthorizedException, ForbiddenException {
// Check that if the room is moderated then the sender of the message has to have voice // Check that if the room is moderated then the sender of the message has to have voice
if (isModerated() && senderRole.getRole() > MUCRole.PARTICIPANT) { if (isModerated() && senderRole.getRole() > MUCRole.PARTICIPANT) {
throw new ForbiddenException(); throw new ForbiddenException();
...@@ -1279,8 +1278,7 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1279,8 +1278,7 @@ public class MUCRoomImpl implements MUCRoom {
occupants.remove(oldNick.toLowerCase()); occupants.remove(oldNick.toLowerCase());
} }
public void changeSubject(Message packet, MUCRole role) throws UnauthorizedException, public void changeSubject(Message packet, MUCRole role) throws ForbiddenException {
ForbiddenException {
if ((canOccupantsChangeSubject() && role.getRole() < MUCRole.VISITOR) || if ((canOccupantsChangeSubject() && role.getRole() < MUCRole.VISITOR) ||
MUCRole.MODERATOR == role.getRole()) { MUCRole.MODERATOR == role.getRole()) {
// Do nothing if the new subject is the same as the existing one // Do nothing if the new subject is the same as the existing one
...@@ -1379,40 +1377,40 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1379,40 +1377,40 @@ public class MUCRoomImpl implements MUCRoom {
return iqAdminHandler; return iqAdminHandler;
} }
public Iterator<String> getOwners() { public Collection<String> getOwners() {
return Collections.unmodifiableList(owners).iterator(); return Collections.unmodifiableList(owners);
} }
public Iterator<String> getAdmins() { public Collection<String> getAdmins() {
return Collections.unmodifiableList(admins).iterator(); return Collections.unmodifiableList(admins);
} }
public Iterator<String> getMembers() { public Collection<String> getMembers() {
return Collections.unmodifiableMap(members).keySet().iterator(); return Collections.unmodifiableMap(members).keySet();
} }
public Iterator<String> getOutcasts() { public Collection<String> getOutcasts() {
return Collections.unmodifiableList(outcasts).iterator(); return Collections.unmodifiableList(outcasts);
} }
public Iterator<MUCRole> getModerators() { public Collection<MUCRole> getModerators() {
List<MUCRole> moderators = new ArrayList<MUCRole>(); List<MUCRole> moderators = new ArrayList<MUCRole>();
for (MUCRole role : occupants.values()) { for (MUCRole role : occupants.values()) {
if (MUCRole.MODERATOR == role.getRole()) { if (MUCRole.MODERATOR == role.getRole()) {
moderators.add(role); moderators.add(role);
} }
} }
return moderators.iterator(); return moderators;
} }
public Iterator<MUCRole> getParticipants() { public Collection<MUCRole> getParticipants() {
List<MUCRole> participants = new ArrayList<MUCRole>(); List<MUCRole> participants = new ArrayList<MUCRole>();
for (MUCRole role : occupants.values()) { for (MUCRole role : occupants.values()) {
if (MUCRole.PARTICIPANT == role.getRole()) { if (MUCRole.PARTICIPANT == role.getRole()) {
participants.add(role); participants.add(role);
} }
} }
return participants.iterator(); return participants;
} }
public Presence addModerator(String fullJID, MUCRole senderRole) throws ForbiddenException { public Presence addModerator(String fullJID, MUCRole senderRole) throws ForbiddenException {
...@@ -1645,11 +1643,11 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1645,11 +1643,11 @@ public class MUCRoomImpl implements MUCRoom {
this.publicRoom = publicRoom; this.publicRoom = publicRoom;
} }
public Iterator getRolesToBroadcastPresence() { public List<String> getRolesToBroadcastPresence() {
return rolesToBroadcastPresence.iterator(); return Collections.unmodifiableList(rolesToBroadcastPresence);
} }
public void setRolesToBroadcastPresence(List rolesToBroadcastPresence) { public void setRolesToBroadcastPresence(List<String> rolesToBroadcastPresence) {
// TODO If the list changes while there are occupants in the room we must send available or // TODO If the list changes while there are occupants in the room we must send available or
// unavailable presences of the affected occupants to the rest of the occupants // unavailable presences of the affected occupants to the rest of the occupants
this.rolesToBroadcastPresence = rolesToBroadcastPresence; this.rolesToBroadcastPresence = rolesToBroadcastPresence;
...@@ -1672,6 +1670,7 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1672,6 +1670,7 @@ public class MUCRoomImpl implements MUCRoom {
public void unlockRoom(MUCRole senderRole) { public void unlockRoom(MUCRole senderRole) {
roomLocked = false; roomLocked = false;
this.lockedTime = 0; this.lockedTime = 0;
if (senderRole.getChatUser() != null) {
// Send to the occupant that unlocked the room a message saying so // Send to the occupant that unlocked the room a message saying so
Message message = new MessageImpl(); Message message = new MessageImpl();
message.setType(Message.GROUP_CHAT); message.setType(Message.GROUP_CHAT);
...@@ -1680,6 +1679,7 @@ public class MUCRoomImpl implements MUCRoom { ...@@ -1680,6 +1679,7 @@ public class MUCRoomImpl implements MUCRoom {
message.setRecipient(senderRole.getChatUser().getAddress()); message.setRecipient(senderRole.getChatUser().getAddress());
router.route(message); router.route(message);
} }
}
public List<Presence> addAdmins(List<String> newAdmins, MUCRole senderRole) public List<Presence> addAdmins(List<String> newAdmins, MUCRole senderRole)
throws ForbiddenException, ConflictException { throws ForbiddenException, ConflictException {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment