Commit be32e4e8 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Refactoring work.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@590 b35dd754-fafc-0310-a699-88a17e54d16e
parent 7a6e9f40
...@@ -24,6 +24,10 @@ import java.util.List; ...@@ -24,6 +24,10 @@ import java.util.List;
import org.dom4j.DocumentHelper; import org.dom4j.DocumentHelper;
import org.dom4j.Element; import org.dom4j.Element;
import org.dom4j.QName; import org.dom4j.QName;
import org.xmpp.packet.IQ;
import org.xmpp.packet.PacketError;
import org.xmpp.packet.Presence;
import org.xmpp.packet.JID;
/** /**
* A handler for the IQ packet with namespace http://jabber.org/protocol/muc#admin. This kind of * A handler for the IQ packet with namespace http://jabber.org/protocol/muc#admin. This kind of
...@@ -68,7 +72,7 @@ public class IQAdminHandler { ...@@ -68,7 +72,7 @@ public class IQAdminHandler {
*/ */
public void handleIQ(IQ packet, MUCRole role) throws ForbiddenException, ConflictException, public void handleIQ(IQ packet, MUCRole role) throws ForbiddenException, ConflictException,
NotAllowedException { NotAllowedException {
IQ reply = packet.createResult(); IQ reply = IQ.createResultIQ(packet);
Element element = ((XMPPDOMFragment)packet.getChildFragment()).getRootElement(); Element element = ((XMPPDOMFragment)packet.getChildFragment()).getRootElement();
// Analyze the action to perform based on the included element // Analyze the action to perform based on the included element
...@@ -79,9 +83,9 @@ public class IQAdminHandler { ...@@ -79,9 +83,9 @@ public class IQAdminHandler {
else { else {
// An unknown and possibly incorrect element was included in the query // An unknown and possibly incorrect element was included in the query
// element so answer a BAD_REQUEST error // element so answer a BAD_REQUEST error
reply.setError(XMPPError.Code.BAD_REQUEST); reply.setError(PacketError.Condition.bad_request);
} }
if (reply.getRecipient() != null) { if (reply.getTo() != null) {
// Send a reply only if the sender of the original packet was from a real JID. (i.e. not // Send a reply only if the sender of the original packet was from a real JID. (i.e. not
// a packet generated locally) // a packet generated locally)
router.route(reply); router.route(reply);
...@@ -214,7 +218,7 @@ public class IQAdminHandler { ...@@ -214,7 +218,7 @@ public class IQAdminHandler {
} }
else { else {
// The client is modifying the list of moderators/members/participants/outcasts // The client is modifying the list of moderators/members/participants/outcasts
String jid = null; JID jid = null;
String nick; String nick;
String target = null; String target = null;
boolean hasAffiliation = ((Element) itemsList.get(0)).attributeValue("affiliation") != boolean hasAffiliation = ((Element) itemsList.get(0)).attributeValue("affiliation") !=
...@@ -232,12 +236,12 @@ public class IQAdminHandler { ...@@ -232,12 +236,12 @@ public class IQAdminHandler {
// jid could be of the form "full JID" or "bare JID" depending if we are // jid could be of the form "full JID" or "bare JID" depending if we are
// going to change a role or an affiliation // going to change a role or an affiliation
if (hasJID) { if (hasJID) {
jid = item.attributeValue("jid"); jid = new JID(item.attributeValue("jid"));
} }
else { else {
// Get the JID based on the requested nick // Get the JID based on the requested nick
nick = item.attributeValue("nick"); nick = item.attributeValue("nick");
jid = room.getOccupant(nick).getChatUser().getAddress().toStringPrep(); jid = room.getOccupant(nick).getChatUser().getAddress();
} }
room.lock.writeLock().lock(); room.lock.writeLock().lock();
...@@ -288,13 +292,13 @@ public class IQAdminHandler { ...@@ -288,13 +292,13 @@ public class IQAdminHandler {
if (MUCRole.MODERATOR != senderRole.getRole()) { if (MUCRole.MODERATOR != senderRole.getRole()) {
throw new ForbiddenException(); throw new ForbiddenException();
} }
presences.add(room.kickOccupant(jid, senderRole.getChatUser() presences.add(room.kickOccupant(jid,
.getAddress().toBareStringPrep(), item senderRole.getChatUser().getAddress(),
.elementTextTrim("reason"))); item.elementTextTrim("reason")));
} }
} }
else { else {
reply.setError(XMPPError.Code.BAD_REQUEST); reply.setError(PacketError.Condition.bad_request);
} }
} }
finally { finally {
......
...@@ -34,6 +34,8 @@ import org.jivesoftware.util.Log; ...@@ -34,6 +34,8 @@ import org.jivesoftware.util.Log;
import org.jivesoftware.messenger.*; import org.jivesoftware.messenger.*;
import org.jivesoftware.messenger.auth.UnauthorizedException; import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.handler.IQHandler; import org.jivesoftware.messenger.handler.IQHandler;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Presence;
/** /**
* This class is not an actual IQHandler since all the packets with namespace * This class is not an actual IQHandler since all the packets with namespace
...@@ -130,7 +132,7 @@ public class IQMUCRegisterHandler extends IQHandler { ...@@ -130,7 +132,7 @@ public class IQMUCRegisterHandler extends IQHandler {
return reply; return reply;
} }
if (IQ.GET.equals(packet.getType())) { if (IQ.Type.get == packet.getType()) {
reply = packet.createResult(); reply = packet.createResult();
String nickname = room.getReservedNickname(packet.getSender().toBareStringPrep()); String nickname = room.getReservedNickname(packet.getSender().toBareStringPrep());
if (nickname != null) { if (nickname != null) {
...@@ -148,7 +150,7 @@ public class IQMUCRegisterHandler extends IQHandler { ...@@ -148,7 +150,7 @@ public class IQMUCRegisterHandler extends IQHandler {
reply.setChildFragment(probeResult); reply.setChildFragment(probeResult);
} }
} }
else if (IQ.SET.equals(packet.getType())) { else if (IQ.Type.set == packet.getType()) {
try { try {
// Keep a registry of the updated presences // Keep a registry of the updated presences
List<Presence> presences = new ArrayList<Presence>(); List<Presence> presences = new ArrayList<Presence>();
......
...@@ -203,7 +203,7 @@ public class MUCPersistenceManager { ...@@ -203,7 +203,7 @@ public class MUCPersistenceManager {
// possible // possible
if (!room.getRoomHistory().hasChangedSubject() && room.getSubject() != null && if (!room.getRoomHistory().hasChangedSubject() && room.getSubject() != null &&
room.getSubject().length() > 0) { room.getSubject().length() > 0) {
room.getRoomHistory().addOldMessage(room.getRole().getRoleAddress().toStringPrep(), room.getRoomHistory().addOldMessage(room.getRole().getRoleAddress().toString(),
null, room.getModificationDate(), room.getSubject(), null); null, room.getModificationDate(), room.getSubject(), null);
} }
...@@ -449,7 +449,7 @@ public class MUCPersistenceManager { ...@@ -449,7 +449,7 @@ public class MUCPersistenceManager {
loadedRoom.getSubject() != null && loadedRoom.getSubject() != null &&
loadedRoom.getSubject().length() > 0) { loadedRoom.getSubject().length() > 0) {
loadedRoom.getRoomHistory().addOldMessage(loadedRoom.getRole().getRoleAddress() loadedRoom.getRoomHistory().addOldMessage(loadedRoom.getRole().getRoleAddress()
.toStringPrep(), null, .toString(), null,
loadedRoom.getModificationDate(), loadedRoom.getSubject(), null); loadedRoom.getModificationDate(), loadedRoom.getSubject(), null);
} }
} }
...@@ -781,7 +781,7 @@ public class MUCPersistenceManager { ...@@ -781,7 +781,7 @@ public class MUCPersistenceManager {
con = DbConnectionManager.getConnection(); con = DbConnectionManager.getConnection();
pstmt = con.prepareStatement(ADD_CONVERSATION_LOG); pstmt = con.prepareStatement(ADD_CONVERSATION_LOG);
pstmt.setLong(1, entry.getRoomID()); pstmt.setLong(1, entry.getRoomID());
pstmt.setString(2, entry.getSender().toStringPrep()); pstmt.setString(2, entry.getSender().toString());
pstmt.setString(3, entry.getNickname()); pstmt.setString(3, entry.getNickname());
pstmt.setString(4, StringUtils.dateToMillis(entry.getDate())); pstmt.setString(4, StringUtils.dateToMillis(entry.getDate()));
pstmt.setString(5, entry.getSubject()); pstmt.setString(5, entry.getSubject());
......
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