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