diff options
6 files changed, 80 insertions, 7 deletions
diff --git a/src/net/java/sip/communicator/impl/history/HistoryServiceImpl.java b/src/net/java/sip/communicator/impl/history/HistoryServiceImpl.java index 370558b..629a860 100644 --- a/src/net/java/sip/communicator/impl/history/HistoryServiceImpl.java +++ b/src/net/java/sip/communicator/impl/history/HistoryServiceImpl.java @@ -335,6 +335,14 @@ public class HistoryServiceImpl } /** + * Clears locally(in memory) cached histories. + */ + public void purgeLocallyCachedHistories() + { + histories.clear(); + } + + /** * Checks the ids of the parent, do they exist in the supplied history ids. * If it exist the history is sub history of the on with the supplied ids. * @param parentIDs the parent ids diff --git a/src/net/java/sip/communicator/impl/history/HistoryWriterImpl.java b/src/net/java/sip/communicator/impl/history/HistoryWriterImpl.java index be70067..b36e791 100644 --- a/src/net/java/sip/communicator/impl/history/HistoryWriterImpl.java +++ b/src/net/java/sip/communicator/impl/history/HistoryWriterImpl.java @@ -20,6 +20,8 @@ import net.java.sip.communicator.service.history.records.*; import org.jitsi.util.xml.XMLUtils; import org.w3c.dom.*; +import com.google.common.xml.*; + /** * @author Alexander Pelov */ @@ -122,13 +124,17 @@ public class HistoryWriterImpl { if (propertyValues[i] != null) { - propertyName = propertyName.replaceFirst(CDATA_SUFFIX, ""); + propertyName = + propertyName.replaceFirst(CDATA_SUFFIX, ""); Element propertyElement = this.currentDoc .createElement(propertyName); Text value = this.currentDoc - .createCDATASection(propertyValues[i].replaceAll("\0", " ")); + .createCDATASection( + XmlEscapers.xmlContentEscaper().escape( + propertyValues[i].replaceAll("\0", " ") + )); propertyElement.appendChild(value); elem.appendChild(propertyElement); @@ -142,7 +148,10 @@ public class HistoryWriterImpl .createElement(propertyName); Text value = this.currentDoc - .createTextNode(propertyValues[i].replaceAll("\0", " ")); + .createTextNode( + XmlEscapers.xmlContentEscaper().escape( + propertyValues[i].replaceAll("\0", " ") + )); propertyElement.appendChild(value); elem.appendChild(propertyElement); @@ -217,8 +226,8 @@ public class HistoryWriterImpl } /** - * Updates a record by searching for record with idProperty which have idValue - * and updating/creating the property with newValue. + * Updates a record by searching for record with idProperty which have + * idValue and updating/creating the property with newValue. * * @param idProperty name of the id property * @param idValue value of the id property diff --git a/src/net/java/sip/communicator/impl/history/history.manifest.mf b/src/net/java/sip/communicator/impl/history/history.manifest.mf index 9d9cb8a..9918d34 100644 --- a/src/net/java/sip/communicator/impl/history/history.manifest.mf +++ b/src/net/java/sip/communicator/impl/history/history.manifest.mf @@ -10,6 +10,8 @@ Import-Package: org.osgi.framework, org.jitsi.util.xml, net.java.sip.communicator.service.history, net.java.sip.communicator.service.history.records, + com.google.common.escape, + com.google.common.xml, org.w3c.dom, org.xml.sax, javax.xml.parsers, diff --git a/src/net/java/sip/communicator/service/history/HistoryService.java b/src/net/java/sip/communicator/service/history/HistoryService.java index b073eb5..d211fbc 100644 --- a/src/net/java/sip/communicator/service/history/HistoryService.java +++ b/src/net/java/sip/communicator/service/history/HistoryService.java @@ -79,7 +79,7 @@ public interface HistoryService { throws IllegalArgumentException, IOException; /** - * Permamently removes local stored History + * Permanently removes local stored History * * @param id HistoryID * @throws IOException @@ -87,6 +87,12 @@ public interface HistoryService { */ public void purgeLocallyStoredHistory(HistoryID id) throws IOException; + + /** + * Clears locally(in memory) cached histories. + */ + public void purgeLocallyCachedHistories(); + /** * Moves the content of oldId history to the content of the newId. * diff --git a/test/net/java/sip/communicator/slick/msghistory/TestMsgHistoryService.java b/test/net/java/sip/communicator/slick/msghistory/TestMsgHistoryService.java index 7e8ba1a..6377a68 100644 --- a/test/net/java/sip/communicator/slick/msghistory/TestMsgHistoryService.java +++ b/test/net/java/sip/communicator/slick/msghistory/TestMsgHistoryService.java @@ -11,6 +11,7 @@ import java.util.*; import junit.framework.*; import net.java.sip.communicator.impl.protocol.mock.*; import net.java.sip.communicator.service.contactlist.*; +import net.java.sip.communicator.service.history.*; import net.java.sip.communicator.service.msghistory.*; import net.java.sip.communicator.service.protocol.*; import net.java.sip.communicator.service.protocol.event.*; @@ -18,6 +19,8 @@ import net.java.sip.communicator.util.*; import org.osgi.framework.*; +import com.google.common.xml.*; + /** * Tests message history. * First installs the MoxkProtocolProvider to be able to send some messages @@ -53,6 +56,8 @@ public class TestMsgHistoryService private static ServiceReference msgHistoryServiceRef = null; public static MessageHistoryService msgHistoryService = null; + public static HistoryService historyService = null; + private static MockContact testContact = null; private static ServiceReference metaCLref = null; @@ -138,6 +143,14 @@ public class TestMsgHistoryService (MessageHistoryService)MsgHistoryServiceLick.bc. getService(msgHistoryServiceRef); + ServiceReference historyServiceRef = + MsgHistoryServiceLick.bc. + getServiceReference(HistoryService.class.getName()); + + historyService = + (HistoryService)MsgHistoryServiceLick.bc. + getService(historyServiceRef); + // fill in a contact to comunicate with MockContactGroup root = (MockContactGroup)mockPresOpSet.getServerStoredContactListRoot(); @@ -180,7 +193,8 @@ public class TestMsgHistoryService mockBImOpSet.createMessage("test message word2" + Math.random()), mockBImOpSet.createMessage("test message word3" + Math.random()), mockBImOpSet.createMessage("test message word4" + Math.random()), - mockBImOpSet.createMessage("test message word5" + Math.random()) + mockBImOpSet.createMessage("test message word5" + Math.random()), + mockBImOpSet.createMessage("Hello \u0002World\u0002!") }; } @@ -380,6 +394,38 @@ public class TestMsgHistoryService msgs.contains(messagesToSend[2].getContent())); } + /** + * Tests some special chars insert and read. + */ + public void specialChars() + { + mockBImOpSet.deliverMessage(TEST_CONTACT_NAME_1, messagesToSend[5]); + + waitWrite(500); + + historyService.purgeLocallyCachedHistories(); + + /** + * Must return exactly the last 3 messages + */ + Collection<EventObject> rs + = msgHistoryService.findLast(testMetaContact, 3); + + assertTrue("Nothing found 8", !rs.isEmpty()); + List<String> msgs = getMessages(rs); + assertEquals("Messages must be 3", 3, msgs.size()); + assertTrue("Message no found", + msgs.contains(messagesToSend[3].getContent())); + assertTrue("Message no found", + msgs.contains(messagesToSend[4].getContent())); + + // For now we are stripping in history the special content chars + // in order to avoid breaking the history records in the xml + assertTrue("Message no found", + msgs.contains(XmlEscapers.xmlContentEscaper().escape( + messagesToSend[5].getContent()))); + } + private static void waitWrite(long timeout) { synchronized (lock) diff --git a/test/net/java/sip/communicator/slick/msghistory/msghistory.slick.manifest.mf b/test/net/java/sip/communicator/slick/msghistory/msghistory.slick.manifest.mf index 4cf11fc..f571a5e 100644 --- a/test/net/java/sip/communicator/slick/msghistory/msghistory.slick.manifest.mf +++ b/test/net/java/sip/communicator/slick/msghistory/msghistory.slick.manifest.mf @@ -13,6 +13,8 @@ Import-Package: junit.framework, net.java.sip.communicator.impl.protocol.mock, net.java.sip.communicator.service.protocol, net.java.sip.communicator.service.protocol.event,org.jitsi.service.protocol.event, + com.google.common.xml, + com.google.common.escape, org.osgi.framework, org.w3c.dom, javax.xml.parsers, |