jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r1214161 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk: MicroKernelImpl.java api/MicroKernel.java json/JsopTokenizer.java util/PathUtils.java
Date Wed, 14 Dec 2011 11:18:43 GMT
Author: stefan
Date: Wed Dec 14 11:18:43 2011
New Revision: 1214161

URL: http://svn.apache.org/viewvc?rev=1214161&view=rev
Log:
MicroKernel#commit: support absolute paths in diff

Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java?rev=1214161&r1=1214160&r2=1214161&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/MicroKernelImpl.java
Wed Dec 14 11:18:43 2011
@@ -381,6 +381,9 @@ public class MicroKernelImpl implements 
         if (rep == null) {
             throw new IllegalStateException("this instance has already been disposed");
         }
+        if (path.length() > 0 && !PathUtils.isAbsolute(path)) {
+            throw new IllegalArgumentException("absolute path expected: " + path);
+        }
         try {
             JsopTokenizer t = new JsopTokenizer(jsonDiff);
             CommitBuilder cb = rep.getCommitBuilder(revisionId, message);
@@ -389,12 +392,17 @@ public class MicroKernelImpl implements 
                 if (r == JsopTokenizer.END) {
                     break;
                 }
+                int pos; // used for error reporting
                 switch (r) {
                     case '+': {
-                        String relPath = t.readString();
+                        pos = t.getLastPos();
+                        String subPath = t.readString();
                         t.read(':');
                         t.read('{');
-                        String nodePath = PathUtils.concat(path, relPath);
+                        String nodePath = PathUtils.concat(path, subPath);
+                        if (!PathUtils.isAbsolute(nodePath)) {
+                            throw new Exception("absolute path expected: " + nodePath + ",
pos: " + pos);
+                        }
                         String parentPath = PathUtils.getParentPath(nodePath);
                         String nodeName = PathUtils.getName(nodePath);
                         // build the list of added nodes recursively
@@ -406,12 +414,18 @@ public class MicroKernelImpl implements 
                         break;
                     }
                     case '-': {
-                        String relPath = t.readString();
-                        cb.removeNode(PathUtils.concat(path, relPath));
+                        pos = t.getLastPos();
+                        String subPath = t.readString();
+                        String targetPath = PathUtils.concat(path, subPath);
+                        if (!PathUtils.isAbsolute(targetPath)) {
+                            throw new Exception("absolute path expected: " + targetPath +
", pos: " + pos);
+                        }
+                        cb.removeNode(targetPath);
                         break;
                     }
                     case '^': {
-                        String relPath = t.readString();
+                        pos = t.getLastPos();
+                        String subPath = t.readString();
                         t.read(':');
                         String value;
                         if (t.matches(JsopTokenizer.NULL)) {
@@ -419,21 +433,33 @@ public class MicroKernelImpl implements 
                         } else {
                             value = t.readRawValue().trim();
                         }
-                        String nodePath = PathUtils.concat(path, relPath);
-                        String parentPath = PathUtils.getParentPath(nodePath);
-                        String propName = PathUtils.getName(nodePath);
+                        String targetPath = PathUtils.concat(path, subPath);
+                        if (!PathUtils.isAbsolute(targetPath)) {
+                            throw new Exception("absolute path expected: " + targetPath +
", pos: " + pos);
+                        }
+                        String parentPath = PathUtils.getParentPath(targetPath);
+                        String propName = PathUtils.getName(targetPath);
                         cb.setProperty(parentPath, propName, value);
                         break;
                     }
                     case '>': {
                         // TODO: support reorder syntax
-                        String relPath = t.readString();
+                        pos = t.getLastPos();
+                        String subPath = t.readString();
+                        String srcPath = PathUtils.concat(path, subPath);
+                        if (!PathUtils.isAbsolute(srcPath)) {
+                            throw new Exception("absolute path expected: " + srcPath + ",
pos: " + pos);
+                        }
                         t.read(':');
+                        pos = t.getLastPos();
                         String targetPath = t.readString();
                         if (!PathUtils.isAbsolute(targetPath)) {
                             targetPath = PathUtils.concat(path, targetPath);
+                            if (!PathUtils.isAbsolute(targetPath)) {
+                                throw new Exception("absolute path expected: " + targetPath
+ ", pos: " + pos);
+                            }
                         }
-                        cb.moveNode(PathUtils.concat(path, relPath), targetPath);
+                        cb.moveNode(srcPath, targetPath);
                         break;
                     }
                     default:

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java?rev=1214161&r1=1214160&r2=1214161&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/api/MicroKernel.java
Wed Dec 14 11:18:43 2011
@@ -271,6 +271,9 @@ public interface MicroKernel {
 
     /**
      * Applies the specified changes on the specified target node.
+     * <p/>
+     * If <code>path.length() == 0</code> the paths specified in the
+     * <code>jsonDiff</code> are expected to be absolute.
      *
      * @param path       path denoting target node
      * @param jsonDiff   changes to be applied in JSON diff format.

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java?rev=1214161&r1=1214160&r2=1214161&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/json/JsopTokenizer.java
Wed Dec 14 11:18:43 2011
@@ -430,6 +430,10 @@ public class JsopTokenizer implements Js
         return pos;
     }
 
+    public int getLastPos() {
+        return lastPos;
+    }
+
     public void setPos(int pos) {
         this.pos = pos;
     }

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java?rev=1214161&r1=1214160&r2=1214161&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/util/PathUtils.java
Wed Dec 14 11:18:43 2011
@@ -230,25 +230,28 @@ public class PathUtils {
      * Concatenate path elements.
      *
      * @param parentPath the parent path
-     * @param relativePath the relative path to add
+     * @param subPath the subPath path to add
      * @return the concatenated path
      */
-    public static String concat(String parentPath, String relativePath) {
+    public static String concat(String parentPath, String subPath) {
         assertValid(parentPath);
-        assertValid(relativePath);
-        if (isAbsolutePath(relativePath)) {
-            throw new IllegalArgumentException("Cannot append absolute path " + relativePath);
-        } else if (relativePath.length() == 0) {
+        assertValid(subPath);
+        // special cases
+        if (parentPath.length() == 0) {
+            return subPath;
+        } else if (subPath.length() == 0) {
             return parentPath;
+        } else if (isAbsolutePath(subPath)) {
+            throw new IllegalArgumentException("Cannot append absolute path " + subPath);
         }
         int parentLen = parentPath.length();
         StringBuilder buff = new StringBuilder(
-                parentLen + 1 + relativePath.length());
+                parentLen + 1 + subPath.length());
         buff.append(parentPath);
         if (parentLen > 0 && !denotesRootPath(parentPath)) {
             buff.append('/');
         }
-        buff.append(relativePath);
+        buff.append(subPath);
         return buff.toString();
     }
 



Mime
View raw message