jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1346505 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/ oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/ oak-it/jcr/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Tue, 05 Jun 2012 18:09:17 GMT
Author: reschke
Date: Tue Jun  5 18:09:17 2012
New Revision: 1346505

URL: http://svn.apache.org/viewvc?rev=1346505&view=rev
Log:
OAK-61: refactor the path mapper to provide a "keepIndex" variant, use it in JCR methods that
create new nodes to check for "[]" in the local name

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/PathMapper.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
    jackrabbit/oak/trunk/oak-it/jcr/pom.xml
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java

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=1346505&r1=1346504&r2=1346505&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
Tue Jun  5 18:09:17 2012
@@ -59,21 +59,29 @@ public class NamePathMapperImpl implemen
     //---------------------------------------------------------< PathMapper >---
     @Override
     public String getOakPath(String jcrPath) {
+        return getOakPath(jcrPath, false);
+    }
+
+    @Override
+    public String getOakPathKeepIndex(String jcrPath) {
+        return getOakPath(jcrPath, true);
+    }
+
+    @Override
+    @Nonnull
+    public String getJcrPath(String oakPath) {
         final List<String> elements = new ArrayList<String>();
-        final StringBuilder parseErrors = new StringBuilder();
 
-        if ("/".equals(jcrPath)) {
+        if ("/".equals(oakPath)) {
             // avoid the need to special case the root path later on
             return "/";
         }
 
         JcrPathParser.Listener listener = new JcrPathParser.Listener() {
-
             @Override
             public boolean root() {
                 if (!elements.isEmpty()) {
-                    parseErrors.append("/ on non-empty path");
-                    return false;
+                    throw new IllegalArgumentException("/ on non-empty path");
                 }
                 elements.add("");
                 return true;
@@ -82,7 +90,7 @@ public class NamePathMapperImpl implemen
             @Override
             public boolean current() {
                 // nothing to do here
-                return true;
+                return false;
             }
 
             @Override
@@ -97,81 +105,79 @@ public class NamePathMapperImpl implemen
 
             @Override
             public void error(String message) {
-                parseErrors.append(message);
+                throw new IllegalArgumentException(message);
             }
 
             @Override
             public boolean name(String name, int index) {
                 if (index > 1) {
-                    parseErrors.append("index > 1");
-                    return false;
-                }
-                String p = nameMapper.getOakName(name);
-                if (p == null) {
-                    parseErrors.append("Invalid name: ").append(name);
-                    return false;
+                    throw new IllegalArgumentException("index > 1");
                 }
+                String p = nameMapper.getJcrName(name);
                 elements.add(p);
                 return true;
             }
         };
 
-        JcrPathParser.parse(jcrPath, listener);
-        if (parseErrors.length() != 0) {
-            log.debug("Could not parse path " + jcrPath + ": " + parseErrors.toString());
-            return null;
-        }
+        JcrPathParser.parse(oakPath, listener);
 
-        // Empty path maps to ""
+        // empty path: map to "."
         if (elements.isEmpty()) {
-            return "";
+            return ".";
         }
 
-        StringBuilder oakPath = new StringBuilder();
+        StringBuilder jcrPath = new StringBuilder();
         for (String element : elements) {
             if (element.isEmpty()) {
                 // root
-                oakPath.append('/');
+                jcrPath.append('/');
             }
             else {
-                oakPath.append(element);
-                oakPath.append('/');
+                jcrPath.append(element);
+                jcrPath.append('/');
             }
         }
 
-        // root path is special-cased early on so it does not need to
-        // be considered here
-        oakPath.deleteCharAt(oakPath.length() - 1);
-        return oakPath.toString();
+        jcrPath.deleteCharAt(jcrPath.length() - 1);
+        return jcrPath.toString();
     }
 
-    @Override
-    public String mapJcrToOakNamespaces(String jcrPath) {
+    private String getOakPath(String jcrPath, final boolean keepIndex) {
         final List<String> elements = new ArrayList<String>();
         final StringBuilder parseErrors = new StringBuilder();
 
         if ("/".equals(jcrPath)) {
-            return jcrPath;
+            // avoid the need to special case the root path later on
+            return "/";
         }
 
         boolean hasClarkBrackets = false;
+        boolean hasIndexBrackets = false;
         boolean hasColon = false;
+        boolean hasNameStartingWithDot = false;
 
+        char prev = 0;
         for (int i = 0; i < jcrPath.length(); i++) {
             char c = jcrPath.charAt(i);
-            
-            if (c == '{' || c=='}') {
+
+            if (c == '{' || c == '}') {
                 hasClarkBrackets = true;
-            }
-            else if (c == ':') {
+            } else if (c == '[' || c == ']') {
+                hasIndexBrackets = true;
+            } else if (c == ':') {
                 hasColon = true;
+            } else if (c == '.' && (prev == 0 || prev == '/')) {
+                hasNameStartingWithDot = true;
             }
+
+            prev = c;
         }
 
-        // no expanded names and no prefixes, or
-        // no expanded names and no prefix remappings
-        if (!hasClarkBrackets && (!hasColon || !hasSessionLocalMappings())) {
-            return removeTrailingSlash(jcrPath);
+        // try a shortcut
+        if (!hasNameStartingWithDot && !hasClarkBrackets && !hasIndexBrackets)
{
+            if (!hasColon || !hasSessionLocalMappings()) {
+                return removeTrailingSlash(jcrPath);
+            }
         }
 
         JcrPathParser.Listener listener = new JcrPathParser.Listener() {
@@ -188,13 +194,17 @@ public class NamePathMapperImpl implemen
 
             @Override
             public boolean current() {
-                elements.add(".");
+                // nothing to do here
                 return true;
             }
 
             @Override
             public boolean parent() {
-                elements.add("..");
+                if (elements.isEmpty() || "..".equals(elements.get(elements.size() - 1)))
{
+                    elements.add("..");
+                    return true;
+                }
+                elements.remove(elements.size() - 1);
                 return true;
             }
 
@@ -205,12 +215,16 @@ public class NamePathMapperImpl implemen
 
             @Override
             public boolean name(String name, int index) {
+                if (!keepIndex && index > 1) {
+                    parseErrors.append("index > 1");
+                    return false;
+                }
                 String p = nameMapper.getOakName(name);
                 if (p == null) {
                     parseErrors.append("Invalid name: ").append(name);
                     return false;
                 }
-                if (index != 0) {
+                if (keepIndex && index > 0) {
                     p += "[" + index + "]";
                 }
                 elements.add(p);
@@ -247,81 +261,6 @@ public class NamePathMapperImpl implemen
         return oakPath.toString();
     }
 
-    @Override
-    @Nonnull
-    public String getJcrPath(String oakPath) {
-        final List<String> elements = new ArrayList<String>();
-        
-        if ("/".equals(oakPath)) {
-            // avoid the need to special case the root path later on
-            return "/";
-        }
-
-        JcrPathParser.Listener listener = new JcrPathParser.Listener() {
-            @Override
-            public boolean root() {
-                if (!elements.isEmpty()) {
-                    throw new IllegalArgumentException("/ on non-empty path");
-                }
-                elements.add("");
-                return true;
-            }
-
-            @Override
-            public boolean current() {
-                // nothing to do here
-                return false;
-            }
-
-            @Override
-            public boolean parent() {
-                if (elements.isEmpty() || "..".equals(elements.get(elements.size() - 1)))
{
-                    elements.add("..");
-                    return true;
-                }
-                elements.remove(elements.size() - 1);
-                return true;
-            }
-
-            @Override
-            public void error(String message) {
-                throw new IllegalArgumentException(message);
-            }
-
-            @Override
-            public boolean name(String name, int index) {
-                if (index > 1) {
-                    throw new IllegalArgumentException("index > 1");
-                }
-                String p = nameMapper.getJcrName(name);
-                elements.add(p);
-                return true;
-            }
-        };
-
-        JcrPathParser.parse(oakPath, listener);
-
-        // empty path: map to "."
-        if (elements.isEmpty()) {
-            return ".";
-        }
-
-        StringBuilder jcrPath = new StringBuilder();
-        for (String element : elements) {
-            if (element.isEmpty()) {
-                // root
-                jcrPath.append('/');
-            }
-            else {
-                jcrPath.append(element);
-                jcrPath.append('/');
-            }
-        }
-
-        jcrPath.deleteCharAt(jcrPath.length() - 1);
-        return jcrPath.toString();
-    }
-
     private String removeTrailingSlash(String path) {
         if ("/".equals(path) || path.isEmpty()) {
             return path;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/PathMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/PathMapper.java?rev=1346505&r1=1346504&r2=1346505&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/PathMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/PathMapper.java
Tue Jun  5 18:09:17 2012
@@ -36,17 +36,13 @@ public interface PathMapper {
     String getOakPath(String jcrPath);
 
     /**
-     * Maps a JCR path to an Oak path, substituting JCR prefixes with
-     * Oak prefixes, and converting expanded names to Oak qualified form.
-     * Returns the converted path for the given JCR path, or {@code null} if no
-     * such mapping exists because the given JCR path contains a name element
-     * with an unknown namespace URI or prefix, or is otherwise invalid.
+     * As {@link #getOakPath(String)}, but preserving the index information
      *
      * @param jcrPath JCR path
      * @return mapped path, or {@code null}
      */
     @CheckForNull
-    String mapJcrToOakNamespaces(String jcrPath);
+    String getOakPathKeepIndex(String jcrPath);
 
     /**
      * Returns the JCR path for the given Oak path. The given path is

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=1346505&r1=1346504&r2=1346505&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
Tue Jun  5 18:09:17 2012
@@ -68,65 +68,45 @@ public class NamePathMapperImplTest {
         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"));
+        assertEquals("/a/b/c", npMapper.getOakPath("/a/b[1]/c[01]"));
     }
 
     @Test
-    public void testMapJcrToOakNamespaces() {
+    public void testJcrToOakKeepIndex() {
         TestNameMapper mapper = new TestNameMapper(true);
         NamePathMapper npMapper = new NamePathMapperImpl(mapper);
 
-        assertEquals("/", npMapper.mapJcrToOakNamespaces("/"));
-        assertEquals("foo", npMapper.mapJcrToOakNamespaces("{}foo"));
-        assertEquals("/oak-foo:bar", npMapper.mapJcrToOakNamespaces("/foo:bar"));
-        assertEquals("/oak-foo:bar/oak-quu:qux", npMapper.mapJcrToOakNamespaces("/foo:bar/quu:qux"));
-        assertEquals("oak-foo:bar", npMapper.mapJcrToOakNamespaces("foo:bar"));
-        assertEquals("oak-nt:unstructured", npMapper.mapJcrToOakNamespaces("{http://www.jcp.org/jcr/nt/1.0}unstructured"));
-        assertEquals("foobar/oak-jcr:content", npMapper.mapJcrToOakNamespaces("foobar/{http://www.jcp.org/jcr/1.0}content"));
-        assertEquals("foobar/oak-jcr:content/..", npMapper.mapJcrToOakNamespaces("foobar/{http://www.jcp.org/jcr/1.0}content/.."));
-        assertEquals("foobar/oak-jcr:content/../..",
-                npMapper.mapJcrToOakNamespaces("foobar/{http://www.jcp.org/jcr/1.0}content/../.."));
-        assertEquals("foobar/oak-jcr:content/../../..",
-                npMapper.mapJcrToOakNamespaces("foobar/{http://www.jcp.org/jcr/1.0}content/../../.."));
-        assertEquals("foobar/oak-jcr:content/../../../..",
-                npMapper.mapJcrToOakNamespaces("foobar/{http://www.jcp.org/jcr/1.0}content/../../../.."));
-        assertEquals("foobar/../oak-jcr:content", npMapper.mapJcrToOakNamespaces("foobar/../{http://www.jcp.org/jcr/1.0}content"));
-        assertEquals("foobar/../../oak-jcr:content",
-                npMapper.mapJcrToOakNamespaces("foobar/../../{http://www.jcp.org/jcr/1.0}content"));
-        assertEquals("..", npMapper.mapJcrToOakNamespaces(".."));
-        assertEquals(".", npMapper.mapJcrToOakNamespaces("."));
-        assertEquals("foobar/oak-jcr:content/.", npMapper.mapJcrToOakNamespaces("foobar/{http://www.jcp.org/jcr/1.0}content/."));
-        assertEquals("foobar/oak-jcr:content/./.", npMapper.mapJcrToOakNamespaces("foobar/{http://www.jcp.org/jcr/1.0}content/./."));
-        assertEquals("foobar/./oak-jcr:content", npMapper.mapJcrToOakNamespaces("foobar/./{http://www.jcp.org/jcr/1.0}content"));
-        assertEquals("foobar/./../oak-jcr:content",
-                npMapper.mapJcrToOakNamespaces("foobar/./../{http://www.jcp.org/jcr/1.0}content"));
+        assertEquals("/", npMapper.getOakPathKeepIndex("/"));
+        assertEquals("foo", npMapper.getOakPathKeepIndex("{}foo"));
+        assertEquals("/oak-foo:bar", npMapper.getOakPathKeepIndex("/foo:bar"));
+        assertEquals("/oak-foo:bar/oak-quu:qux", npMapper.getOakPathKeepIndex("/foo:bar/quu:qux"));
+        assertEquals("oak-foo:bar", npMapper.getOakPathKeepIndex("foo:bar"));
+        assertEquals("oak-nt:unstructured", npMapper.getOakPathKeepIndex("{http://www.jcp.org/jcr/nt/1.0}unstructured"));
+        assertEquals("foobar/oak-jcr:content", npMapper.getOakPathKeepIndex("foobar/{http://www.jcp.org/jcr/1.0}content"));
+        assertEquals("foobar", npMapper.getOakPathKeepIndex("foobar/{http://www.jcp.org/jcr/1.0}content/.."));
+        assertEquals("", npMapper.getOakPathKeepIndex("foobar/{http://www.jcp.org/jcr/1.0}content/../.."));
+        assertEquals("..", npMapper.getOakPathKeepIndex("foobar/{http://www.jcp.org/jcr/1.0}content/../../.."));
+        assertEquals("../..", npMapper.getOakPathKeepIndex("foobar/{http://www.jcp.org/jcr/1.0}content/../../../.."));
+        assertEquals("oak-jcr:content", npMapper.getOakPathKeepIndex("foobar/../{http://www.jcp.org/jcr/1.0}content"));
+        assertEquals("../oak-jcr:content", npMapper.getOakPathKeepIndex("foobar/../../{http://www.jcp.org/jcr/1.0}content"));
+        assertEquals("..", npMapper.getOakPathKeepIndex(".."));
+        assertEquals("", npMapper.getOakPathKeepIndex("."));
+        assertEquals("foobar/oak-jcr:content", npMapper.getOakPathKeepIndex("foobar/{http://www.jcp.org/jcr/1.0}content/."));
+        assertEquals("foobar/oak-jcr:content", npMapper.getOakPathKeepIndex("foobar/{http://www.jcp.org/jcr/1.0}content/./."));
+        assertEquals("foobar/oak-jcr:content", npMapper.getOakPathKeepIndex("foobar/./{http://www.jcp.org/jcr/1.0}content"));
+        assertEquals("oak-jcr:content", npMapper.getOakPathKeepIndex("foobar/./../{http://www.jcp.org/jcr/1.0}content"));
+        assertEquals("/a/b[1]/c[1]", npMapper.getOakPathKeepIndex("/a/b[1]/c[01]"));
     }
 
     @Test
-    public void testMapJcrToOakNamespacesNoRemap() {
+    public void testJcrToOakKeepIndexNoRemap() {
         TestNameMapper mapper = new TestNameMapper(false); // a mapper with no prefix remappings
present
         NamePathMapper npMapper = new NamePathMapperImpl(mapper);
 
         checkIdentical(npMapper, "/");
-        assertEquals("foo", npMapper.mapJcrToOakNamespaces("{}foo"));
         checkIdentical(npMapper, "/foo:bar");
         checkIdentical(npMapper, "/foo:bar/quu:qux");
         checkIdentical(npMapper, "foo:bar");
-        assertEquals("nt:unstructured", npMapper.mapJcrToOakNamespaces("{http://www.jcp.org/jcr/nt/1.0}unstructured"));
-        assertEquals("foobar/jcr:content", npMapper.mapJcrToOakNamespaces("foobar/{http://www.jcp.org/jcr/1.0}content"));
-        assertEquals("foobar/jcr:content/..", npMapper.mapJcrToOakNamespaces("foobar/{http://www.jcp.org/jcr/1.0}content/.."));
-        assertEquals("foobar/jcr:content/../..", npMapper.mapJcrToOakNamespaces("foobar/{http://www.jcp.org/jcr/1.0}content/../.."));
-        assertEquals("foobar/jcr:content/../../..",
-                npMapper.mapJcrToOakNamespaces("foobar/{http://www.jcp.org/jcr/1.0}content/../../.."));
-        assertEquals("foobar/jcr:content/../../../..",
-                npMapper.mapJcrToOakNamespaces("foobar/{http://www.jcp.org/jcr/1.0}content/../../../.."));
-        assertEquals("foobar/../jcr:content", npMapper.mapJcrToOakNamespaces("foobar/../{http://www.jcp.org/jcr/1.0}content"));
-        assertEquals("foobar/../../jcr:content", npMapper.mapJcrToOakNamespaces("foobar/../../{http://www.jcp.org/jcr/1.0}content"));
-        assertEquals("..", npMapper.mapJcrToOakNamespaces(".."));
-        assertEquals(".", npMapper.mapJcrToOakNamespaces("."));
-        assertEquals("foobar/jcr:content/.", npMapper.mapJcrToOakNamespaces("foobar/{http://www.jcp.org/jcr/1.0}content/."));
-        assertEquals("foobar/jcr:content/./.", npMapper.mapJcrToOakNamespaces("foobar/{http://www.jcp.org/jcr/1.0}content/./."));
-        assertEquals("foobar/./jcr:content", npMapper.mapJcrToOakNamespaces("foobar/./{http://www.jcp.org/jcr/1.0}content"));
-        assertEquals("foobar/./../jcr:content", npMapper.mapJcrToOakNamespaces("foobar/./../{http://www.jcp.org/jcr/1.0}content"));
     }
 
     @Test
@@ -153,12 +133,12 @@ public class NamePathMapperImplTest {
     }
 
     private void checkEquals(NamePathMapper npMapper, String jcrPath) {
-        String oakPath = npMapper.mapJcrToOakNamespaces(jcrPath);
+        String oakPath = npMapper.getOakPathKeepIndex(jcrPath);
         assertEquals(jcrPath, oakPath);
     }
     
     private void checkIdentical(NamePathMapper npMapper, String jcrPath) {
-        String oakPath = npMapper.mapJcrToOakNamespaces(jcrPath);
+        String oakPath = npMapper.getOakPathKeepIndex(jcrPath);
         checkIdentical(jcrPath, oakPath);
     }
 

Modified: jackrabbit/oak/trunk/oak-it/jcr/pom.xml
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-it/jcr/pom.xml?rev=1346505&r1=1346504&r2=1346505&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-it/jcr/pom.xml (original)
+++ jackrabbit/oak/trunk/oak-it/jcr/pom.xml Tue Jun  5 18:09:17 2012
@@ -45,8 +45,6 @@
               <name>known.issues</name>
               <value>
 org.apache.jackrabbit.test.api.AddNodeTest#testConstraintViolation
-org.apache.jackrabbit.test.api.AddNodeTest#testRepositoryException
-org.apache.jackrabbit.test.api.SessionTest#testMoveRepositoryException
 org.apache.jackrabbit.test.api.SessionTest#testMoveConstraintViolationExceptionSrc
 org.apache.jackrabbit.test.api.SessionTest#testMoveConstraintViolationExceptionDest
 org.apache.jackrabbit.test.api.SessionTest#testSaveConstraintViolationException
@@ -66,9 +64,11 @@ org.apache.jackrabbit.test.api.SetProper
 org.apache.jackrabbit.test.api.SetPropertyAssumeTypeTest
 org.apache.jackrabbit.test.api.NodeAddMixinTest#testAddInheritedMixin
 org.apache.jackrabbit.test.api.WorkspaceCopySameNameSibsTest
-org.apache.jackrabbit.test.api.WorkspaceCopyTest
+org.apache.jackrabbit.test.api.WorkspaceCopyTest#testCopyNodesConstraintViolationException
+org.apache.jackrabbit.test.api.WorkspaceCopyTest#testCopyNodesAccessDenied
 org.apache.jackrabbit.test.api.WorkspaceMoveSameNameSibsTest
-org.apache.jackrabbit.test.api.WorkspaceMoveTest
+org.apache.jackrabbit.test.api.WorkspaceMoveTest#testMoveNodesConstraintViolationException
+org.apache.jackrabbit.test.api.WorkspaceMoveTest#testMoveNodesAccessDenied
 org.apache.jackrabbit.test.api.ImpersonateTest
 org.apache.jackrabbit.test.api.CheckPermissionTest
 org.apache.jackrabbit.test.api.DocumentViewImportTest

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=1346505&r1=1346504&r2=1346505&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
Tue Jun  5 18:09:17 2012
@@ -170,9 +170,16 @@ public class NodeImpl extends ItemImpl i
     public Node addNode(String relPath, String primaryNodeTypeName) throws RepositoryException
{
         checkStatus();
 
-        String oakPath = sessionDelegate.getOakPathOrThrow(relPath);
+        String oakPath = sessionDelegate.getOakPathKeepIndexOrThrowNotFound(relPath);
         String oakName = PathUtils.getName(oakPath);
-        NodeDelegate parent = dlg.getChild(PathUtils.getParentPath(oakPath));
+        String parentPath = sessionDelegate.getOakPathOrThrow(PathUtils.getParentPath(oakPath));
+
+        // handle index
+        if (oakName.contains("[")) {
+            throw new RepositoryException("Cannot create a new node using a name including
an index");
+        }
+
+        NodeDelegate parent = dlg.getChild(parentPath);
         if (parent == null) {
             throw new PathNotFoundException(relPath);
         }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java?rev=1346505&r1=1346504&r2=1346505&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionDelegate.java
Tue Jun  5 18:09:17 2012
@@ -37,7 +37,6 @@ import org.slf4j.LoggerFactory;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.ItemExistsException;
-import javax.jcr.NamespaceRegistry;
 import javax.jcr.Node;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.Repository;
@@ -195,6 +194,23 @@ public class SessionDelegate {
     }
 
     /**
+     * Shortcut for {@code SessionDelegate.getOakPathKeepIndex(jcrPath)}.
+     *
+     * @param jcrPath JCR path
+     * @return Oak path, or {@code null}, with indexes left intact
+     * @throws PathNotFoundException 
+     */
+    @Nonnull
+    public String getOakPathKeepIndexOrThrowNotFound(String jcrPath) throws PathNotFoundException
{
+        String oakPath = getNamePathMapper().getOakPathKeepIndex(jcrPath);
+        if (oakPath != null) {
+            return oakPath;
+        } else {
+            throw new PathNotFoundException(jcrPath);
+        }
+    }
+
+    /**
      * Returns the Oak path for the given JCR path, or throws a
      * {@link PathNotFoundException} if the path can not be mapped.
      *
@@ -202,9 +218,8 @@ public class SessionDelegate {
      * @return Oak path
      * @throws PathNotFoundException if the path can not be mapped
      */
-    @CheckForNull
-    public String getOakPathOrThrowNotFound(String jcrPath)
-            throws PathNotFoundException {
+    @Nonnull
+    public String getOakPathOrThrowNotFound(String jcrPath) throws PathNotFoundException
{
         String oakPath = getOakPathOrNull(jcrPath);
         if (oakPath != null) {
             return oakPath;

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1346505&r1=1346504&r2=1346505&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Tue Jun  5 18:09:17 2012
@@ -35,6 +35,7 @@ import org.apache.jackrabbit.api.Jackrab
 import org.apache.jackrabbit.api.security.principal.PrincipalManager;
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.commons.AbstractSession;
+import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.jcr.xml.XmlImportHandler;
 import org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials;
 import org.slf4j.Logger;
@@ -129,9 +130,17 @@ public class SessionImpl extends Abstrac
     @Override
     public void move(String srcAbsPath, String destAbsPath) throws RepositoryException {
         ensureIsAlive();
+
+        String oakPath = dlg.getOakPathKeepIndexOrThrowNotFound(destAbsPath);
+        String oakName = PathUtils.getName(oakPath);
+        // handle index
+        if (oakName.contains("[")) {
+            throw new RepositoryException("Cannot create a new node using a name including
an index");
+        }
+
         dlg.move(
                 dlg.getOakPathOrThrowNotFound(srcAbsPath),
-                dlg.getOakPathOrThrowNotFound(destAbsPath),
+                dlg.getOakPathOrThrowNotFound(oakPath),
                 true);
     }
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java?rev=1346505&r1=1346504&r2=1346505&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
Tue Jun  5 18:09:17 2012
@@ -18,6 +18,7 @@ package org.apache.jackrabbit.oak.jcr;
 
 import org.apache.jackrabbit.api.JackrabbitWorkspace;
 import org.apache.jackrabbit.api.security.authorization.PrivilegeManager;
+import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.jcr.nodetype.NodeTypeManagerImpl;
 import org.apache.jackrabbit.oak.jcr.query.QueryManagerImpl;
 import org.apache.jackrabbit.oak.jcr.security.privileges.PrivilegeManagerImpl;
@@ -89,9 +90,16 @@ public class WorkspaceImpl implements Ja
             throw new UnsupportedRepositoryOperationException("Not implemented.");
         }
 
+        String oakPath = sessionDelegate.getOakPathKeepIndexOrThrowNotFound(destAbsPath);
+        String oakName = PathUtils.getName(oakPath);
+        // handle index
+        if (oakName.contains("[")) {
+            throw new RepositoryException("Cannot create a new node using a name including
an index");
+        }
+
         sessionDelegate.copy(
                 sessionDelegate.getOakPathOrThrowNotFound(srcAbsPath),
-                sessionDelegate.getOakPathOrThrowNotFound(destAbsPath));
+                sessionDelegate.getOakPathOrThrowNotFound(oakPath));
     }
 
     @SuppressWarnings("deprecation")
@@ -110,9 +118,16 @@ public class WorkspaceImpl implements Ja
         ensureSupportedOption(Repository.LEVEL_2_SUPPORTED);
         ensureIsAlive();
 
+        String oakPath = sessionDelegate.getOakPathKeepIndexOrThrowNotFound(destAbsPath);
+        String oakName = PathUtils.getName(oakPath);
+        // handle index
+        if (oakName.contains("[")) {
+            throw new RepositoryException("Cannot create a new node using a name including
an index");
+        }
+
         sessionDelegate.move(
                 sessionDelegate.getOakPathOrThrowNotFound(srcAbsPath),
-                sessionDelegate.getOakPathOrThrowNotFound(destAbsPath),
+                sessionDelegate.getOakPathOrThrowNotFound(oakPath),
                 false);
     }
 



Mime
View raw message