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:51:33 UTC

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

Author: reschke
Date: Mon Jul  4 13:51:33 2016
New Revision: 1751288

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

(patch by Carsten Ziegeler)

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

Propchange: jackrabbit/branches/2.12/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Jul  4 13:51:33 2016
@@ -1,3 +1,3 @@
 /jackrabbit/branches/JCR-2272:1173165-1176545
 /jackrabbit/sandbox/JCR-2415-lucene-3.0:1060860-1064038
-/jackrabbit/trunk:1732436
+/jackrabbit/trunk:1732436,1751279

Modified: jackrabbit/branches/2.12/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java
URL: http://svn.apache.org/viewvc/jackrabbit/branches/2.12/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java?rev=1751288&r1=1751287&r2=1751288&view=diff
==============================================================================
--- jackrabbit/branches/2.12/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java (original)
+++ jackrabbit/branches/2.12/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/commons/JcrUtils.java Mon Jul  4 13:51:33 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('/');