Author: reschke
Date: Thu May 10 13:18:02 2012
New Revision: 1336665

URL: http://svn.apache.org/viewvc?rev=1336665&view=rev
Log:
OAK-95: path mapping needs to deal with relative paths (patch by mduerig)

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
    
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java?rev=1336665&r1=1336664&r2=1336665&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/JcrPathParser.java
 Thu May 10 13:18:02 2012
@@ -48,14 +48,14 @@ public class JcrPathParser {
         // check for length
         int len = jcrPath == null ? 0 : jcrPath.length();
 
-        // shortcut
+        // shortcut for root path
         if (len == 1 && jcrPath.charAt(0) == '/') {
             listener.root();
             return;
         }
 
+        // short cut for empty path
         if (len == 0) {
-            listener.error("empty path");
             return;
         }
 

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java?rev=1336665&r1=1336664&r2=1336665&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
 Thu May 10 13:18:02 2012
@@ -91,9 +91,9 @@ public class NamePathMapperImpl implemen
 
             @Override
             public boolean parent() {
-                if (elements.isEmpty()) {
-                    parseErrors.append(".. of empty path");
-                    return false;
+                if (elements.isEmpty() || 
"..".equals(elements.get(elements.size() - 1))) {
+                    elements.add("..");
+                    return true;
                 }
                 elements.remove(elements.size() - 1);
                 return true;
@@ -131,6 +131,11 @@ public class NamePathMapperImpl implemen
             return null;
         }
 
+        // Empty path maps to ""
+        if (elements.isEmpty()) {
+            return "";
+        }
+
         StringBuilder oakPath = new StringBuilder();
         for (String element : elements) {
             if (element.isEmpty()) {
@@ -143,11 +148,6 @@ public class NamePathMapperImpl implemen
             }
         }
 
-        // empty path: map to "."
-        if (oakPath.length() == 0) {
-            return ".";
-        }
-        
         // root path is special-cased early on so it does not need to
         // be considered here
         oakPath.deleteCharAt(oakPath.length() - 1);
@@ -191,8 +191,9 @@ public class NamePathMapperImpl implemen
 
             @Override
             public boolean parent() {
-                if (elements.isEmpty()) {
-                    throw new IllegalArgumentException(".. of empty path");
+                if (elements.isEmpty() || 
"..".equals(elements.get(elements.size() - 1))) {
+                    elements.add("..");
+                    return true;
                 }
                 elements.remove(elements.size() - 1);
                 return true;
@@ -221,6 +222,11 @@ public class NamePathMapperImpl implemen
 
         JcrPathParser.parse(oakPath, listener);
 
+        // empty path: map to "."
+        if (elements.isEmpty()) {
+            return ".";
+        }
+
         StringBuilder jcrPath = new StringBuilder();
         for (String element : elements) {
             if (element.isEmpty()) {
@@ -233,11 +239,6 @@ public class NamePathMapperImpl implemen
             }
         }
 
-        // empty path: map to "."
-        if (jcrPath.length() == 0) {
-            return ".";
-        }
-
         jcrPath.deleteCharAt(jcrPath.length() - 1);
         return jcrPath.toString();
     }

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java?rev=1336665&r1=1336664&r2=1336665&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
 Thu May 10 13:18:02 2012
@@ -63,6 +63,28 @@ public class NamePathMapperImplTest {
                 "{http://www.jcp.org/jcr/nt/1.0}unstructured";));
         assertEquals("foobar/oak-jcr:content", npMapper.getOakPath(
                 "foobar/{http://www.jcp.org/jcr/1.0}content";));
+        assertEquals("foobar", npMapper.getOakPath(
+                "foobar/{http://www.jcp.org/jcr/1.0}content/..";));
+        assertEquals("", npMapper.getOakPath(
+                "foobar/{http://www.jcp.org/jcr/1.0}content/../..";));
+        assertEquals("..", npMapper.getOakPath(
+                "foobar/{http://www.jcp.org/jcr/1.0}content/../../..";));
+        assertEquals("../..", npMapper.getOakPath(
+                "foobar/{http://www.jcp.org/jcr/1.0}content/../../../..";));
+        assertEquals("oak-jcr:content", npMapper.getOakPath(
+                "foobar/../{http://www.jcp.org/jcr/1.0}content";));
+        assertEquals("../oak-jcr:content", npMapper.getOakPath(
+                "foobar/../../{http://www.jcp.org/jcr/1.0}content";));
+        assertEquals("..", npMapper.getOakPath(".."));
+        assertEquals("", npMapper.getOakPath("."));
+        assertEquals("foobar/oak-jcr:content", npMapper.getOakPath(
+                "foobar/{http://www.jcp.org/jcr/1.0}content/.";));
+        assertEquals("foobar/oak-jcr:content", npMapper.getOakPath(
+                "foobar/{http://www.jcp.org/jcr/1.0}content/./.";));
+        assertEquals("foobar/oak-jcr:content", npMapper.getOakPath(
+                "foobar/./{http://www.jcp.org/jcr/1.0}content";));
+        assertEquals("oak-jcr:content", npMapper.getOakPath(
+                "foobar/./../{http://www.jcp.org/jcr/1.0}content";));
     }
 
     @Test
@@ -71,6 +93,7 @@ public class NamePathMapperImplTest {
         assertEquals("/jcr-foo:bar/jcr-quu:qux",
                 npMapper.getJcrPath("/foo:bar/quu:qux"));
         assertEquals("jcr-foo:bar", npMapper.getJcrPath("foo:bar"));
+        assertEquals(".", npMapper.getJcrPath(""));
 
         try {
             npMapper.getJcrPath("{http://www.jcp.org/jcr/nt/1.0}unstructured";);

Modified: 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1336665&r1=1336664&r2=1336665&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
 Thu May 10 13:18:02 2012
@@ -365,12 +365,7 @@ public class NodeImpl extends ItemImpl i
         checkStatus();
 
         String oakPath = sessionDelegate.getOakPathOrThrowNotFound(relPath);
-        
-        // TODO: hack
-        if (".".equals(oakPath)) {
-            return this;
-        }
-        
+
         NodeDelegate nd = dlg.getChild(oakPath);
         if (nd == null) {
             throw new PathNotFoundException(relPath);


Reply via email to