|
7 | 7 | import com.reucon.openfire.plugin.archive.model.Participant;
|
8 | 8 | import com.reucon.openfire.plugin.archive.util.StanzaIDUtil;
|
9 | 9 | import com.reucon.openfire.plugin.archive.xep0059.XmppResultSet;
|
10 |
| -import org.dom4j.Document; |
11 |
| -import org.dom4j.DocumentFactory; |
12 |
| -import org.dom4j.DocumentHelper; |
13 |
| -import org.dom4j.Element; |
| 10 | +import org.dom4j.*; |
14 | 11 | import org.jivesoftware.database.DbConnectionManager;
|
15 | 12 | import org.jivesoftware.openfire.archive.ConversationManager;
|
16 | 13 | import org.jivesoftware.util.JiveConstants;
|
|
31 | 28 | */
|
32 | 29 | public class JdbcPersistenceManager implements PersistenceManager {
|
33 | 30 | private static final Logger Log = LoggerFactory.getLogger( JdbcPersistenceManager.class );
|
34 |
| - protected static final DocumentFactory docFactory = DocumentFactory.getInstance(); |
35 | 31 | public static final int DEFAULT_MAX = 1000;
|
36 | 32 |
|
37 | 33 | public static final String SELECT_MESSAGES_BY_CONVERSATION = "SELECT DISTINCT ofConversation.conversationID, ofConversation.room, "
|
@@ -474,7 +470,7 @@ public Conversation getConversation(JID owner, JID with, Date start) {
|
474 | 470 | message = extractMessage(rs);
|
475 | 471 | conversation.addMessage(message);
|
476 | 472 | }
|
477 |
| - } catch (SQLException sqle) { |
| 473 | + } catch (SQLException | DocumentException sqle) { |
478 | 474 | Log.error("Error selecting conversation", sqle);
|
479 | 475 | } finally {
|
480 | 476 | DbConnectionManager.closeConnection(rs, pstmt, con);
|
@@ -542,7 +538,7 @@ private Collection<Participant> extractParticipant(ResultSet rs) throws SQLExcep
|
542 | 538 | return participants;
|
543 | 539 | }
|
544 | 540 |
|
545 |
| - static ArchivedMessage extractMessage(ResultSet rs) throws SQLException { |
| 541 | + static ArchivedMessage extractMessage(ResultSet rs) throws SQLException, DocumentException { |
546 | 542 | Date time = millisToDate(rs.getLong("sentDate"));
|
547 | 543 | String body = rs.getString("body");
|
548 | 544 | String stanza = rs.getString("stanza");
|
@@ -604,46 +600,26 @@ public static ArchivedMessage getArchivedMessage( long messageId, JID owner )
|
604 | 600 | } catch (SQLException ex) {
|
605 | 601 | Log.warn("SQL failure while trying to get message with ID {} from the archive of {}.", messageId, owner, ex);
|
606 | 602 | return null;
|
| 603 | + } catch (DocumentException ex) { |
| 604 | + Log.warn("Failure to parse 'stanza' value as XMPP for the message with ID {} from the archive of {}.", messageId, owner, ex); |
| 605 | + return null; |
607 | 606 | } finally {
|
608 | 607 | DbConnectionManager.closeConnection(rs, pstmt, connection);
|
609 | 608 | }
|
610 | 609 | }
|
611 | 610 |
|
612 |
| - static protected ArchivedMessage asArchivedMessage(JID owner, String fromJID, String fromJIDResource, String toJID, String toJIDResource, Date sentDate, String body, String stanza, Long id) |
613 |
| - { |
614 |
| - if (stanza == null) { |
615 |
| - Message message = new Message(); |
616 |
| - message.setFrom(fromJID); |
617 |
| - message.setTo(toJID); |
618 |
| - message.setType(Message.Type.normal); |
619 |
| - message.setBody(body); |
620 |
| - stanza = message.toString(); |
621 |
| - } |
622 |
| - |
| 611 | + static protected ArchivedMessage asArchivedMessage(JID owner, String fromJID, String fromJIDResource, String toJID, String toJIDResource, Date sentDate, String body, String stanza, Long id) throws DocumentException { |
623 | 612 | String sid;
|
624 |
| - try |
625 |
| - { |
626 |
| - if ( !JiveGlobals.getBooleanProperty( "conversation.OF-1804.disable", false ) ) |
627 |
| - { |
628 |
| - // Prior to OF-1804 (Openfire 4.4.0), the stanza was logged with a formatter applied. |
629 |
| - // This causes message formatting to be modified (notably, new lines could be altered). |
630 |
| - // This workaround restores the original body text, that was stored in a different column. |
631 |
| - final int pos1 = stanza.indexOf( "<body>" ); |
632 |
| - final int pos2 = stanza.indexOf( "</body>" ); |
633 |
| - |
634 |
| - if ( pos1 > -1 && pos2 > -1 ) |
635 |
| - { |
636 |
| - // Add the body value to a proper XML element, so that the strings get XML encoded (eg: ampersand is escaped). |
637 |
| - final Element bodyEl = docFactory.createDocument().addElement("body"); |
638 |
| - bodyEl.setText(body); |
639 |
| - stanza = stanza.substring( 0, pos1 ) + bodyEl.asXML() + stanza.substring( pos2 + 7 ); |
640 |
| - } |
| 613 | + if (stanza != null) { |
| 614 | + try { |
| 615 | + final Document doc = DocumentHelper.parseText(stanza); |
| 616 | + final Message message = new Message(doc.getRootElement()); |
| 617 | + sid = StanzaIDUtil.findFirstUniqueAndStableStanzaID(message, owner.toBareJID()); |
| 618 | + } catch (Exception e) { |
| 619 | + Log.warn("An exception occurred while parsing message with ID {}", id, e); |
| 620 | + sid = null; |
641 | 621 | }
|
642 |
| - final Document doc = DocumentHelper.parseText( stanza ); |
643 |
| - final Message message = new Message( doc.getRootElement() ); |
644 |
| - sid = StanzaIDUtil.findFirstUniqueAndStableStanzaID( message, owner.toBareJID() ); |
645 |
| - } catch ( Exception e ) { |
646 |
| - Log.warn( "An exception occurred while parsing message with ID {}", id, e ); |
| 622 | + } else { |
647 | 623 | sid = null;
|
648 | 624 | }
|
649 | 625 |
|
|
0 commit comments