The original code snippet:
private void handleItemsElement(MUCRole senderRole, List itemsList, IQ reply)
throws ForbiddenException, ConflictException, NotAllowedException, CannotBeInvitedException {
Element item;
String affiliation;
String roleAttribute;
boolean hasJID = itemsList.get(0).attributeValue(“jid”) != null;
boolean hasNick = itemsList.get(0).attributeValue(“nick”) != null;
// Check if the client is requesting or changing the list of moderators/members/etc.
if (!hasJID && !hasNick) {
// The client is requesting the list of moderators/members/participants/outcasts
for (Object anItem : itemsList) {
item = (Element) anItem;
affiliation = item.attributeValue(“affiliation”);
roleAttribute = item.attributeValue(“role”);
// Create the result that will hold an item for each
// moderator/member/participant/outcast
** Element result = reply.setChildElement(“query”, “http://jabber.org/protocol/muc#admin”);**
**
**
Element metaData;
if (“outcast”.equals(affiliation)) {
// The client is requesting the list of outcasts
if (MUCRole.Affiliation.admin != senderRole.getAffiliation()
&& MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
throw new ForbiddenException();
}
for (JID jid : room.getOutcasts()) {
metaData = result.addElement("item", "[http://jabber.org/protocol/muc#admin](http://jabber.org/protocol/muc#admin)");
metaData.addAttribute(“affiliation”, “outcast”);
metaData.addAttribute(“jid”, jid.toString());
}
} else if (“member”.equals(affiliation)) {
// The client is requesting the list of members
// In a members-only room members can get the list of members
if (!room.isMembersOnly()
&& MUCRole.Affiliation.admin != senderRole.getAffiliation()
&& MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
throw new ForbiddenException();
}
for (JID jid : room.getMembers()) {
metaData = result.addElement("item", "[http://jabber.org/protocol/muc#admin](http://jabber.org/protocol/muc#admin)");
metaData.addAttribute(“affiliation”, “member”);
metaData.addAttribute(“jid”, jid.toString());
try {
List roles = room.getOccupantsByBareJID(jid);
MUCRole role = roles.get(0);
metaData.addAttribute(“role”, role.getRole().toString());
metaData.addAttribute(“nick”, role.getNickname());
}
catch (UserNotFoundException e) {
// Do nothing
}
}
} else if (“moderator”.equals(roleAttribute)) {
// The client is requesting the list of moderators
if (MUCRole.Affiliation.admin != senderRole.getAffiliation()
&& MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
throw new ForbiddenException();
}
for (MUCRole role : room.getModerators()) {
metaData = result.addElement("item", "[http://jabber.org/protocol/muc#admin](http://jabber.org/protocol/muc#admin)");
metaData.addAttribute(“role”, “moderator”);
metaData.addAttribute(“jid”, role.getUserAddress().toString());
metaData.addAttribute(“nick”, role.getNickname());
metaData.addAttribute(“affiliation”, role.getAffiliation().toString());
}
} else if (“participant”.equals(roleAttribute)) {
// The client is requesting the list of participants
if (MUCRole.Role.moderator != senderRole.getRole()) {
throw new ForbiddenException();
}
for (MUCRole role : room.getParticipants()) {
metaData = result.addElement("item", "[http://jabber.org/protocol/muc#admin](http://jabber.org/protocol/muc#admin)");
metaData.addAttribute(“role”, “participant”);
metaData.addAttribute(“jid”, role.getUserAddress().toString());
metaData.addAttribute(“nick”, role.getNickname());
metaData.addAttribute(“affiliation”, role.getAffiliation().toString());
}
} else if (“owner”.equals(affiliation)) {
// The client is requesting the list of owners
Element ownerMetaData;
MUCRole role;
for (JID jid : room.getOwners()) {
ownerMetaData = result.addElement("item", "[http://jabber.org/protocol/muc#admin](http://jabber.org/protocol/muc#admin)");
ownerMetaData.addAttribute(“affiliation”, “owner”);
ownerMetaData.addAttribute(“jid”, jid.toBareJID());
// Add role and nick to the metadata if the user is in the room
try {
List roles = room.getOccupantsByBareJID(jid);
role = roles.get(0);
ownerMetaData.addAttribute(“role”, role.getRole().toString());
ownerMetaData.addAttribute(“nick”, role.getNickname());
}
catch (UserNotFoundException e) {
// Do nothing
}
}
} else if (“admin”.equals(affiliation)) {
// The client is requesting the list of admins
Element adminMetaData;
MUCRole role;
for (JID jid : room.getAdmins()) {
adminMetaData = result.addElement("item", "[http://jabber.org/protocol/muc#admin](http://jabber.org/protocol/muc#admin)");
adminMetaData.addAttribute(“affiliation”, “admin”);
adminMetaData.addAttribute(“jid”, jid.toBareJID());
// Add role and nick to the metadata if the user is in the room
try {
List roles = room.getOccupantsByBareJID(jid);
role = roles.get(0);
adminMetaData.addAttribute(“role”, role.getRole().toString());
adminMetaData.addAttribute(“nick”, role.getNickname());
}
catch (UserNotFoundException e) {
// Do nothing
}
}
} else {
reply.setError(PacketError.Condition.bad_request);
}
}
}
else {
// The client is modifying the list of moderators/members/participants/outcasts
JID jid;
String nick;
String target;
boolean hasAffiliation = itemsList.get(0).attributeValue(“affiliation”) !=
null;
// Keep a registry of the updated presences
List presences = new ArrayList(itemsList.size());
// Collect the new affiliations or roles for the specified jids
for (Object anItem : itemsList) {
try {
item = (Element) anItem;
target = (hasAffiliation ? item.attributeValue(“affiliation”) : item
.attributeValue(“role”));
// jid could be of the form “full JID” or “bare JID” depending if we are
// going to change a role or an affiliation
if (hasJID) {
jid = new JID(item.attributeValue(“jid”));
nick = null;
} else {
// Get the JID based on the requested nick
nick = item.attributeValue(“nick”);
jid = room.getOccupant(nick).getUserAddress();
}
if (“moderator”.equals(target)) {
// Add the user as a moderator of the room based on the full JID
presences.add(room.addModerator(jid, senderRole));
} else if (“owner”.equals(target)) {
presences.addAll(room.addOwner(jid, senderRole));
} else if (“admin”.equals(target)) {
presences.addAll(room.addAdmin(jid, senderRole));
} else if (“participant”.equals(target)) {
// Add the user as a participant of the room based on the full JID
presences.add(room.addParticipant(jid,
item.elementTextTrim(“reason”),
senderRole));
} else if (“visitor”.equals(target)) {
// Add the user as a visitor of the room based on the full JID
presences.add(room.addVisitor(jid, senderRole));
} else if (“member”.equals(target)) {
// Add the user as a member of the room based on the bare JID
boolean hadAffiliation = room.getAffiliation(jid) != MUCRole.Affiliation.none;
presences.addAll(room.addMember(jid, nick, senderRole));
// If the user had an affiliation don’t send an invitation. Otherwise
// send an invitation if the room is members-only and skipping invites
// are not disabled system-wide xmpp.muc.skipInvite
if (!skipInvite && !hadAffiliation && room.isMembersOnly()) {
room.sendInvitation(jid, null, senderRole, null);
}
} else if (“outcast”.equals(target)) {
// Add the user as an outcast of the room based on the bare JID
presences.addAll(room.addOutcast(jid, item.elementTextTrim(“reason”), senderRole));
} else if (“none”.equals(target)) {
if (hasAffiliation) {
// Set that this jid has a NONE affiliation based on the bare JID
presences.addAll(room.addNone(jid, senderRole));
} else {
// Kick the user from the room
if (MUCRole.Role.moderator != senderRole.getRole()) {
throw new ForbiddenException();
}
presences.add(room.kickOccupant(jid, senderRole.getUserAddress(),
item.elementTextTrim(“reason”)));
}
} else {
reply.setError(PacketError.Condition.bad_request);
}
}
catch (UserNotFoundException e) {
// Do nothing
}
}
// Send the updated presences to the room occupants
for (Presence presence : presences) {
room.send(presence);
}
}
}
****and after patch
if (!hasJID && !hasNick) {
// The client is requesting the list of moderators/members/participants/outcasts
** Element result = reply.setChildElement(“query”, “http://jabber.org/protocol/muc#admin”);**
for (Object anItem : itemsList) {
item = (Element) anItem;
affiliation = item.attributeValue(“affiliation”);
roleAttribute = item.attributeValue(“role”);
// Create the result that will hold an item for each
// moderator/member/participant/outcast
Element metaData;
…