Commit cb0f7b56 authored by guus's avatar guus

OF-523: Apply defensive coding to the MUC implementation (mainly: use JIDs,...

OF-523: Apply defensive coding to the MUC implementation (mainly: use JIDs, not Strings - but includes some other fixes as well).

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@12978 b35dd754-fafc-0310-a699-88a17e54d16e
parent 4b8cb088
...@@ -108,8 +108,8 @@ public class ClearspaceMUCEventDelegate extends MUCEventDelegate { ...@@ -108,8 +108,8 @@ public class ClearspaceMUCEventDelegate extends MUCEventDelegate {
public boolean joiningRoom(MUCRoom room, JID userjid) { public boolean joiningRoom(MUCRoom room, JID userjid) {
// Always allow an owner to join the room (especially since they need to join to configure the // Always allow an owner to join the room (especially since they need to join to configure the
// room on initial creation). // room on initial creation).
Collection<String> owners = room.getOwners(); Collection<JID> owners = room.getOwners();
if (owners != null && owners.contains(userjid.toBareJID())) { if (owners != null && owners.contains(new JID(userjid.toBareJID()))) {
return true; return true;
} }
...@@ -186,9 +186,11 @@ public class ClearspaceMUCEventDelegate extends MUCEventDelegate { ...@@ -186,9 +186,11 @@ public class ClearspaceMUCEventDelegate extends MUCEventDelegate {
Log.warn(GET_ROOM_CONFIG_WARNING + " Room: " + roomJid.toBareJID()); Log.warn(GET_ROOM_CONFIG_WARNING + " Room: " + roomJid.toBareJID());
return null; return null;
} }
Iterator fields = xElement.elementIterator("field");
@SuppressWarnings("unchecked")
Iterator<Element> fields = xElement.elementIterator("field");
while (fields.hasNext()) { while (fields.hasNext()) {
Element field = (Element) fields.next(); Element field = fields.next();
Attribute varAttribute = field.attribute("var"); Attribute varAttribute = field.attribute("var");
if (varAttribute != null) { if (varAttribute != null) {
Element value = field.element("value"); Element value = field.element("value");
......
...@@ -186,7 +186,7 @@ public class ClearspaceMUCTranscriptManager implements MUCEventListener { ...@@ -186,7 +186,7 @@ public class ClearspaceMUCTranscriptManager implements MUCEventListener {
MUCRoom room = mucService.getChatRoom(jid.getNode()); MUCRoom room = mucService.getChatRoom(jid.getNode());
// Not count room owners as occupants // Not count room owners as occupants
int totalOccupants = room.getOccupantsCount(); int totalOccupants = room.getOccupantsCount();
for (String owner : room.getOwners()) { for (JID owner : room.getOwners()) {
try { try {
if (!room.getOccupantsByBareJID(owner).isEmpty()) { if (!room.getOccupantsByBareJID(owner).isEmpty()) {
totalOccupants--; totalOccupants--;
......
...@@ -149,9 +149,9 @@ public class HistoryRequest { ...@@ -149,9 +149,9 @@ public class HistoryRequest {
*/ */
public void sendHistory(LocalMUCRole joinRole, MUCRoomHistory roomHistory) { public void sendHistory(LocalMUCRole joinRole, MUCRoomHistory roomHistory) {
if (!isConfigured()) { if (!isConfigured()) {
Iterator history = roomHistory.getMessageHistory(); Iterator<Message> history = roomHistory.getMessageHistory();
while (history.hasNext()) { while (history.hasNext()) {
joinRole.send((Message) history.next()); joinRole.send(history.next());
} }
} }
else { else {
...@@ -164,14 +164,13 @@ public class HistoryRequest { ...@@ -164,14 +164,13 @@ public class HistoryRequest {
} }
return; return;
} }
Message message;
int accumulatedChars = 0; int accumulatedChars = 0;
int accumulatedStanzas = 0; int accumulatedStanzas = 0;
Element delayInformation; Element delayInformation;
LinkedList<Message> historyToSend = new LinkedList<Message>(); LinkedList<Message> historyToSend = new LinkedList<Message>();
ListIterator iterator = roomHistory.getReverseMessageHistory(); ListIterator<Message> iterator = roomHistory.getReverseMessageHistory();
while (iterator.hasPrevious()) { while (iterator.hasPrevious()) {
message = (Message)iterator.previous(); Message message = iterator.previous();
// Update number of characters to send // Update number of characters to send
String text = message.getBody() == null ? message.getSubject() : message.getBody(); String text = message.getBody() == null ? message.getSubject() : message.getBody();
if (text == null) { if (text == null) {
......
...@@ -205,7 +205,7 @@ public class HistoryStrategy { ...@@ -205,7 +205,7 @@ public class HistoryStrategy {
// last room subject // last room subject
// message because we want to preserve the room subject if // message because we want to preserve the room subject if
// possible. // possible.
Iterator historyIter = history.iterator(); Iterator<Message> historyIter = history.iterator();
while (historyIter.hasNext() && history.size() > strategyMaxNumber) { while (historyIter.hasNext() && history.size() > strategyMaxNumber) {
if (historyIter.next() != roomSubject) { if (historyIter.next() != roomSubject) {
historyIter.remove(); historyIter.remove();
......
...@@ -111,9 +111,15 @@ public abstract class MUCEventDelegate { ...@@ -111,9 +111,15 @@ public abstract class MUCEventDelegate {
room.setChangeNickname("1".equals(roomConfig.get("x-muc#roomconfig_canchangenick"))); room.setChangeNickname("1".equals(roomConfig.get("x-muc#roomconfig_canchangenick")));
room.setRegistrationEnabled("1".equals(roomConfig.get("x-muc#roomconfig_registration"))); room.setRegistrationEnabled("1".equals(roomConfig.get("x-muc#roomconfig_registration")));
room.setPersistent("1".equals(roomConfig.get("muc#roomconfig_persistentroom"))); room.setPersistent("1".equals(roomConfig.get("muc#roomconfig_persistentroom")));
room.addFirstOwner(roomConfig.get("muc#roomconfig_roomowners")); final String property = roomConfig.get("muc#roomconfig_roomowners");
if (property != null) {
String jids[] = property.split(",");
for (String jid : jids) {
room.addFirstOwner(new JID(new JID(jid.trim().toLowerCase()).toBareJID()));
}
}
try { try {
room.unlock(room.getRole()); room.unlock(room.getRole());
} catch (ForbiddenException e) { } catch (ForbiddenException e) {
......
...@@ -170,7 +170,7 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -170,7 +170,7 @@ public interface MUCRoom extends Externalizable, Result {
* @return The user's roles in the room * @return The user's roles in the room
* @throws UserNotFoundException If there is no user with the given nickname * @throws UserNotFoundException If there is no user with the given nickname
*/ */
List<MUCRole> getOccupantsByBareJID(String jid) throws UserNotFoundException; List<MUCRole> getOccupantsByBareJID(JID jid) throws UserNotFoundException;
/** /**
* Returns the role of a given user in the room by his full JID or <tt>null</tt> * Returns the role of a given user in the room by his full JID or <tt>null</tt>
...@@ -209,7 +209,7 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -209,7 +209,7 @@ public interface MUCRoom extends Externalizable, Result {
* @param bareJID The bare jid of the user of which you'd like to obtain his reserved nickname. * @param bareJID The bare jid of the user of which you'd like to obtain his reserved nickname.
* @return the reserved room nickname for the bare JID or null if none. * @return the reserved room nickname for the bare JID or null if none.
*/ */
String getReservedNickname(String bareJID); String getReservedNickname(JID jid);
/** /**
* Returns the affiliation state of the user in the room. Possible affiliations are * Returns the affiliation state of the user in the room. Possible affiliations are
...@@ -220,7 +220,7 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -220,7 +220,7 @@ public interface MUCRoom extends Externalizable, Result {
* @param bareJID The bare jid of the user of which you'd like to obtain his affiliation. * @param bareJID The bare jid of the user of which you'd like to obtain his affiliation.
* @return the affiliation state of the user in the room. * @return the affiliation state of the user in the room.
*/ */
MUCRole.Affiliation getAffiliation(String bareJID); MUCRole.Affiliation getAffiliation(JID bareJID);
/** /**
* Joins the room using the given nickname. * Joins the room using the given nickname.
...@@ -263,7 +263,7 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -263,7 +263,7 @@ public interface MUCRoom extends Externalizable, Result {
* @param alternateJID the alternate JID. Commonly used to provide a replacement room. * @param alternateJID the alternate JID. Commonly used to provide a replacement room.
* @param reason the reason why the room was destroyed. * @param reason the reason why the room was destroyed.
*/ */
void destroyRoom(String alternateJID, String reason); void destroyRoom(JID alternateJID, String reason);
/** /**
* Create a new presence in this room for the given role. * Create a new presence in this room for the given role.
...@@ -296,20 +296,7 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -296,20 +296,7 @@ public interface MUCRoom extends Externalizable, Result {
* *
* @param bareJID The bare JID of the user to add as owner. * @param bareJID The bare JID of the user to add as owner.
*/ */
public void addFirstOwner(String bareJID); public void addFirstOwner(JID bareJID);
/**
* Adds a new user to the list of owners.
*
* @param bareJID The bare JID of the user to add as owner.
* @param senderRole the role of the user that is trying to modify the owners list.
* @return the list of updated presences of all the client resources that the client used to
* join the room.
* @throws ForbiddenException If the user is not allowed to modify the owner list.
* @deprecated Replaced by {@link #addOwner(JID, MUCRole)}
*/
@Deprecated
public List<Presence> addOwner(String bareJID, MUCRole senderRole) throws ForbiddenException;
/** /**
* Adds a new user to the list of owners. * Adds a new user to the list of owners.
...@@ -331,7 +318,7 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -331,7 +318,7 @@ public interface MUCRoom extends Externalizable, Result {
* join the room. * join the room.
* @throws ForbiddenException If the user is not allowed to modify the owner list. * @throws ForbiddenException If the user is not allowed to modify the owner list.
*/ */
public List<Presence> addOwners(List<String> newOwners, MUCRole senderRole) public List<Presence> addOwners(List<JID> newOwners, MUCRole senderRole)
throws ForbiddenException; throws ForbiddenException;
/** /**
...@@ -344,24 +331,9 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -344,24 +331,9 @@ public interface MUCRoom extends Externalizable, Result {
* @throws ForbiddenException If the user is not allowed to modify the admin list. * @throws ForbiddenException If the user is not allowed to modify the admin list.
* @throws ConflictException If the room was going to lose all its owners. * @throws ConflictException If the room was going to lose all its owners.
*/ */
public List<Presence> addAdmins(List<String> newAdmins, MUCRole senderRole) public List<Presence> addAdmins(List<JID> newAdmins, MUCRole senderRole)
throws ForbiddenException, ConflictException; throws ForbiddenException, ConflictException;
/**
* Adds a new user to the list of admins.
*
* @param bareJID The bare JID of the user to add as admin.
* @param senderRole The role of the user that is trying to modify the admins list.
* @return the list of updated presences of all the client resources that the client used to
* join the room.
* @throws ForbiddenException If the user is not allowed to modify the admin list.
* @throws ConflictException If the room was going to lose all its owners.
* @deprecated Replaced by {@link #addAdmin(JID, MUCRole)}
*/
@Deprecated
public List<Presence> addAdmin(String bareJID, MUCRole senderRole) throws ForbiddenException,
ConflictException;
/** /**
* Adds a new user to the list of admins. * Adds a new user to the list of admins.
* *
...@@ -375,23 +347,6 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -375,23 +347,6 @@ public interface MUCRoom extends Externalizable, Result {
public List<Presence> addAdmin(JID jid, MUCRole senderRole) throws ForbiddenException, public List<Presence> addAdmin(JID jid, MUCRole senderRole) throws ForbiddenException,
ConflictException; ConflictException;
/**
* Adds a new user to the list of members.
*
* @param bareJID The bare JID of the user to add as a member.
* @param nickname The reserved nickname of the member for the room or null if none.
* @param senderRole the role of the user that is trying to modify the members list.
* @return the list of updated presences of all the client resources that the client used to
* join the room.
* @throws ForbiddenException If the user is not allowed to modify the members list.
* @throws ConflictException If the desired room nickname is already reserved for the room or if
* the room was going to lose all its owners.
* @deprecated Replaced by {@link #addMember(JID, String, MUCRole)}
*/
@Deprecated
public List<Presence> addMember(String bareJID, String nickname, MUCRole senderRole)
throws ForbiddenException, ConflictException;
/** /**
* Adds a new user to the list of members. * Adds a new user to the list of members.
* *
...@@ -407,23 +362,6 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -407,23 +362,6 @@ public interface MUCRoom extends Externalizable, Result {
public List<Presence> addMember(JID jid, String nickname, MUCRole senderRole) public List<Presence> addMember(JID jid, String nickname, MUCRole senderRole)
throws ForbiddenException, ConflictException; throws ForbiddenException, ConflictException;
/**
* Adds a new user to the list of outcast users.
*
* @param bareJID The bare JID of the user to add as an outcast.
* @param reason The reason why the user was banned.
* @param senderRole The role of the user that initiated the ban.
* @return the list of updated presences of all the client resources that the client used to
* join the room.
* @throws NotAllowedException Thrown if trying to ban an owner or an administrator.
* @throws ForbiddenException If the user is not allowed to modify the outcast list.
* @throws ConflictException If the room was going to lose all its owners.
* @deprecated Replaced by {@link #addOutcast(JID, String, MUCRole)}
*/
@Deprecated
public List<Presence> addOutcast(String bareJID, String reason, MUCRole senderRole)
throws NotAllowedException, ForbiddenException, ConflictException;
/** /**
* Adds a new user to the list of outcast users. * Adds a new user to the list of outcast users.
* *
...@@ -439,21 +377,6 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -439,21 +377,6 @@ public interface MUCRoom extends Externalizable, Result {
public List<Presence> addOutcast(JID jid, String reason, MUCRole senderRole) public List<Presence> addOutcast(JID jid, String reason, MUCRole senderRole)
throws NotAllowedException, ForbiddenException, ConflictException; throws NotAllowedException, ForbiddenException, ConflictException;
/**
* Removes the user from all the other affiliation list thus giving the user a NONE affiliation.
*
* @param bareJID The bare JID of the user to keep with a NONE affiliation.
* @param senderRole The role of the user that set the affiliation to none.
* @return the list of updated presences of all the client resources that the client used to
* join the room or null if none was updated.
* @throws ForbiddenException If the user is not allowed to modify the none list.
* @throws ConflictException If the room was going to lose all its owners.
* @deprecated Replaced by {@link #addNone(JID, MUCRole)}
*/
@Deprecated
public List<Presence> addNone(String bareJID, MUCRole senderRole) throws ForbiddenException,
ConflictException;
/** /**
* Removes the user from all the other affiliation list thus giving the user a NONE affiliation. * Removes the user from all the other affiliation list thus giving the user a NONE affiliation.
* *
...@@ -627,7 +550,7 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -627,7 +550,7 @@ public interface MUCRoom extends Externalizable, Result {
* *
* @return a collection with the current list of owners. * @return a collection with the current list of owners.
*/ */
public Collection<String> getOwners(); public Collection<JID> getOwners();
/** /**
* Returns a collection with the current list of admins. The collection contains the bareJID of * Returns a collection with the current list of admins. The collection contains the bareJID of
...@@ -635,7 +558,7 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -635,7 +558,7 @@ public interface MUCRoom extends Externalizable, Result {
* *
* @return a collection with the current list of admins. * @return a collection with the current list of admins.
*/ */
public Collection<String> getAdmins(); public Collection<JID> getAdmins();
/** /**
* Returns a collection with the current list of room members. The collection contains the * Returns a collection with the current list of room members. The collection contains the
...@@ -645,7 +568,7 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -645,7 +568,7 @@ public interface MUCRoom extends Externalizable, Result {
* *
* @return a collection with the current list of members. * @return a collection with the current list of members.
*/ */
public Collection<String> getMembers(); public Collection<JID> getMembers();
/** /**
* Returns a collection with the current list of outcast users. An outcast user is not allowed * Returns a collection with the current list of outcast users. An outcast user is not allowed
...@@ -654,7 +577,7 @@ public interface MUCRoom extends Externalizable, Result { ...@@ -654,7 +577,7 @@ public interface MUCRoom extends Externalizable, Result {
* *
* @return a collection with the current list of outcast users. * @return a collection with the current list of outcast users.
*/ */
public Collection<String> getOutcasts(); public Collection<JID> getOutcasts();
/** /**
* Returns a collection with the current list of room moderators. The collection contains the * Returns a collection with the current list of room moderators. The collection contains the
......
...@@ -84,12 +84,10 @@ public final class MUCRoomHistory { ...@@ -84,12 +84,10 @@ public final class MUCRoomHistory {
if (isNonAnonymousRoom != room.canAnyoneDiscoverJID()) { if (isNonAnonymousRoom != room.canAnyoneDiscoverJID()) {
isNonAnonymousRoom = room.canAnyoneDiscoverJID(); isNonAnonymousRoom = room.canAnyoneDiscoverJID();
// Update the "from" attribute of the delay information in the history // Update the "from" attribute of the delay information in the history
Message message;
Element delayElement;
// TODO Make this update in a separate thread // TODO Make this update in a separate thread
for (Iterator it = getMessageHistory(); it.hasNext();) { for (Iterator<Message> it = getMessageHistory(); it.hasNext();) {
message = (Message) it.next(); Message message = it.next();
delayElement = message.getChildElement("x", "jabber:x:delay"); Element delayElement = message.getChildElement("x", "jabber:x:delay");
if (room.canAnyoneDiscoverJID()) { if (room.canAnyoneDiscoverJID()) {
// Set the Full JID as the "from" attribute // Set the Full JID as the "from" attribute
try { try {
...@@ -133,7 +131,7 @@ public final class MUCRoomHistory { ...@@ -133,7 +131,7 @@ public final class MUCRoomHistory {
historyStrategy.addMessage(packetToAdd); historyStrategy.addMessage(packetToAdd);
} }
public Iterator getMessageHistory() { public Iterator<Message> getMessageHistory() {
return historyStrategy.getMessageHistory(); return historyStrategy.getMessageHistory();
} }
...@@ -144,7 +142,7 @@ public final class MUCRoomHistory { ...@@ -144,7 +142,7 @@ public final class MUCRoomHistory {
* *
* @return A list iterator of Message objects positioned at the end of the list. * @return A list iterator of Message objects positioned at the end of the list.
*/ */
public ListIterator getReverseMessageHistory() { public ListIterator<Message> getReverseMessageHistory() {
return historyStrategy.getReverseMessageHistory(); return historyStrategy.getReverseMessageHistory();
} }
......
...@@ -22,6 +22,7 @@ package org.jivesoftware.openfire.muc; ...@@ -22,6 +22,7 @@ package org.jivesoftware.openfire.muc;
import org.jivesoftware.openfire.ChannelHandler; import org.jivesoftware.openfire.ChannelHandler;
import org.xmpp.packet.JID; import org.xmpp.packet.JID;
import org.xmpp.packet.Packet;
/** /**
* The chat user is a separate user abstraction for interacting with * The chat user is a separate user abstraction for interacting with
...@@ -36,7 +37,7 @@ import org.xmpp.packet.JID; ...@@ -36,7 +37,7 @@ import org.xmpp.packet.JID;
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public interface MUCUser extends ChannelHandler { public interface MUCUser extends ChannelHandler<Packet> {
/** /**
* Obtain the address of the user. The address is used by services like the core * Obtain the address of the user. The address is used by services like the core
......
...@@ -62,7 +62,7 @@ public interface MultiUserChatService extends Component { ...@@ -62,7 +62,7 @@ public interface MultiUserChatService extends Component {
* *
* @return a list of bare JIDs. * @return a list of bare JIDs.
*/ */
Collection<String> getSysadmins(); Collection<JID> getSysadmins();
/** /**
* Adds a new system administrator of the MUC service. A sysadmin has the same permissions as * Adds a new system administrator of the MUC service. A sysadmin has the same permissions as
...@@ -70,14 +70,14 @@ public interface MultiUserChatService extends Component { ...@@ -70,14 +70,14 @@ public interface MultiUserChatService extends Component {
* *
* @param userJID the bare JID of the new user to add as a system administrator. * @param userJID the bare JID of the new user to add as a system administrator.
*/ */
void addSysadmin(String userJID); void addSysadmin(JID userJID);
/** /**
* Removes a system administrator of the MUC service. * Removes a system administrator of the MUC service.
* *
* @param userJID the bare JID of the user to remove from the list. * @param userJID the bare JID of the user to remove from the list.
*/ */
void removeSysadmin(String userJID); void removeSysadmin(JID userJID);
/** /**
* Returns false if anyone can create rooms or true if only the returned JIDs in * Returns false if anyone can create rooms or true if only the returned JIDs in
...@@ -101,21 +101,21 @@ public interface MultiUserChatService extends Component { ...@@ -101,21 +101,21 @@ public interface MultiUserChatService extends Component {
* *
* @return a list of bare JIDs. * @return a list of bare JIDs.
*/ */
Collection<String> getUsersAllowedToCreate(); Collection<JID> getUsersAllowedToCreate();
/** /**
* Adds a new user to the list of JIDs that are allowed to create MUC rooms. * Adds a new user to the list of JIDs that are allowed to create MUC rooms.
* *
* @param userJID the bare JID of the new user to add to list. * @param userJID the bare JID of the new user to add to list.
*/ */
void addUserAllowedToCreate(String userJID); void addUserAllowedToCreate(JID userJID);
/** /**
* Removes a user from list of JIDs that are allowed to create MUC rooms. * Removes a user from list of JIDs that are allowed to create MUC rooms.
* *
* @param userJID the bare JID of the user to remove from the list. * @param userJID the bare JID of the user to remove from the list.
*/ */
void removeUserAllowedToCreate(String userJID); void removeUserAllowedToCreate(JID userJID);
/** /**
* Sets the time to elapse between clearing of idle chat users. A <code>TimerTask</code> will be * Sets the time to elapse between clearing of idle chat users. A <code>TimerTask</code> will be
......
...@@ -20,33 +20,40 @@ ...@@ -20,33 +20,40 @@
package org.jivesoftware.openfire.muc.cluster; package org.jivesoftware.openfire.muc.cluster;
import org.jivesoftware.openfire.muc.spi.LocalMUCRoom;
import org.jivesoftware.util.cache.ExternalizableUtil;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInput; import java.io.ObjectInput;
import java.io.ObjectOutput; import java.io.ObjectOutput;
import org.jivesoftware.openfire.muc.spi.LocalMUCRoom;
import org.jivesoftware.util.cache.ExternalizableUtil;
import org.xmpp.packet.JID;
/** /**
* Task that adds a new member to the room in the other cluster nodes. * Task that adds a new member to the room in the other cluster nodes.
* *
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class AddMember extends MUCRoomTask { public class AddMember extends MUCRoomTask {
private String bareJID; private JID bareJID;
private String nickname; private String nickname;
public AddMember() { public AddMember() {
super(); super();
} }
public AddMember(LocalMUCRoom room, JID bareJID, String nickname) {
super(room);
this.bareJID = new JID(bareJID.toBareJID());
this.nickname = nickname;
}
public AddMember(LocalMUCRoom room, String bareJID, String nickname) { public AddMember(LocalMUCRoom room, String bareJID, String nickname) {
super(room); super(room);
this.bareJID = bareJID; this.bareJID = new JID(new JID(bareJID).toBareJID());
this.nickname = nickname; this.nickname = nickname;
} }
public String getBareJID() { public JID getBareJID() {
return bareJID; return bareJID;
} }
...@@ -70,14 +77,14 @@ public class AddMember extends MUCRoomTask { ...@@ -70,14 +77,14 @@ public class AddMember extends MUCRoomTask {
@Override @Override
public void writeExternal(ObjectOutput out) throws IOException { public void writeExternal(ObjectOutput out) throws IOException {
super.writeExternal(out); super.writeExternal(out);
ExternalizableUtil.getInstance().writeSafeUTF(out, bareJID); ExternalizableUtil.getInstance().writeSafeUTF(out, bareJID.toFullJID());
ExternalizableUtil.getInstance().writeSafeUTF(out, nickname); ExternalizableUtil.getInstance().writeSafeUTF(out, nickname);
} }
@Override @Override
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
super.readExternal(in); super.readExternal(in);
bareJID = ExternalizableUtil.getInstance().readSafeUTF(in); bareJID = new JID(ExternalizableUtil.getInstance().readSafeUTF(in));
nickname = ExternalizableUtil.getInstance().readSafeUTF(in); nickname = ExternalizableUtil.getInstance().readSafeUTF(in);
} }
} }
...@@ -20,13 +20,14 @@ ...@@ -20,13 +20,14 @@
package org.jivesoftware.openfire.muc.cluster; package org.jivesoftware.openfire.muc.cluster;
import org.jivesoftware.openfire.muc.spi.LocalMUCRoom;
import org.jivesoftware.util.cache.ExternalizableUtil;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInput; import java.io.ObjectInput;
import java.io.ObjectOutput; import java.io.ObjectOutput;
import org.jivesoftware.openfire.muc.spi.LocalMUCRoom;
import org.jivesoftware.util.cache.ExternalizableUtil;
import org.xmpp.packet.JID;
/** /**
* Task that destroys the local room in the cluster node. Local room occupants * Task that destroys the local room in the cluster node. Local room occupants
* hosted in the cluster node will get the notification of the room being * hosted in the cluster node will get the notification of the room being
...@@ -35,18 +36,24 @@ import java.io.ObjectOutput; ...@@ -35,18 +36,24 @@ import java.io.ObjectOutput;
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
public class DestroyRoomRequest extends MUCRoomTask { public class DestroyRoomRequest extends MUCRoomTask {
private String alternateJID; private JID alternateJID;
private String reason; private String reason;
public DestroyRoomRequest() { public DestroyRoomRequest() {
} }
public DestroyRoomRequest(LocalMUCRoom room, String alternateJID, String reason) { public DestroyRoomRequest(LocalMUCRoom room, JID alternateJID, String reason) {
super(room); super(room);
this.alternateJID = alternateJID; this.alternateJID = alternateJID;
this.reason = reason; this.reason = reason;
} }
public DestroyRoomRequest(LocalMUCRoom room, String alternateJID, String reason) {
super(room);
this.alternateJID = new JID(alternateJID);
this.reason = reason;
}
public Object getResult() { public Object getResult() {
return null; return null;
} }
...@@ -60,7 +67,7 @@ public class DestroyRoomRequest extends MUCRoomTask { ...@@ -60,7 +67,7 @@ public class DestroyRoomRequest extends MUCRoomTask {
}); });
} }
public String getAlternateJID() { public JID getAlternateJID() {
return alternateJID; return alternateJID;
} }
...@@ -73,7 +80,7 @@ public class DestroyRoomRequest extends MUCRoomTask { ...@@ -73,7 +80,7 @@ public class DestroyRoomRequest extends MUCRoomTask {
super.writeExternal(out); super.writeExternal(out);
ExternalizableUtil.getInstance().writeBoolean(out, alternateJID != null); ExternalizableUtil.getInstance().writeBoolean(out, alternateJID != null);
if (alternateJID != null) { if (alternateJID != null) {
ExternalizableUtil.getInstance().writeSafeUTF(out, alternateJID); ExternalizableUtil.getInstance().writeSafeUTF(out, alternateJID.toFullJID());
} }
ExternalizableUtil.getInstance().writeBoolean(out, reason != null); ExternalizableUtil.getInstance().writeBoolean(out, reason != null);
if (reason != null) { if (reason != null) {
...@@ -85,7 +92,7 @@ public class DestroyRoomRequest extends MUCRoomTask { ...@@ -85,7 +92,7 @@ public class DestroyRoomRequest extends MUCRoomTask {
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
super.readExternal(in); super.readExternal(in);
if (ExternalizableUtil.getInstance().readBoolean(in)) { if (ExternalizableUtil.getInstance().readBoolean(in)) {
alternateJID = ExternalizableUtil.getInstance().readSafeUTF(in); alternateJID = new JID(ExternalizableUtil.getInstance().readSafeUTF(in));
} }
if (ExternalizableUtil.getInstance().readBoolean(in)) { if (ExternalizableUtil.getInstance().readBoolean(in)) {
reason = ExternalizableUtil.getInstance().readSafeUTF(in); reason = ExternalizableUtil.getInstance().readSafeUTF(in);
......
...@@ -30,21 +30,23 @@ import org.xmpp.packet.JID; ...@@ -30,21 +30,23 @@ import org.xmpp.packet.JID;
* Represents an entry in the conversation log of a room. An entry basically obtains the necessary * Represents an entry in the conversation log of a room. An entry basically obtains the necessary
* information to log from the message adding a timestamp of when the message was sent to the room. * information to log from the message adding a timestamp of when the message was sent to the room.
* *
* Instances of this class are immutable, and therefor thread safe.
*
* @author Gaston Dombiak * @author Gaston Dombiak
*/ */
class ConversationLogEntry { class ConversationLogEntry {
private Date date; private final Date date;
private String subject; private final String subject;
private String body; private final String body;
private JID sender; private final JID sender;
private String nickname; private final String nickname;
private long roomID; private final long roomID;
/** /**
* Creates a new ConversationLogEntry that registers that a given message was sent to a given * Creates a new ConversationLogEntry that registers that a given message was sent to a given
......
...@@ -47,11 +47,11 @@ import org.xmpp.packet.Presence; ...@@ -47,11 +47,11 @@ import org.xmpp.packet.Presence;
*/ */
public class IQAdminHandler { public class IQAdminHandler {
private LocalMUCRoom room; private final LocalMUCRoom room;
private PacketRouter router; private final PacketRouter router;
private boolean skipInvite; private final boolean skipInvite;
public IQAdminHandler(LocalMUCRoom chatroom, PacketRouter packetRouter) { public IQAdminHandler(LocalMUCRoom chatroom, PacketRouter packetRouter) {
this.room = chatroom; this.room = chatroom;
...@@ -89,7 +89,9 @@ public class IQAdminHandler { ...@@ -89,7 +89,9 @@ public class IQAdminHandler {
Element element = packet.getChildElement(); Element element = packet.getChildElement();
// Analyze the action to perform based on the included element // Analyze the action to perform based on the included element
List itemsList = element.elements("item"); @SuppressWarnings("unchecked")
List<Element> itemsList = element.elements("item");
if (!itemsList.isEmpty()) { if (!itemsList.isEmpty()) {
handleItemsElement(role, itemsList, reply); handleItemsElement(role, itemsList, reply);
} }
...@@ -122,13 +124,13 @@ public class IQAdminHandler { ...@@ -122,13 +124,13 @@ public class IQAdminHandler {
* @throws NotAllowedException Thrown if trying to ban an owner or an administrator. * @throws NotAllowedException Thrown if trying to ban an owner or an administrator.
* @throws CannotBeInvitedException If the user being invited as a result of being added to a members-only room still does not have permission * @throws CannotBeInvitedException If the user being invited as a result of being added to a members-only room still does not have permission
*/ */
private void handleItemsElement(MUCRole senderRole, List itemsList, IQ reply) private void handleItemsElement(MUCRole senderRole, List<Element> itemsList, IQ reply)
throws ForbiddenException, ConflictException, NotAllowedException, CannotBeInvitedException { throws ForbiddenException, ConflictException, NotAllowedException, CannotBeInvitedException {
Element item; Element item;
String affiliation; String affiliation;
String roleAttribute; String roleAttribute;
boolean hasJID = ((Element)itemsList.get(0)).attributeValue("jid") != null; boolean hasJID = itemsList.get(0).attributeValue("jid") != null;
boolean hasNick = ((Element)itemsList.get(0)).attributeValue("nick") != null; boolean hasNick = itemsList.get(0).attributeValue("nick") != null;
// Check if the client is requesting or changing the list of moderators/members/etc. // Check if the client is requesting or changing the list of moderators/members/etc.
if (!hasJID && !hasNick) { if (!hasJID && !hasNick) {
// The client is requesting the list of moderators/members/participants/outcasts // The client is requesting the list of moderators/members/participants/outcasts
...@@ -147,10 +149,10 @@ public class IQAdminHandler { ...@@ -147,10 +149,10 @@ public class IQAdminHandler {
&& MUCRole.Affiliation.owner != senderRole.getAffiliation()) { && MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
throw new ForbiddenException(); throw new ForbiddenException();
} }
for (String jid : room.getOutcasts()) { for (JID jid : room.getOutcasts()) {
metaData = result.addElement("item", "http://jabber.org/protocol/muc#admin"); metaData = result.addElement("item", "http://jabber.org/protocol/muc#admin");
metaData.addAttribute("affiliation", "outcast"); metaData.addAttribute("affiliation", "outcast");
metaData.addAttribute("jid", jid); metaData.addAttribute("jid", jid.toString());
} }
} else if ("member".equals(affiliation)) { } else if ("member".equals(affiliation)) {
...@@ -161,10 +163,10 @@ public class IQAdminHandler { ...@@ -161,10 +163,10 @@ public class IQAdminHandler {
&& MUCRole.Affiliation.owner != senderRole.getAffiliation()) { && MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
throw new ForbiddenException(); throw new ForbiddenException();
} }
for (String jid : room.getMembers()) { for (JID jid : room.getMembers()) {
metaData = result.addElement("item", "http://jabber.org/protocol/muc#admin"); metaData = result.addElement("item", "http://jabber.org/protocol/muc#admin");
metaData.addAttribute("affiliation", "member"); metaData.addAttribute("affiliation", "member");
metaData.addAttribute("jid", jid); metaData.addAttribute("jid", jid.toString());
try { try {
List<MUCRole> roles = room.getOccupantsByBareJID(jid); List<MUCRole> roles = room.getOccupantsByBareJID(jid);
MUCRole role = roles.get(0); MUCRole role = roles.get(0);
...@@ -210,7 +212,7 @@ public class IQAdminHandler { ...@@ -210,7 +212,7 @@ public class IQAdminHandler {
JID jid; JID jid;
String nick; String nick;
String target; String target;
boolean hasAffiliation = ((Element) itemsList.get(0)).attributeValue("affiliation") != boolean hasAffiliation = itemsList.get(0).attributeValue("affiliation") !=
null; null;
// Keep a registry of the updated presences // Keep a registry of the updated presences
...@@ -246,7 +248,7 @@ public class IQAdminHandler { ...@@ -246,7 +248,7 @@ public class IQAdminHandler {
presences.add(room.addVisitor(jid, senderRole)); presences.add(room.addVisitor(jid, senderRole));
} else if ("member".equals(target)) { } else if ("member".equals(target)) {
// Add the user as a member of the room based on the bare JID // Add the user as a member of the room based on the bare JID
boolean hadAffiliation = room.getAffiliation(jid.toBareJID()) != MUCRole.Affiliation.none; boolean hadAffiliation = room.getAffiliation(jid) != MUCRole.Affiliation.none;
presences.addAll(room.addMember(jid, nick, senderRole)); presences.addAll(room.addMember(jid, nick, senderRole));
// If the user had an affiliation don't send an invitation. Otherwise // If the user had an affiliation don't send an invitation. Otherwise
// send an invitation if the room is members-only and skipping invites // send an invitation if the room is members-only and skipping invites
......
...@@ -52,65 +52,63 @@ class IQMUCRegisterHandler { ...@@ -52,65 +52,63 @@ class IQMUCRegisterHandler {
private static final Logger Log = LoggerFactory.getLogger(IQMUCRegisterHandler.class); private static final Logger Log = LoggerFactory.getLogger(IQMUCRegisterHandler.class);
private static Element probeResult; private static final Element probeResult;
private MultiUserChatService mucService;
static {
// Create the registration form of the room which contains information
// such as: first name, last name and nickname.
final DataForm registrationForm = new DataForm(DataForm.Type.form);
registrationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.reg.title"));
registrationForm.addInstruction(LocaleUtils
.getLocalizedString("muc.form.reg.instruction"));
final FormField fieldForm = registrationForm.addField();
fieldForm.setVariable("FORM_TYPE");
fieldForm.setType(FormField.Type.hidden);
fieldForm.addValue("http://jabber.org/protocol/muc#register");
final FormField fieldReg = registrationForm.addField();
fieldReg.setVariable("muc#register_first");
fieldReg.setType(FormField.Type.text_single);
fieldReg.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.first-name"));
fieldReg.setRequired(true);
final FormField fieldLast = registrationForm.addField();
fieldLast.setVariable("muc#register_last");
fieldLast.setType(FormField.Type.text_single);
fieldLast.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.last-name"));
fieldLast.setRequired(true);
final FormField fieldNick = registrationForm.addField();
fieldNick.setVariable("muc#register_roomnick");
fieldNick.setType(FormField.Type.text_single);
fieldNick.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.nickname"));
fieldNick.setRequired(true);
final FormField fieldUrl = registrationForm.addField();
fieldUrl.setVariable("muc#register_url");
fieldUrl.setType(FormField.Type.text_single);
fieldUrl.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.url"));
final FormField fieldMail = registrationForm.addField();
fieldMail.setVariable("muc#register_email");
fieldMail.setType(FormField.Type.text_single);
fieldMail.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.email"));
final FormField fieldFaq = registrationForm.addField();
fieldFaq.setVariable("muc#register_faqentry");
fieldFaq.setType(FormField.Type.text_single);
fieldFaq.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.faqentry"));
// Create the probeResult and add the registration form
probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:register"));
probeResult.add(registrationForm.getElement());
}
private final MultiUserChatService mucService;
public IQMUCRegisterHandler(MultiUserChatService mucService) { public IQMUCRegisterHandler(MultiUserChatService mucService) {
this.mucService = mucService; this.mucService = mucService;
initialize();
}
public void initialize() {
if (probeResult == null) {
// Create the registration form of the room which contains information
// such as: first name, last name and nickname.
final DataForm registrationForm = new DataForm(DataForm.Type.form);
registrationForm.setTitle(LocaleUtils.getLocalizedString("muc.form.reg.title"));
registrationForm.addInstruction(LocaleUtils
.getLocalizedString("muc.form.reg.instruction"));
final FormField fieldForm = registrationForm.addField();
fieldForm.setVariable("FORM_TYPE");
fieldForm.setType(FormField.Type.hidden);
fieldForm.addValue("http://jabber.org/protocol/muc#register");
final FormField fieldReg = registrationForm.addField();
fieldReg.setVariable("muc#register_first");
fieldReg.setType(FormField.Type.text_single);
fieldReg.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.first-name"));
fieldReg.setRequired(true);
final FormField fieldLast = registrationForm.addField();
fieldLast.setVariable("muc#register_last");
fieldLast.setType(FormField.Type.text_single);
fieldLast.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.last-name"));
fieldLast.setRequired(true);
final FormField fieldNick = registrationForm.addField();
fieldNick.setVariable("muc#register_roomnick");
fieldNick.setType(FormField.Type.text_single);
fieldNick.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.nickname"));
fieldNick.setRequired(true);
final FormField fieldUrl = registrationForm.addField();
fieldUrl.setVariable("muc#register_url");
fieldUrl.setType(FormField.Type.text_single);
fieldUrl.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.url"));
final FormField fieldMail = registrationForm.addField();
fieldMail.setVariable("muc#register_email");
fieldMail.setType(FormField.Type.text_single);
fieldMail.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.email"));
final FormField fieldFaq = registrationForm.addField();
fieldFaq.setVariable("muc#register_faqentry");
fieldFaq.setType(FormField.Type.text_single);
fieldFaq.setLabel(LocaleUtils.getLocalizedString("muc.form.reg.faqentry"));
// Create the probeResult and add the registration form
probeResult = DocumentHelper.createElement(QName.get("query", "jabber:iq:register"));
probeResult.add(registrationForm.getElement());
}
} }
public IQ handleIQ(IQ packet) { public IQ handleIQ(IQ packet) {
...@@ -138,16 +136,19 @@ class IQMUCRegisterHandler { ...@@ -138,16 +136,19 @@ class IQMUCRegisterHandler {
if (IQ.Type.get == packet.getType()) { if (IQ.Type.get == packet.getType()) {
reply = IQ.createResultIQ(packet); reply = IQ.createResultIQ(packet);
String nickname = room.getReservedNickname(packet.getFrom().toBareJID()); String nickname = room.getReservedNickname(packet.getFrom());
Element currentRegistration = probeResult.createCopy(); Element currentRegistration = probeResult.createCopy();
if (nickname != null) { if (nickname != null) {
// The user is already registered with the room so answer a completed form // The user is already registered with the room so answer a completed form
ElementUtil.setProperty(currentRegistration, "query.registered", null); ElementUtil.setProperty(currentRegistration, "query.registered", null);
Element form = currentRegistration.element(QName.get("x", "jabber:x:data")); Element form = currentRegistration.element(QName.get("x", "jabber:x:data"));
Iterator fields = form.elementIterator("field");
@SuppressWarnings("unchecked")
Iterator<Element> fields = form.elementIterator("field");
Element field; Element field;
while (fields.hasNext()) { while (fields.hasNext()) {
field = (Element) fields.next(); field = fields.next();
if ("muc#register_roomnick".equals(field.attributeValue("var"))) { if ("muc#register_roomnick".equals(field.attributeValue("var"))) {
field.addElement("value").addText(nickname); field.addElement("value").addText(nickname);
} }
......
...@@ -60,15 +60,15 @@ public class IQOwnerHandler { ...@@ -60,15 +60,15 @@ public class IQOwnerHandler {
private static final Logger Log = LoggerFactory.getLogger(IQOwnerHandler.class); private static final Logger Log = LoggerFactory.getLogger(IQOwnerHandler.class);
private LocalMUCRoom room; private final LocalMUCRoom room;
private PacketRouter router; private final PacketRouter router;
private DataForm configurationForm; private DataForm configurationForm;
private Element probeResult; private Element probeResult;
private boolean skipInvite; private final boolean skipInvite;
public IQOwnerHandler(LocalMUCRoom chatroom, PacketRouter packetRouter) { public IQOwnerHandler(LocalMUCRoom chatroom, PacketRouter packetRouter) {
this.room = chatroom; this.room = chatroom;
...@@ -122,8 +122,8 @@ public class IQOwnerHandler { ...@@ -122,8 +122,8 @@ public class IQOwnerHandler {
} }
} }
room.destroyRoom(destroyElement.attributeValue("jid"), destroyElement room.destroyRoom(new JID(destroyElement.attributeValue("jid")),
.elementTextTrim("reason")); destroyElement.elementTextTrim("reason"));
} }
else { else {
List<Element> itemsList = element.elements("item"); List<Element> itemsList = element.elements("item");
...@@ -183,10 +183,10 @@ public class IQOwnerHandler { ...@@ -183,10 +183,10 @@ public class IQOwnerHandler {
// The client is requesting the list of owners // The client is requesting the list of owners
Element ownerMetaData; Element ownerMetaData;
MUCRole role; MUCRole role;
for (String jid : room.getOwners()) { for (JID jid : room.getOwners()) {
ownerMetaData = result.addElement("item", "http://jabber.org/protocol/muc#owner"); ownerMetaData = result.addElement("item", "http://jabber.org/protocol/muc#owner");
ownerMetaData.addAttribute("affiliation", "owner"); ownerMetaData.addAttribute("affiliation", "owner");
ownerMetaData.addAttribute("jid", jid); ownerMetaData.addAttribute("jid", jid.toString());
// Add role and nick to the metadata if the user is in the room // Add role and nick to the metadata if the user is in the room
try { try {
List<MUCRole> roles = room.getOccupantsByBareJID(jid); List<MUCRole> roles = room.getOccupantsByBareJID(jid);
...@@ -202,10 +202,10 @@ public class IQOwnerHandler { ...@@ -202,10 +202,10 @@ public class IQOwnerHandler {
// The client is requesting the list of admins // The client is requesting the list of admins
Element adminMetaData; Element adminMetaData;
MUCRole role; MUCRole role;
for (String jid : room.getAdmins()) { for (JID jid : room.getAdmins()) {
adminMetaData = result.addElement("item", "http://jabber.org/protocol/muc#owner"); adminMetaData = result.addElement("item", "http://jabber.org/protocol/muc#owner");
adminMetaData.addAttribute("affiliation", "admin"); adminMetaData.addAttribute("affiliation", "admin");
adminMetaData.addAttribute("jid", jid); adminMetaData.addAttribute("jid", jid.toString());
// Add role and nick to the metadata if the user is in the room // Add role and nick to the metadata if the user is in the room
try { try {
List<MUCRole> roles = room.getOccupantsByBareJID(jid); List<MUCRole> roles = room.getOccupantsByBareJID(jid);
...@@ -270,7 +270,7 @@ public class IQOwnerHandler { ...@@ -270,7 +270,7 @@ public class IQOwnerHandler {
presences.addAll(room.addAdmin(jid, senderRole)); presences.addAll(room.addAdmin(jid, senderRole));
} else if ("member".equals(targetAffiliation)) { } else if ("member".equals(targetAffiliation)) {
// Add the new user as a member of the room // Add the new user as a member of the room
boolean hadAffiliation = room.getAffiliation(jid.toBareJID()) != MUCRole.Affiliation.none; boolean hadAffiliation = room.getAffiliation(jid) != MUCRole.Affiliation.none;
presences.addAll(room.addMember(jid, null, senderRole)); presences.addAll(room.addMember(jid, null, senderRole));
// If the user had an affiliation don't send an invitation. Otherwise // If the user had an affiliation don't send an invitation. Otherwise
// send an invitation if the room is members-only and skipping invites // send an invitation if the room is members-only and skipping invites
...@@ -365,17 +365,25 @@ public class IQOwnerHandler { ...@@ -365,17 +365,25 @@ public class IQOwnerHandler {
// Get the new list of admins // Get the new list of admins
field = completedForm.getField("muc#roomconfig_roomadmins"); field = completedForm.getField("muc#roomconfig_roomadmins");
boolean adminsSent = field != null; boolean adminsSent = field != null;
List<String> admins = new ArrayList<String>(); List<JID> admins = new ArrayList<JID>();
if (field != null) { if (field != null) {
admins.addAll(field.getValues()); for (String value : field.getValues()) {
// XEP-0045: "Affiliations are granted, revoked, and
// maintained based on the user's bare JID, (...)"
admins.add(new JID(new JID(value).toBareJID()));
}
} }
// Get the new list of owners // Get the new list of owners
field = completedForm.getField("muc#roomconfig_roomowners"); field = completedForm.getField("muc#roomconfig_roomowners");
boolean ownersSent = field != null; boolean ownersSent = field != null;
List<String> owners = new ArrayList<String>(); List<JID> owners = new ArrayList<JID>();
if (field != null) { if (field != null) {
owners.addAll(field.getValues()); for(String value : field.getValues()) {
// XEP-0045: "Affiliations are granted, revoked, and
// maintained based on the user's bare JID, (...)"
owners.add(new JID(new JID(value).toBareJID()));
}
} }
// Answer a conflic error if all the current owners will be removed // Answer a conflic error if all the current owners will be removed
...@@ -526,22 +534,22 @@ public class IQOwnerHandler { ...@@ -526,22 +534,22 @@ public class IQOwnerHandler {
if (ownersSent) { if (ownersSent) {
// Change the affiliation to "member" for the current owners that won't be neither // Change the affiliation to "member" for the current owners that won't be neither
// owner nor admin (if the form included the owners field) // owner nor admin (if the form included the owners field)
List<String> ownersToRemove = new ArrayList<String>(room.owners); List<JID> ownersToRemove = new ArrayList<JID>(room.owners);
ownersToRemove.removeAll(admins); ownersToRemove.removeAll(admins);
ownersToRemove.removeAll(owners); ownersToRemove.removeAll(owners);
for (String jid : ownersToRemove) { for (JID jid : ownersToRemove) {
presences.addAll(room.addMember(new JID(jid), null, senderRole)); presences.addAll(room.addMember(jid, null, senderRole));
} }
} }
if (adminsSent) { if (adminsSent) {
// Change the affiliation to "member" for the current admins that won't be neither // Change the affiliation to "member" for the current admins that won't be neither
// owner nor admin (if the form included the admins field) // owner nor admin (if the form included the admins field)
List<String> adminsToRemove = new ArrayList<String>(room.admins); List<JID> adminsToRemove = new ArrayList<JID>(room.admins);
adminsToRemove.removeAll(admins); adminsToRemove.removeAll(admins);
adminsToRemove.removeAll(owners); adminsToRemove.removeAll(owners);
for (String jid : adminsToRemove) { for (JID jid : adminsToRemove) {
presences.addAll(room.addMember(new JID(jid), null, senderRole)); presences.addAll(room.addMember(jid, null, senderRole));
} }
} }
...@@ -632,14 +640,14 @@ public class IQOwnerHandler { ...@@ -632,14 +640,14 @@ public class IQOwnerHandler {
field = configurationForm.getField("muc#roomconfig_roomadmins"); field = configurationForm.getField("muc#roomconfig_roomadmins");
field.clearValues(); field.clearValues();
for (String jid : room.getAdmins()) { for (JID jid : room.getAdmins()) {
field.addValue(jid); field.addValue(jid.toString());
} }
field = configurationForm.getField("muc#roomconfig_roomowners"); field = configurationForm.getField("muc#roomconfig_roomowners");
field.clearValues(); field.clearValues();
for (String jid : room.getOwners()) { for (JID jid : room.getOwners()) {
field.addValue(jid); field.addValue(jid.toString());
} }
// Remove the old element // Remove the old element
......
...@@ -312,9 +312,12 @@ public class LocalMUCUser implements MUCUser { ...@@ -312,9 +312,12 @@ public class LocalMUCUser implements MUCUser {
List<Element> extensions = new ArrayList<Element>(packet List<Element> extensions = new ArrayList<Element>(packet
.getElement().elements()); .getElement().elements());
extensions.remove(userInfo); extensions.remove(userInfo);
// Send invitations to invitees // Send invitations to invitees
for (Iterator it=userInfo.elementIterator("invite");it.hasNext();) { @SuppressWarnings("unchecked")
Element info = (Element) it.next(); Iterator<Element> it = userInfo.elementIterator("invite");
while(it.hasNext()) {
Element info = it.next();
JID jid = new JID(info.attributeValue("to")); JID jid = new JID(info.attributeValue("to"));
// Add the user as a member of the room if the room is // Add the user as a member of the room if the room is
......
...@@ -557,16 +557,8 @@ public class MUCPersistenceManager { ...@@ -557,16 +557,8 @@ public class MUCPersistenceManager {
} catch (IllegalArgumentException ex) { } catch (IllegalArgumentException ex) {
Log.warn("An illegal JID ({}) was found in the database, " Log.warn("An illegal JID ({}) was found in the database, "
+ "while trying to load all affiliations for room " + "while trying to load all affiliations for room "
+ "{} on the MUC service {}. An attempt is made to" + "{} on the MUC service {}. The JID is ignored."
+ " delete the associated affiliation. The JID is" , new Object[] { jidValue, roomID, chatserver.getName() });
+ " otherwise ignored.", new Object[] { jidValue,
roomID, chatserver.getName() });
try {
removeAffiliationFromDB(room, jidValue, affiliation);
Log.warn("Affiliation removed.");
} catch (RuntimeException e) {
Log.warn("Unable to remove affiliation.", e);
}
continue; continue;
} }
try { try {
...@@ -727,9 +719,10 @@ public class MUCPersistenceManager { ...@@ -727,9 +719,10 @@ public class MUCPersistenceManager {
* @param newAffiliation the new affiliation of the user in the room. * @param newAffiliation the new affiliation of the user in the room.
* @param oldAffiliation the previous affiliation of the user in the room. * @param oldAffiliation the previous affiliation of the user in the room.
*/ */
public static void saveAffiliationToDB(MUCRoom room, String bareJID, String nickname, public static void saveAffiliationToDB(MUCRoom room, JID jid, String nickname,
MUCRole.Affiliation newAffiliation, MUCRole.Affiliation oldAffiliation) MUCRole.Affiliation newAffiliation, MUCRole.Affiliation oldAffiliation)
{ {
final String bareJID = jid.toBareJID();
if (!room.isPersistent() || !room.wasSavedToDB()) { if (!room.isPersistent() || !room.wasSavedToDB()) {
return; return;
} }
...@@ -880,9 +873,10 @@ public class MUCPersistenceManager { ...@@ -880,9 +873,10 @@ public class MUCPersistenceManager {
* @param bareJID The bareJID of the user to remove his affiliation. * @param bareJID The bareJID of the user to remove his affiliation.
* @param oldAffiliation the previous affiliation of the user in the room. * @param oldAffiliation the previous affiliation of the user in the room.
*/ */
public static void removeAffiliationFromDB(MUCRoom room, String bareJID, public static void removeAffiliationFromDB(MUCRoom room, JID jid,
MUCRole.Affiliation oldAffiliation) MUCRole.Affiliation oldAffiliation)
{ {
final String bareJID = jid.toBareJID();
if (room.isPersistent() && room.wasSavedToDB()) { if (room.isPersistent() && room.wasSavedToDB()) {
if (MUCRole.Affiliation.member == oldAffiliation) { if (MUCRole.Affiliation.member == oldAffiliation) {
// Remove the user from the members table // Remove the user from the members table
...@@ -1004,13 +998,14 @@ public class MUCPersistenceManager { ...@@ -1004,13 +998,14 @@ public class MUCPersistenceManager {
* @param name the name of the property to return. * @param name the name of the property to return.
* @return the property value specified by name. * @return the property value specified by name.
*/ */
public static String getProperty(String subdomain, String name) { public static String getProperty(String subdomain, String name) {
MUCServiceProperties properties = propertyMaps.get(subdomain); final MUCServiceProperties newProps = new MUCServiceProperties(subdomain);
if (properties == null) { final MUCServiceProperties oldProps = propertyMaps.putIfAbsent(subdomain, newProps);
properties = new MUCServiceProperties(subdomain); if (oldProps != null) {
propertyMaps.put(subdomain, properties); return oldProps.get(name);
} } else {
return properties.get(name); return newProps.get(name);
}
} }
/** /**
...@@ -1023,18 +1018,12 @@ public class MUCPersistenceManager { ...@@ -1023,18 +1018,12 @@ public class MUCPersistenceManager {
* @return the property value specified by name. * @return the property value specified by name.
*/ */
public static String getProperty(String subdomain, String name, String defaultValue) { public static String getProperty(String subdomain, String name, String defaultValue) {
MUCServiceProperties properties = propertyMaps.get(subdomain); final String value = getProperty(subdomain, name);
if (properties == null) { if (value != null) {
properties = new MUCServiceProperties(subdomain); return value;
propertyMaps.put(subdomain, properties); } else {
} return defaultValue;
String value = properties.get(name); }
if (value != null) {
return value;
}
else {
return defaultValue;
}
} }
/** /**
...@@ -1130,11 +1119,11 @@ public class MUCPersistenceManager { ...@@ -1130,11 +1119,11 @@ public class MUCPersistenceManager {
* @return a List of all immediate children property names (Strings). * @return a List of all immediate children property names (Strings).
*/ */
public static List<String> getPropertyNames(String subdomain, String parent) { public static List<String> getPropertyNames(String subdomain, String parent) {
MUCServiceProperties properties = propertyMaps.get(subdomain); MUCServiceProperties properties = new MUCServiceProperties(subdomain);
if (properties == null) { final MUCServiceProperties oldProps = propertyMaps.putIfAbsent(subdomain, properties);
properties = new MUCServiceProperties(subdomain); if (oldProps != null) {
propertyMaps.put(subdomain, properties); properties = oldProps;
} }
return new ArrayList<String>(properties.getChildrenNames(parent)); return new ArrayList<String>(properties.getChildrenNames(parent));
} }
...@@ -1150,11 +1139,11 @@ public class MUCPersistenceManager { ...@@ -1150,11 +1139,11 @@ public class MUCPersistenceManager {
* @return all child property values for the given parent. * @return all child property values for the given parent.
*/ */
public static List<String> getProperties(String subdomain, String parent) { public static List<String> getProperties(String subdomain, String parent) {
MUCServiceProperties properties = propertyMaps.get(subdomain); MUCServiceProperties properties = new MUCServiceProperties(subdomain);
if (properties == null) { final MUCServiceProperties oldProps = propertyMaps.putIfAbsent(subdomain, properties);
properties = new MUCServiceProperties(subdomain); if (oldProps != null) {
propertyMaps.put(subdomain, properties); properties = oldProps;
} }
Collection<String> propertyNames = properties.getChildrenNames(parent); Collection<String> propertyNames = properties.getChildrenNames(parent);
List<String> values = new ArrayList<String>(); List<String> values = new ArrayList<String>();
...@@ -1175,11 +1164,11 @@ public class MUCPersistenceManager { ...@@ -1175,11 +1164,11 @@ public class MUCPersistenceManager {
* @return a List of all property names (Strings). * @return a List of all property names (Strings).
*/ */
public static List<String> getPropertyNames(String subdomain) { public static List<String> getPropertyNames(String subdomain) {
MUCServiceProperties properties = propertyMaps.get(subdomain); MUCServiceProperties properties = new MUCServiceProperties(subdomain);
if (properties == null) { final MUCServiceProperties oldProps = propertyMaps.putIfAbsent(subdomain, properties);
properties = new MUCServiceProperties(subdomain); if (oldProps != null) {
propertyMaps.put(subdomain, properties); properties = oldProps;
} }
return new ArrayList<String>(properties.getPropertyNames()); return new ArrayList<String>(properties.getPropertyNames());
} }
......
...@@ -198,13 +198,13 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -198,13 +198,13 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
* Bare jids of users that are allowed to create MUC rooms. An empty list means that anyone can * Bare jids of users that are allowed to create MUC rooms. An empty list means that anyone can
* create a room. * create a room.
*/ */
private List<String> allowedToCreate = new CopyOnWriteArrayList<String>(); private List<JID> allowedToCreate = new CopyOnWriteArrayList<JID>();
/** /**
* Bare jids of users that are system administrators of the MUC service. A sysadmin has the same * Bare jids of users that are system administrators of the MUC service. A sysadmin has the same
* permissions as a room owner. * permissions as a room owner.
*/ */
private List<String> sysadmins = new CopyOnWriteArrayList<String>(); private List<JID> sysadmins = new CopyOnWriteArrayList<JID>();
/** /**
* Queue that holds the messages to log for the rooms that need to log their conversations. * Queue that holds the messages to log for the rooms that need to log their conversations.
...@@ -547,15 +547,16 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -547,15 +547,16 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
else { else {
// The room does not exist so check for creation permissions // The room does not exist so check for creation permissions
// Room creation is always allowed for sysadmin // Room creation is always allowed for sysadmin
if (isRoomCreationRestricted() && !sysadmins.contains(userjid.toBareJID())) { final JID bareJID = new JID(userjid.toBareJID());
if (isRoomCreationRestricted() && !sysadmins.contains(bareJID)) {
// The room creation is only allowed for certain JIDs // The room creation is only allowed for certain JIDs
if (!allowedToCreate.contains(userjid.toBareJID())) { if (!allowedToCreate.contains(bareJID)) {
// The user is not in the list of allowed JIDs to create a room so raise // The user is not in the list of allowed JIDs to create a room so raise
// an exception // an exception
throw new NotAllowedException(); throw new NotAllowedException();
} }
} }
room.addFirstOwner(userjid.toBareJID()); room.addFirstOwner(userjid);
created = true; created = true;
} }
} }
...@@ -806,31 +807,42 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -806,31 +807,42 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
return log_batch_size; return log_batch_size;
} }
public Collection<String> getUsersAllowedToCreate() { public Collection<JID> getUsersAllowedToCreate() {
return allowedToCreate; return Collections.unmodifiableCollection(allowedToCreate);
} }
public Collection<String> getSysadmins() { public Collection<JID> getSysadmins() {
return sysadmins; return Collections.unmodifiableCollection(sysadmins);
} }
public void addSysadmin(String userJID) { public void addSysadmin(JID userJID) {
sysadmins.add(userJID.trim().toLowerCase()); final JID bareJID = new JID(userJID.toBareJID());
sysadmins.add(bareJID);
// CopyOnWriteArray does not allow sorting, so do sorting in temp list. // CopyOnWriteArray does not allow sorting, so do sorting in temp list.
ArrayList<String> tempList = new ArrayList<String>(sysadmins); ArrayList<JID> tempList = new ArrayList<JID>(sysadmins);
Collections.sort(tempList); Collections.sort(tempList);
sysadmins = new CopyOnWriteArrayList<String>(tempList); sysadmins = new CopyOnWriteArrayList<JID>(tempList);
// Update the config. // Update the config.
String[] jids = new String[sysadmins.size()]; String[] jids = new String[sysadmins.size()];
jids = sysadmins.toArray(jids); for (int i = 0; i < jids.length; i++) {
jids[i] = sysadmins.get(i).toBareJID();
}
MUCPersistenceManager.setProperty(chatServiceName, "sysadmin.jid", fromArray(jids)); MUCPersistenceManager.setProperty(chatServiceName, "sysadmin.jid", fromArray(jids));
} }
public void removeSysadmin(String userJID) { public void removeSysadmin(JID userJID) {
sysadmins.remove(userJID.trim().toLowerCase()); final JID bareJID = new JID(userJID.toBareJID());
sysadmins.remove(bareJID);
// Update the config. // Update the config.
String[] jids = new String[sysadmins.size()]; String[] jids = new String[sysadmins.size()];
jids = sysadmins.toArray(jids); for (int i = 0; i < jids.length; i++) {
jids[i] = sysadmins.get(i).toBareJID();
}
MUCPersistenceManager.setProperty(chatServiceName, "sysadmin.jid", fromArray(jids)); MUCPersistenceManager.setProperty(chatServiceName, "sysadmin.jid", fromArray(jids));
} }
...@@ -868,27 +880,39 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -868,27 +880,39 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
MUCPersistenceManager.setProperty(chatServiceName, "create.anyone", Boolean.toString(roomCreationRestricted)); MUCPersistenceManager.setProperty(chatServiceName, "create.anyone", Boolean.toString(roomCreationRestricted));
} }
public void addUserAllowedToCreate(String userJID) { public void addUserAllowedToCreate(JID userJID) {
final JID bareJID = new JID(userJID.toBareJID());
// Update the list of allowed JIDs to create MUC rooms. Since we are updating the instance // Update the list of allowed JIDs to create MUC rooms. Since we are updating the instance
// variable there is no need to restart the service // variable there is no need to restart the service
allowedToCreate.add(userJID.trim().toLowerCase());
allowedToCreate.add(bareJID);
// CopyOnWriteArray does not allow sorting, so do sorting in temp list. // CopyOnWriteArray does not allow sorting, so do sorting in temp list.
ArrayList<String> tempList = new ArrayList<String>(allowedToCreate); ArrayList<JID> tempList = new ArrayList<JID>(allowedToCreate);
Collections.sort(tempList); Collections.sort(tempList);
allowedToCreate = new CopyOnWriteArrayList<String>(tempList); allowedToCreate = new CopyOnWriteArrayList<JID>(tempList);
// Update the config. // Update the config.
String[] jids = new String[allowedToCreate.size()]; String[] jids = new String[allowedToCreate.size()];
jids = allowedToCreate.toArray(jids); for (int i = 0; i < jids.length; i++) {
jids[i] = allowedToCreate.get(i).toBareJID();
}
MUCPersistenceManager.setProperty(chatServiceName, "create.jid", fromArray(jids)); MUCPersistenceManager.setProperty(chatServiceName, "create.jid", fromArray(jids));
} }
public void removeUserAllowedToCreate(String userJID) { public void removeUserAllowedToCreate(JID userJID) {
final JID bareJID = new JID(userJID.toBareJID());
// Update the list of allowed JIDs to create MUC rooms. Since we are updating the instance // Update the list of allowed JIDs to create MUC rooms. Since we are updating the instance
// variable there is no need to restart the service // variable there is no need to restart the service
allowedToCreate.remove(userJID.trim().toLowerCase()); allowedToCreate.remove(bareJID);
// Update the config. // Update the config.
String[] jids = new String[allowedToCreate.size()]; String[] jids = new String[allowedToCreate.size()];
jids = allowedToCreate.toArray(jids); for (int i = 0; i < jids.length; i++) {
jids[i] = allowedToCreate.get(i).toBareJID();
}
MUCPersistenceManager.setProperty(chatServiceName, "create.jid", fromArray(jids)); MUCPersistenceManager.setProperty(chatServiceName, "create.jid", fromArray(jids));
} }
...@@ -915,7 +939,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -915,7 +939,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
if (property != null) { if (property != null) {
jids = property.split(","); jids = property.split(",");
for (String jid : jids) { for (String jid : jids) {
sysadmins.add(jid.trim().toLowerCase()); sysadmins.add(new JID(new JID(jid.trim().toLowerCase()).toBareJID()));
} }
} }
allowToDiscoverLockedRooms = allowToDiscoverLockedRooms =
...@@ -928,7 +952,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -928,7 +952,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
if (property != null) { if (property != null) {
jids = property.split(","); jids = property.split(",");
for (String jid : jids) { for (String jid : jids) {
allowedToCreate.add(jid.trim().toLowerCase()); allowedToCreate.add(new JID(new JID(jid.trim().toLowerCase()).toBareJID()));
} }
} }
String value = MUCPersistenceManager.getProperty(chatServiceName, "tasks.user.timeout"); String value = MUCPersistenceManager.getProperty(chatServiceName, "tasks.user.timeout");
...@@ -1201,7 +1225,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -1201,7 +1225,7 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
// Answer reserved nickname for the sender of the disco request in the requested room // Answer reserved nickname for the sender of the disco request in the requested room
MUCRoom room = getChatRoom(name); MUCRoom room = getChatRoom(name);
if (room != null) { if (room != null) {
String reservedNick = room.getReservedNickname(senderJID.toBareJID()); String reservedNick = room.getReservedNickname(senderJID);
if (reservedNick != null) { if (reservedNick != null) {
Element identity = DocumentHelper.createElement("identity"); Element identity = DocumentHelper.createElement("identity");
identity.addAttribute("category", "conference"); identity.addAttribute("category", "conference");
...@@ -1346,12 +1370,14 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService ...@@ -1346,12 +1370,14 @@ public class MultiUserChatServiceImpl implements Component, MultiUserChatService
* @param name Name of identity to remove. * @param name Name of identity to remove.
*/ */
public void removeExtraIdentity(String name) { public void removeExtraIdentity(String name) {
for (Element elem : extraDiscoIdentities) { final Iterator<Element> iter = extraDiscoIdentities.iterator();
while (iter.hasNext()) {
Element elem = iter.next();
if (name.equals(elem.attribute("name").getStringValue())) { if (name.equals(elem.attribute("name").getStringValue())) {
extraDiscoFeatures.remove(elem); iter.remove();
break; break;
} }
} }
} }
/** /**
......
...@@ -145,7 +145,6 @@ public class WebDAVLiteServlet extends HttpServlet { ...@@ -145,7 +145,6 @@ public class WebDAVLiteServlet extends HttpServlet {
private Boolean isAuthorized(HttpServletRequest request, HttpServletResponse response, private Boolean isAuthorized(HttpServletRequest request, HttpServletResponse response,
String service, String room) throws ServletException, IOException { String service, String room) throws ServletException, IOException {
String auth = request.getHeader("Authorization"); String auth = request.getHeader("Authorization");
JID jid;
try { try {
if (auth == null || !request.getAuthType().equals(HttpServletRequest.BASIC_AUTH)) { if (auth == null || !request.getAuthType().equals(HttpServletRequest.BASIC_AUTH)) {
throw new Exception("No authorization or improper authorization provided."); throw new Exception("No authorization or improper authorization provided.");
...@@ -157,8 +156,8 @@ public class WebDAVLiteServlet extends HttpServlet { ...@@ -157,8 +156,8 @@ public class WebDAVLiteServlet extends HttpServlet {
if (!username.contains("@")) { if (!username.contains("@")) {
throw new Exception("Not a valid JID."); throw new Exception("Not a valid JID.");
} }
jid = new JID(username); final JID bareJID = new JID(new JID(username).toBareJID());
XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(service).getChatRoom(room).getOccupantsByBareJID(jid.toBareJID()); XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService(service).getChatRoom(room).getOccupantsByBareJID(bareJID);
return true; return true;
} }
catch (Exception e) { catch (Exception e) {
......
...@@ -74,7 +74,7 @@ public class DummyExternalizableUtil implements ExternalizableUtilStrategy { ...@@ -74,7 +74,7 @@ public class DummyExternalizableUtil implements ExternalizableUtilStrategy {
* @return a Map of Long key/Integer value pairs. * @return a Map of Long key/Integer value pairs.
* @throws IOException if an error occurs. * @throws IOException if an error occurs.
*/ */
public Map readLongIntMap(DataInput in) throws IOException { public Map<Long, Integer> readLongIntMap(DataInput in) throws IOException {
// Do nothing // Do nothing
return Collections.emptyMap(); return Collections.emptyMap();
} }
...@@ -87,7 +87,7 @@ public class DummyExternalizableUtil implements ExternalizableUtilStrategy { ...@@ -87,7 +87,7 @@ public class DummyExternalizableUtil implements ExternalizableUtilStrategy {
* @param stringList the List of Strings. * @param stringList the List of Strings.
* @throws IOException if an error occurs. * @throws IOException if an error occurs.
*/ */
public void writeStringList(DataOutput out, List stringList) throws IOException { public void writeStringList(DataOutput out, List<String> stringList) throws IOException {
// Do nothing // Do nothing
} }
...@@ -206,11 +206,11 @@ public class DummyExternalizableUtil implements ExternalizableUtilStrategy { ...@@ -206,11 +206,11 @@ public class DummyExternalizableUtil implements ExternalizableUtilStrategy {
return 0; return 0;
} }
public void writeSerializableMap(DataOutput out, Map<String, ? extends Serializable> map) throws IOException { public void writeSerializableMap(DataOutput out, Map<? extends Serializable, ? extends Serializable> map) throws IOException {
// Do nothing // Do nothing
} }
public int readSerializableMap(DataInput in, Map<String, ? extends Serializable> map, ClassLoader loader) public int readSerializableMap(DataInput in, Map<? extends Serializable, ? extends Serializable> map, ClassLoader loader)
throws IOException { throws IOException {
// Do nothing // Do nothing
return 0; return 0;
......
...@@ -124,7 +124,7 @@ public class ExternalizableUtil { ...@@ -124,7 +124,7 @@ public class ExternalizableUtil {
* @return a Map of Long key/Integer value pairs. * @return a Map of Long key/Integer value pairs.
* @throws IOException if an error occurs. * @throws IOException if an error occurs.
*/ */
public Map readLongIntMap(DataInput in) throws IOException { public Map<Long, Integer> readLongIntMap(DataInput in) throws IOException {
return strategy.readLongIntMap(in); return strategy.readLongIntMap(in);
} }
...@@ -136,7 +136,7 @@ public class ExternalizableUtil { ...@@ -136,7 +136,7 @@ public class ExternalizableUtil {
* @param stringList the List of Strings. * @param stringList the List of Strings.
* @throws IOException if an error occurs. * @throws IOException if an error occurs.
*/ */
public void writeStringList(DataOutput out, List stringList) throws IOException { public void writeStringList(DataOutput out, List<String> stringList) throws IOException {
strategy.writeStringList(out, stringList); strategy.writeStringList(out, stringList);
} }
...@@ -291,14 +291,14 @@ public class ExternalizableUtil { ...@@ -291,14 +291,14 @@ public class ExternalizableUtil {
} }
/** /**
* Writes a Map of String key and value pairs. This method handles the * Writes a Map of Serializable key and value pairs. This method handles the
* case when the Map is <tt>null</tt>. * case when the Map is <tt>null</tt>.
* *
* @param out the output stream. * @param out the output stream.
* @param map the Map of String key and Externalizable value pairs. * @param map the Map of Serializable key and value pairs.
* @throws java.io.IOException if an error occurs. * @throws java.io.IOException if an error occurs.
*/ */
public void writeSerializableMap(DataOutput out, Map<String, ? extends Serializable> map) throws IOException { public void writeSerializableMap(DataOutput out, Map<? extends Serializable, ? extends Serializable> map) throws IOException {
strategy.writeSerializableMap(out, map); strategy.writeSerializableMap(out, map);
} }
...@@ -317,16 +317,16 @@ public class ExternalizableUtil { ...@@ -317,16 +317,16 @@ public class ExternalizableUtil {
} }
/** /**
* Reads a Map of String key and value pairs. This method will return * Reads a Map of Serializable key and value pairs. This method will return
* <tt>null</tt> if the Map written to the stream was <tt>null</tt>. * <tt>null</tt> if the Map written to the stream was <tt>null</tt>.
* *
* @param in the input stream. * @param in the input stream.
* @param map a Map of String key and Serializable value pairs. * @param map a Map of Serializable key and value pairs.
* @param loader class loader to use to build elements inside of the serialized collection. * @param loader class loader to use to build elements inside of the serialized collection.
* @throws IOException if an error occurs. * @throws IOException if an error occurs.
* @return the number of elements added to the collection. * @return the number of elements added to the collection.
*/ */
public int readSerializableMap(DataInput in, Map<String, ? extends Serializable> map, ClassLoader loader) throws IOException { public int readSerializableMap(DataInput in, Map<? extends Serializable, ? extends Serializable> map, ClassLoader loader) throws IOException {
return strategy.readSerializableMap(in, map, loader); return strategy.readSerializableMap(in, map, loader);
} }
......
...@@ -72,7 +72,7 @@ public interface ExternalizableUtilStrategy { ...@@ -72,7 +72,7 @@ public interface ExternalizableUtilStrategy {
* @return a Map of Long key/Integer value pairs. * @return a Map of Long key/Integer value pairs.
* @throws IOException if an error occurs. * @throws IOException if an error occurs.
*/ */
Map readLongIntMap(DataInput in) throws IOException; Map<Long, Integer> readLongIntMap(DataInput in) throws IOException;
/** /**
* Writes a List of Strings. This method handles the case when the List is * Writes a List of Strings. This method handles the case when the List is
...@@ -82,7 +82,7 @@ public interface ExternalizableUtilStrategy { ...@@ -82,7 +82,7 @@ public interface ExternalizableUtilStrategy {
* @param stringList the List of Strings. * @param stringList the List of Strings.
* @throws IOException if an error occurs. * @throws IOException if an error occurs.
*/ */
void writeStringList(DataOutput out, List stringList) throws IOException; void writeStringList(DataOutput out, List<String> stringList) throws IOException;
/** /**
* Reads a List of Strings. This method will return <tt>null</tt> if the List * Reads a List of Strings. This method will return <tt>null</tt> if the List
...@@ -148,9 +148,9 @@ public interface ExternalizableUtilStrategy { ...@@ -148,9 +148,9 @@ public interface ExternalizableUtilStrategy {
int readExternalizableMap(DataInput in, Map<String, ? extends Externalizable> map, ClassLoader loader) throws IOException; int readExternalizableMap(DataInput in, Map<String, ? extends Externalizable> map, ClassLoader loader) throws IOException;
void writeSerializableMap(DataOutput out, Map<String, ? extends Serializable> map) throws IOException; void writeSerializableMap(DataOutput out, Map<? extends Serializable, ? extends Serializable> map) throws IOException;
int readSerializableMap(DataInput in, Map<String, ? extends Serializable> map, ClassLoader loader) throws IOException; int readSerializableMap(DataInput in, Map<? extends Serializable, ? extends Serializable> map, ClassLoader loader) throws IOException;
void writeStringsMap(DataOutput out, Map<String, Set<String>> map) throws IOException; void writeStringsMap(DataOutput out, Map<String, Set<String>> map) throws IOException;
......
...@@ -320,7 +320,7 @@ public class CoherenceExternalizableUtil implements ExternalizableUtilStrategy { ...@@ -320,7 +320,7 @@ public class CoherenceExternalizableUtil implements ExternalizableUtilStrategy {
ExternalizableHelper.writeMap(out, map); ExternalizableHelper.writeMap(out, map);
} }
public void writeSerializableMap(DataOutput out, Map<String, ? extends Serializable> map) throws IOException { public void writeSerializableMap(DataOutput out, Map<? extends Serializable, ? extends Serializable> map) throws IOException {
ExternalizableHelper.writeMap(out, map); ExternalizableHelper.writeMap(out, map);
} }
...@@ -328,7 +328,7 @@ public class CoherenceExternalizableUtil implements ExternalizableUtilStrategy { ...@@ -328,7 +328,7 @@ public class CoherenceExternalizableUtil implements ExternalizableUtilStrategy {
return ExternalizableHelper.readMap(in, map, loader); return ExternalizableHelper.readMap(in, map, loader);
} }
public int readSerializableMap(DataInput in, Map<String, ? extends Serializable> map, ClassLoader loader) throws IOException { public int readSerializableMap(DataInput in, Map<? extends Serializable, ? extends Serializable> map, ClassLoader loader) throws IOException {
return ExternalizableHelper.readMap(in, map, loader); return ExternalizableHelper.readMap(in, map, loader);
} }
......
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