aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/history
diff options
context:
space:
mode:
authorYana Stamcheva <yana@jitsi.org>2009-06-25 15:32:01 +0000
committerYana Stamcheva <yana@jitsi.org>2009-06-25 15:32:01 +0000
commit71d51b2b03c10f07c6b4e4b1f3f66f5cd24064ae (patch)
treeee523c55087f03c0035efaa3e4e53360315c282c /src/net/java/sip/communicator/impl/history
parent206ea67e27a168ac11d6e3e801892a8d73a17e3a (diff)
downloadjitsi-71d51b2b03c10f07c6b4e4b1f3f66f5cd24064ae.zip
jitsi-71d51b2b03c10f07c6b4e4b1f3f66f5cd24064ae.tar.gz
jitsi-71d51b2b03c10f07c6b4e4b1f3f66f5cd24064ae.tar.bz2
- Possibility added to update history records - provided by Damian Minkov.
- File transfer dates fixed. - File transfer history improved. - Check for active file transfers before closing the chat window.
Diffstat (limited to 'src/net/java/sip/communicator/impl/history')
-rw-r--r--src/net/java/sip/communicator/impl/history/HistoryWriterImpl.java94
1 files changed, 92 insertions, 2 deletions
diff --git a/src/net/java/sip/communicator/impl/history/HistoryWriterImpl.java b/src/net/java/sip/communicator/impl/history/HistoryWriterImpl.java
index b779a78..448fb1f 100644
--- a/src/net/java/sip/communicator/impl/history/HistoryWriterImpl.java
+++ b/src/net/java/sip/communicator/impl/history/HistoryWriterImpl.java
@@ -11,14 +11,17 @@ import java.security.*;
import java.util.*;
import org.w3c.dom.*;
+
import net.java.sip.communicator.service.history.*;
import net.java.sip.communicator.service.history.records.*;
+import net.java.sip.communicator.util.xml.*;
/**
* @author Alexander Pelov
*/
-public class HistoryWriterImpl implements HistoryWriter {
-
+public class HistoryWriterImpl
+ implements HistoryWriter
+{
public static final int MAX_RECORDS_PER_FILE = 150;
private static final String CDATA_SUFFIX = "_CDATA";
@@ -204,4 +207,91 @@ public class HistoryWriterImpl implements HistoryWriter {
.getChildNodes().getLength();
}
+ /**
+ * 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
+ * @param property the property to change
+ * @param newValue the value of the changed property.
+ */
+ public void updateRecord(String idProperty, String idValue,
+ String property, String newValue)
+ throws IOException
+ {
+ Iterator<String> fileIterator = this.historyImpl.getFileList();
+
+ while (fileIterator.hasNext())
+ {
+ String filename = fileIterator.next();
+
+ Document doc = this.historyImpl.getDocumentForFile(filename);
+
+ if(doc == null)
+ continue;
+
+ NodeList nodes = doc.getElementsByTagName("record");
+
+ boolean changed = false;
+
+ Node node;
+ for (int i = 0; i < nodes.getLength(); i++)
+ {
+ node = nodes.item(i);
+
+ Element idNode = XMLUtils.findChild((Element)node, idProperty);
+ if(idNode == null)
+ continue;
+
+ Node nestedNode = idNode.getFirstChild();
+ if(nestedNode == null)
+ continue;
+
+ // Get nested TEXT node's value
+ String nodeValue = nestedNode.getNodeValue();
+
+ if(!nodeValue.equals(idValue))
+ continue;
+
+ Element changedNode =
+ XMLUtils.findChild((Element)node, property);
+
+ if(changedNode != null)
+ {
+ Node changedNestedNode = changedNode.getFirstChild();
+
+ changedNestedNode.setNodeValue(newValue);
+ }
+ else
+ {
+ Element propertyElement = this.currentDoc
+ .createElement(property);
+
+ Text value = this.currentDoc
+ .createTextNode(newValue.replaceAll("\0", " "));
+ propertyElement.appendChild(value);
+
+ node.appendChild(propertyElement);
+ }
+
+ changed = true;
+ break;
+ }
+
+ if(changed)
+ {
+ // write changes
+ synchronized (this.docWriteLock)
+ {
+ if(historyImpl.getHistoryServiceImpl().isCacheEnabled())
+ this.historyImpl.writeFile(filename);
+ else
+ this.historyImpl.writeFile(filename, doc);
+ }
+
+ break;
+ }
+ }
+ }
}