Commit 4cba0c1b authored by Matt Tucker's avatar Matt Tucker Committed by matt

Refactoring work.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@608 b35dd754-fafc-0310-a699-88a17e54d16e
parent 0b3caaf6
......@@ -15,9 +15,9 @@ import org.jivesoftware.messenger.container.BasicModule;
import org.jivesoftware.database.DbConnectionManager;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.LocaleUtils;
import org.jivesoftware.util.XPPReader;
import org.dom4j.Element;
import org.dom4j.Document;
import org.dom4j.io.SAXReader;
import java.sql.*;
import java.sql.Connection;
......@@ -46,6 +46,8 @@ public class PrivateStorage extends BasicModule {
private boolean enabled = JiveGlobals.getBooleanProperty("xmpp.privateStorageEnabled", true);
SAXReader xmlReader = new SAXReader();
/**
* Constructs a new PrivateStore instance.
*/
......@@ -148,8 +150,8 @@ public class PrivateStorage extends BasicModule {
pstmt.setString(2, data.getNamespaceURI());
ResultSet rs = pstmt.executeQuery();
if (rs.next()) {
StringReader reader = new StringReader(rs.getString(1).trim());
Document doc = XPPReader.parseDocument(reader, this.getClass());
String result = rs.getString(1).trim();
Document doc = xmlReader.read(result);
data = doc.getRootElement();
}
rs.close();
......
......@@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.dom4j.Document;
import org.dom4j.io.SAXReader;
/**
* <p>The initial container that hosts all other modules (and containers).</p>
......@@ -503,13 +504,12 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
try {
in = getClass().getResourceAsStream("/messenger_init.xml");
if (in != null) {
Document doc = XPPReader.parseDocument(new InputStreamReader(in),
this.getClass());
SAXReader reader = new SAXReader();
Document doc = reader.read(in);
String path = doc.getRootElement().getText();
try {
if (path != null) {
messengerHome = verifyHome(path,
jiveConfigName);
messengerHome = verifyHome(path, jiveConfigName);
}
}
catch (FileNotFoundException fe) {
......@@ -522,11 +522,7 @@ public abstract class BootstrapContainer implements Container, ServiceLookupProv
e.printStackTrace();
}
finally {
try {
if (in != null) {
in.close();
}
}
try { if (in != null) { in.close(); } }
catch (Exception e) {
System.err.println("Could not close open connection");
e.printStackTrace();
......
......@@ -36,6 +36,7 @@ import org.jivesoftware.messenger.auth.UnauthorizedException;
import org.jivesoftware.messenger.handler.IQHandler;
import org.xmpp.packet.IQ;
import org.xmpp.packet.Presence;
import org.xmpp.packet.PacketError;
/**
* This class is not an actual IQHandler since all the packets with namespace
......@@ -54,7 +55,7 @@ import org.xmpp.packet.Presence;
*/
public class IQMUCRegisterHandler extends IQHandler {
private static MetaDataFragment probeResult;
private static Element probeResult;
private IQHandlerInfo info;
private MultiUserChatServer mucServer;
......@@ -115,30 +116,29 @@ public class IQMUCRegisterHandler extends IQHandler {
registrationForm.addField(field);
// Create the probeResult and add the basic info together with the registration form
probeResult = new MetaDataFragment(element);
probeResult.addFragment(registrationForm);
probeResult = element;
probeResult.add(registrationForm.asXMLElement());
}
}
public IQ handleIQ(IQ packet) throws UnauthorizedException, XMLStreamException {
Session session = packet.getOriginatingSession();
public IQ handleIQ(IQ packet) throws UnauthorizedException {
Session session = SessionManager.getInstance().getSession(packet.getFrom());
IQ reply = null;
// Get the target room
MUCRoom room = mucServer.getChatRoom(packet.getRecipient().getNamePrep());
MUCRoom room = mucServer.getChatRoom(packet.getTo().getNode());
if (room == null) {
// The room doesn't exist so answer a NOT_FOUND error
reply = packet.createResult();
reply.setError(XMPPError.Code.NOT_FOUND);
reply = IQ.createResultIQ(packet);
reply.setError(PacketError.Condition.item_not_found);
return reply;
}
if (IQ.Type.get == packet.getType()) {
reply = packet.createResult();
String nickname = room.getReservedNickname(packet.getSender().toBareStringPrep());
reply = IQ.createResultIQ(packet);
String nickname = room.getReservedNickname(packet.getFrom().toBareJID());
if (nickname != null) {
// The user is already registered with the room so answer a completed form
MetaDataFragment currentRegistration = (MetaDataFragment) probeResult
.createDeepCopy();
Element currentRegistration = probeResult.createCopy();
currentRegistration.setProperty("query.registered", null);
XDataFormImpl form = (XDataFormImpl) currentRegistration.getFragment("x",
"jabber:x:data");
......
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