jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1142610 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem: MemoryKernelImpl.java NodeImpl.java
Date Mon, 04 Jul 2011 10:37:11 GMT
Author: thomasm
Date: Mon Jul  4 10:37:11 2011
New Revision: 1142610

URL: http://svn.apache.org/viewvc?rev=1142610&view=rev
Log:
Re-write diff

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java?rev=1142610&r1=1142609&r2=1142610&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/MemoryKernelImpl.java
Mon Jul  4 10:37:11 2011
@@ -27,6 +27,7 @@ import org.apache.jackrabbit.mk.api.Micr
 import org.apache.jackrabbit.mk.json.JsopBuilder;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.apache.jackrabbit.mk.util.NonDescendingClock;
+import org.apache.jackrabbit.mk.util.PathUtils;
 
 /**
  * An in-memory implementation.
@@ -82,19 +83,21 @@ public class MemoryKernelImpl implements
         // TODO optional read / write version in json 'api' (as comments?)
 
         headRevId++;
-        apply(path, jsonDiff);
+        jsonDiff = apply(path, jsonDiff);
         commit(jsonDiff, message);
+
+        System.out.println("commit " + getRevisionId(headRevId) + " = " + jsonDiff);
+
         return getHeadRevision();
     }
 
-    private void apply(String rootPath, String jsonDiff) {
+    private String apply(String rootPath, String jsonDiff) {
+        JsopBuilder w = new JsopBuilder();
         JsopTokenizer t = new JsopTokenizer(jsonDiff);
-        if (rootPath.startsWith("/")) {
-            rootPath = rootPath.substring(1);
-        }
-        if (rootPath.length() > 0 && !rootPath.endsWith("/")) {
+        if (!PathUtils.denotesRoot(rootPath)) {
             rootPath += "/";
         }
+        String fromRoot = rootPath.substring(1);
         while (true) {
             int r = t.read();
             if (r == JsopTokenizer.END) {
@@ -104,14 +107,17 @@ public class MemoryKernelImpl implements
             switch (r) {
             case '+':
                 path = t.readString();
+                w.append("+ ").key(rootPath + path);
                 t.read(':');
                 t.read('{');
                 NodeImpl n = NodeImpl.parse(t, headRevId);
-                headRoot = headRoot.cloneAndAddChildNode(rootPath + path, n, headRevId);
+                headRoot = headRoot.cloneAndAddChildNode(fromRoot + path, n, headRevId);
+                w.append(n.toString()).append("\n");
                 break;
             case '-':
                 path = t.readString();
-                headRoot = headRoot.cloneAndRemoveChildNode(rootPath + path, headRevId);
+                w.append("- ").key(rootPath + path);
+                headRoot = headRoot.cloneAndRemoveChildNode(fromRoot + path, headRevId);
                 break;
             case '^':
                 path = t.readString();
@@ -119,15 +125,27 @@ public class MemoryKernelImpl implements
                 String value;
                 if (t.matches(JsopTokenizer.NULL)) {
                     value = null;
+                    w.append("^ ").key(rootPath + path);
+                    w.value(null);
                 } else {
                     value = t.readRawValue().trim();
+                    String nodeName = fromRoot + PathUtils.getParentPath(path);
+                    String propertyName = PathUtils.getName(path);
+                    if (headRoot.getNode(nodeName).hasProperty(propertyName)) {
+                        w.append("^ ").key(rootPath + path);
+                    } else {
+                        w.append("+ ").key(rootPath + path);
+                    }
+                    w.append(value);
                 }
-                headRoot = headRoot.cloneAndSetProperty(rootPath + path, value, headRevId);
+                headRoot = headRoot.cloneAndSetProperty(fromRoot + path, value, headRevId);
+                w.append("\n");
                 break;
             default:
                 throw new AssertionError("token type: " + t.getTokenType());
             }
         }
+        return w.toString();
     }
 
     public String getHeadRevision() {
@@ -146,7 +164,7 @@ public class MemoryKernelImpl implements
             index = -index + 1;
         }
         JsopBuilder buff = new JsopBuilder().array();
-        for (int i= index; i < revisionList.size(); i++) {
+        for (int i = index; i < revisionList.size(); i++) {
             Revision rev = revisionList.get(i);
             buff.object().
                 key("id").value(Long.toString(rev.getId())).
@@ -158,8 +176,8 @@ public class MemoryKernelImpl implements
 
     public String getJournal(String fromRevisionId, String toRevisionId) {
         long fromRevId = parseRevisionId(fromRevisionId);
-        long toRevId = parseRevisionId(fromRevisionId);
-        JsopBuilder buff = new JsopBuilder().array();
+        long toRevId = parseRevisionId(toRevisionId);
+        JsopBuilder buff = new JsopBuilder().array().append("\n");
         SortedMap<Long, Revision> map = revisions.subMap(fromRevId, true, toRevId,
true);
         for (Revision rev : map.values()) {
             buff.object().
@@ -167,7 +185,7 @@ public class MemoryKernelImpl implements
                 key("ts").value(rev.getTime()).
                 key("msg").value(rev.getMsg()).
                 key("changes").value(rev.getDiff()).
-            endObject();
+            endObject().append("\n");
         }
         return buff.endArray().toString();
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java?rev=1142610&r1=1142609&r2=1142610&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
Mon Jul  4 10:37:11 2011
@@ -25,9 +25,9 @@ import org.apache.jackrabbit.mk.util.Pat
 
 public class NodeImpl {
 
-    final long revId;
-    HashMap<String, String> properties;
-    LinkedHashMap<String, NodeImpl> childNodes;
+    private final long revId;
+    private HashMap<String, String> properties;
+    private LinkedHashMap<String, NodeImpl> childNodes;
 
     NodeImpl(long revId) {
         this.revId = revId;
@@ -140,6 +140,10 @@ public class NodeImpl {
         return c;
     }
 
+    public boolean hasProperty(String propertyName) {
+        return properties != null && properties.containsKey(propertyName);
+    }
+
     public String toString() {
         JsopBuilder json = new JsopBuilder();
         append(json, 0, 0, -1);
@@ -189,7 +193,7 @@ public class NodeImpl {
         if (childNodes == null) {
             childNodes = new LinkedHashMap<String, NodeImpl>();
         } else if (childNodes.containsKey(name)) {
-            throw new RuntimeException("Node already exiss: " + name);
+            throw new RuntimeException("Node already exists: " + name);
         }
         if (Constants.NODE_NAME_AS_PROPERTY) {
             node.setProperty(":name", JsopBuilder.encode(name));



Mime
View raw message