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

Refactoring fixes.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@644 b35dd754-fafc-0310-a699-88a17e54d16e
parent ee482ec7
......@@ -592,6 +592,12 @@ public class IQOwnerHandler {
for (String jid : room.getOwners()) {
field.addValue(jid);
}
// Remove the old element
probeResult.remove(probeResult.element(QName.get("x", "jabber:x:data")));
// Add the new representation of configurationForm as an element
probeResult.add(configurationForm.asXMLElement());
}
finally {
room.lock.readLock().unlock();
......
......@@ -13,6 +13,7 @@ package org.jivesoftware.messenger.muc.spi;
import org.dom4j.Element;
import org.dom4j.DocumentHelper;
import org.dom4j.QName;
import org.jivesoftware.messenger.PacketRouter;
import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.muc.MUCRole;
......@@ -108,7 +109,8 @@ public class MUCRoleImpl implements MUCRole {
this.router = packetRouter;
this.role = role;
this.affiliation = affiliation;
extendedInformation = DocumentHelper.createElement("x").addNamespace("", "http://jabber.org/protocol/muc#user");
extendedInformation =
DocumentHelper.createElement(QName.get("x", "http://jabber.org/protocol/muc#user"));
calculateExtendedInformation();
rJID = new JID(room.getName(), server.getServiceName(), nick);
setPresence(room.createPresence(null));
......
......@@ -501,7 +501,7 @@ public class MUCRoomImpl implements MUCRoom {
if (isRoomNew) {
Element frag = joinPresence.getChildElement(
"x", "http://jabber.org/protocol/muc#user");
frag.element("status").addAttribute("code", "201");
frag.addElement("status").addAttribute("code", "201");
}
joinPresence.setFrom(joinRole.getRoleAddress());
broadcastPresence(joinPresence);
......@@ -648,11 +648,7 @@ public class MUCRoomImpl implements MUCRoom {
if (destroy == null) {
destroy = fragment.addElement("destroy");
}
Element reasonEl = destroy.element("reason");
if (reasonEl == null) {
reasonEl = destroy.addElement("reason");
}
reasonEl.setText(reason);
destroy.addElement("reason").setText(reason);
}
router.route(presence);
......@@ -915,14 +911,12 @@ public class MUCRoomImpl implements MUCRoom {
throws NotAllowedException {
List<Presence> presences = new ArrayList<Presence>();
// Get all the roles (i.e. occupants) of this user based on his/her bare JID
List roles = occupantsByBareJID.get(bareJID);
List<MUCRole> roles = occupantsByBareJID.get(bareJID);
if (roles == null) {
return presences;
}
MUCRole role;
// Collect all the updated presences of these roles
for (Iterator it = roles.iterator(); it.hasNext();) {
role = (MUCRole) it.next();
for (MUCRole role : roles) {
// Update the presence with the new affiliation and role
role.setAffiliation(newAffiliation);
role.setRole(newRole);
......@@ -1125,19 +1119,16 @@ public class MUCRoomImpl implements MUCRoom {
bareJID,
MUCRole.OUTCAST,
MUCRole.NONE_ROLE);
if (!updatedPresences.isEmpty()) {
Presence presence;
Element frag;
// Add the status code and reason why the user was banned to the presences that will
// be sent to the room occupants (the banned user will not receive this presences)
for (Iterator it = updatedPresences.iterator(); it.hasNext();) {
presence = (Presence) it.next();
for (Presence presence : updatedPresences) {
frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
// Add the status code 301 that indicates that the user was banned
frag.element("status").addAttribute("code", "301");
frag.addElement("status").addAttribute("code", "301");
// Add the reason why the user was banned
if (reason != null && reason.trim().length() > 0) {
frag.element("item").element("reason").setText(reason);
frag.element("item").addElement("reason").setText(reason);
}
// Remove the banned users from the room. If a user has joined the room from
......@@ -1145,7 +1136,6 @@ public class MUCRoomImpl implements MUCRoom {
// Effectively kick the occupant from the room
kickPresence(presence, actorJID);
}
}
// Update the affiliation lists
outcasts.add(bareJID);
// Remove the user from other affiliation lists
......@@ -1216,25 +1206,22 @@ public class MUCRoomImpl implements MUCRoom {
// If the room is members-only, remove the user from the room including a status
// code of 321 to indicate that the user was removed because of an affiliation
// change
Presence presence;
Element frag;
// Add the status code to the presences that will be sent to the room occupants
for (Iterator it = updatedPresences.iterator(); it.hasNext();) {
presence = (Presence) it.next();
for (Presence presence : updatedPresences) {
// Set the presence as an unavailable presence
presence.setType(Presence.Type.unavailable);
frag = presence.getChildElement("x", "http://jabber.org/protocol/muc#user");
// Add the status code 321 that indicates that the user was removed because of
// an affiliation change
frag.element("status").addAttribute("code", "321");
frag.addElement("status").addAttribute("code", "321");
// Remove the ex-member from the room. If a user has joined the room from
// different client resources, he/she will be kicked from all the client
// resources.
// Effectively kick the occupant from the room
MUCUser senderUser = senderRole.getChatUser();
JID actorJID = (senderUser == null ?
null : senderUser.getAddress());
JID actorJID = (senderUser == null ? null : senderUser.getAddress());
kickPresence(presence, actorJID);
}
}
......@@ -1415,15 +1402,7 @@ public class MUCRoomImpl implements MUCRoom {
"x", "http://jabber.org/protocol/muc#user");
// Add the reason why the user was granted voice
if (reason != null && reason.trim().length() > 0) {
Element item = frag.element("item");
if (item == null) {
item = frag.addElement("item");
}
Element reasonEl = item.element("reason");
if (reasonEl == null) {
reasonEl = item.addElement("reason");
}
reasonEl.setText(reason);
frag.element("item").addElement("reason").setText(reason);
}
}
return updatedPresence;
......@@ -1446,22 +1425,10 @@ public class MUCRoomImpl implements MUCRoom {
"x", "http://jabber.org/protocol/muc#user");
// Add the status code 307 that indicates that the user was kicked
Element status = frag.element("status");
if (status == null) {
status = frag.addElement("status");
}
status.addAttribute("code", "307");
frag.addElement("status").addAttribute("code", "307");
// Add the reason why the user was kicked
if (reason != null && reason.trim().length() > 0) {
Element item = frag.element("item");
if (item == null) {
item = frag.addElement("item");
}
Element reasonEl = item.element("reason");
if (reasonEl == null) {
reasonEl = item.addElement("reason");
}
reasonEl.setText(reason);
frag.element("item").addElement("reason").setText(reason);
}
// Effectively kick the occupant from the room
......@@ -1489,15 +1456,7 @@ public class MUCRoomImpl implements MUCRoom {
if (actorJID != null && actorJID.toString().length() > 0) {
Element frag = kickPresence.getChildElement(
"x", "http://jabber.org/protocol/muc#user");
Element item = frag.element("item");
if (item == null) {
frag.addElement("item");
}
Element actor = item.element("actor");
if (actor == null) {
actor = item.addElement("actor");
}
actor.addAttribute("jid", actorJID.toString());
frag.element("item").addElement("actor").addAttribute("jid", actorJID.toString());
}
// Send the unavailable presence to the banned user
kickedRole.send(kickPresence);
......
......@@ -289,14 +289,13 @@ public class MUCUserImpl implements MUCUser {
}
else {
try {
if ("query".equals(packet.getElement().getNamespacePrefix())
&& "http://jabber.org/protocol/muc#owner".equals(packet
.getElement().getNamespaceURI())) {
Element query = packet.getElement().element("query");
if (query != null &&
"http://jabber.org/protocol/muc#owner".equals(query.getNamespaceURI())) {
role.getChatRoom().getIQOwnerHandler().handleIQ(packet, role);
}
else if ("query".equals(packet.getElement().getNamespacePrefix())
&& "http://jabber.org/protocol/muc#admin".equals(packet
.getElement().getNamespaceURI())) {
else if (query != null &&
"http://jabber.org/protocol/muc#admin".equals(query.getNamespaceURI())) {
role.getChatRoom().getIQAdminHandler().handleIQ(packet, role);
}
else {
......
......@@ -64,7 +64,8 @@ public class ElementUtil {
}
// Search for this property by traversing down the XML hierarchy.
for (int i = 0; i < propName.length; i++) {
int i = propName[0].equals(element.getName()) ? 1 : 0;
for (; i < propName.length; i++) {
element = element.element(propName[i]);
if (element == null) {
break;
......@@ -105,7 +106,8 @@ public class ElementUtil {
}
// Search for this property by traversing down the XML hierarchy.
for (int i = 0; i < propName.length; i++) {
int i = propName[0].equals(element.getName()) ? 1 : 0;
for (; i < propName.length; i++) {
element = element.element(propName[i]);
if (element == null) {
break;
......@@ -113,8 +115,13 @@ public class ElementUtil {
}
if (element != null) {
if (attName == null){
// The property exists so return true
return true;
} else {
// The property exists if the attribute exists in the element
return element.attribute(attName) != null;
}
}
else {
// The property does not exist so return false
......@@ -150,7 +157,8 @@ public class ElementUtil {
String[] propName = parsePropertyName(name);
// Search for this property by traversing down the XML heirarchy, stopping one short.
for (int i = 0; i < propName.length - 1; i++) {
int i = propName[0].equals(element.getName()) ? 1 : 0;
for (; i < propName.length - 1; i++) {
element = element.element(propName[i]);
if (element == null) {
// This node doesn't match this part of the property name which
......@@ -191,9 +199,10 @@ public class ElementUtil {
public static void setProperties(Element element, String name, String[] values) {
String[] propName = parsePropertyName(name);
setProperty(element, name, values[0]);
// Search for this property by traversing down the XML heirarchy, stopping one short.
for (int i = 0; i < propName.length - 1; i++) {
// Search for this property by traversing down the XML heirarchy, stopping one short.
int i = propName[0].equals(element.getName()) ? 1 : 0;
for (; i < propName.length - 1; i++) {
element = element.element(propName[i]);
if (element == null) {
// This node doesn't match this part of the property name which
......@@ -207,9 +216,9 @@ public class ElementUtil {
while (iter.hasNext()) {
((Node) iter.next()).detach();
}
for (int i = 0; i < values.length; i++) {
if (values[i] != null) {
element.addElement(childName).setText(values[i]);
for (int j = 0; i < values.length; i++) {
if (values[j] != null) {
element.addElement(childName).setText(values[j]);
}
}
}
......@@ -229,7 +238,8 @@ public class ElementUtil {
String[] propName = parsePropertyName(parent);
// Search for this property by traversing down the XML heirarchy.
for (int i = 0; i < propName.length; i++) {
int i = propName[0].equals(element.getName()) ? 1 : 0;
for (; i < propName.length; i++) {
element = element.element(propName[i]);
if (element == null) {
// This node doesn't match this part of the property name which
......@@ -241,8 +251,8 @@ public class ElementUtil {
List children = element.elements();
int childCount = children.size();
String[] childrenNames = new String[childCount];
for (int i = 0; i < childCount; i++) {
childrenNames[i] = ((Element) children.get(i)).getName();
for (int j = 0; i < childCount; i++) {
childrenNames[j] = ((Element) children.get(j)).getName();
}
return childrenNames;
}
......@@ -280,13 +290,14 @@ public class ElementUtil {
* @param value the new value for the property.
*/
public static void setProperty(Element element, String name, String value) {
if (name == null) return;
if (name == null || name.length() == 0) return;
if (value == null) value = "";
String[] propName = parsePropertyName(name);
// Search for this property by traversing down the XML heirarchy.
for (int i = 0; i < propName.length - 1; i++) {
int i = propName[0].equals(element.getName()) ? 1 : 0;
for (; i < propName.length - 1; i++) {
// If we don't find this part of the property in the XML heirarchy
// we add it as a new node
if (element.element(propName[i]) == null) {
......
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