You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by re...@apache.org on 2016/07/04 13:56:09 UTC

svn commit: r1751291 - in /jackrabbit/branches/2.10: ./ jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java

Author: reschke
Date: Mon Jul  4 13:56:08 2016
New Revision: 1751291

URL: http://svn.apache.org/viewvc?rev=1751291&view=rev
Log:
JCR-3987: JcrUtils.getOrCreateByPath fails if session is not allowed to read root (ported to 2.10)

(patch by Carsten Ziegeler)

Modified:
    jackrabbit/branches/2.10/   (props changed)
    jackrabbit/branches/2.10/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java

Propchange: jackrabbit/branches/2.10/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jul  4 13:56:08 2016
@@ -1,3 +1,3 @@
 /jackrabbit/branches/JCR-2272:1173165-1176545
 /jackrabbit/sandbox/JCR-2415-lucene-3.0:1060860-1064038
-/jackrabbit/trunk:1729382,1732436,1740814-1740815
+/jackrabbit/trunk:1729382,1732436,1740814-1740815,1751279

Modified: jackrabbit/branches/2.10/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.10/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java?rev=1751291&r1=1751290&r2=1751291&view=diff
==============================================================================
--- jackrabbit/branches/2.10/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java (original)
+++ jackrabbit/branches/2.10/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java Mon Jul  4 13:56:08 2016
@@ -1543,6 +1543,27 @@ public class JcrUtils {
             return baseNode.getNode(path);
         }
 
+        // find the parent that exists
+        // we can start from the deepest child in tree
+        String fullPath = baseNode.getPath().equals("/") ? "/" + path : baseNode.getPath() + "/" + path;
+        int currentIndex = fullPath.lastIndexOf('/');
+        String temp = fullPath;
+        String existingPath = null;
+        while (currentIndex > 0) {
+            temp = temp.substring(0, currentIndex);
+            // break when first existing parent is found
+            if (baseNode.getSession().itemExists(temp)) {
+                existingPath = temp;
+                break;
+            }
+            currentIndex = temp.lastIndexOf("/");
+        }
+
+        if (existingPath != null) {
+            baseNode = baseNode.getSession().getNode(existingPath);
+            path = path.substring(existingPath.length() + 1);
+        }
+
         Node node = baseNode;
         int pos = path.lastIndexOf('/');