Commit 0f912735 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

Fixed storage of offline messages. JM-113


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@848 b35dd754-fafc-0310-a699-88a17e54d16e
parent 5d08dc6a
...@@ -17,11 +17,11 @@ import org.jivesoftware.util.*; ...@@ -17,11 +17,11 @@ import org.jivesoftware.util.*;
import org.jivesoftware.messenger.container.BasicModule; import org.jivesoftware.messenger.container.BasicModule;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.dom4j.io.SAXReader; import org.dom4j.io.SAXReader;
import org.dom4j.DocumentFactory;
import java.util.*; import java.util.*;
import java.sql.*; import java.sql.*;
import java.sql.Connection; import java.sql.Connection;
import java.io.StringReader;
/** /**
* Represents the user's offline message storage. A message store holds messages that were sent * Represents the user's offline message storage. A message store holds messages that were sent
...@@ -54,7 +54,6 @@ public class OfflineMessageStore extends BasicModule { ...@@ -54,7 +54,6 @@ public class OfflineMessageStore extends BasicModule {
} }
private SAXReader saxReader = new SAXReader(); private SAXReader saxReader = new SAXReader();
private DocumentFactory docFactory = new DocumentFactory();
public OfflineMessageStore() { public OfflineMessageStore() {
super("Offline Message Store"); super("Offline Message Store");
...@@ -70,7 +69,7 @@ public class OfflineMessageStore extends BasicModule { ...@@ -70,7 +69,7 @@ public class OfflineMessageStore extends BasicModule {
if (message == null) { if (message == null) {
return; return;
} }
String username = message.getFrom().getNode(); String username = message.getTo().getNode();
// If the username is null (such as when an anonymous user), don't store. // If the username is null (such as when an anonymous user), don't store.
if (username == null) { if (username == null) {
return; return;
...@@ -78,9 +77,8 @@ public class OfflineMessageStore extends BasicModule { ...@@ -78,9 +77,8 @@ public class OfflineMessageStore extends BasicModule {
long messageID = SequenceManager.nextID(JiveConstants.OFFLINE); long messageID = SequenceManager.nextID(JiveConstants.OFFLINE);
// Get the message in XML format. We add the element to a new document so // Get the message in XML format.
// that we can easily parse the message from the database later. String msgXML = message.getElement().asXML();
String msgXML = docFactory.createDocument(message.getElement()).asXML();
Connection con = null; Connection con = null;
PreparedStatement pstmt = null; PreparedStatement pstmt = null;
...@@ -124,7 +122,7 @@ public class OfflineMessageStore extends BasicModule { ...@@ -124,7 +122,7 @@ public class OfflineMessageStore extends BasicModule {
ResultSet rs = pstmt.executeQuery(); ResultSet rs = pstmt.executeQuery();
while (rs.next()) { while (rs.next()) {
String msgXML = rs.getString(1); String msgXML = rs.getString(1);
messages.add(new Message(saxReader.read(msgXML).getRootElement())); messages.add(new Message(saxReader.read(new StringReader(msgXML)).getRootElement()));
} }
rs.close(); rs.close();
pstmt.close(); pstmt.close();
......
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