### Eclipse Workspace Patch 1.0 #P jackrabbit-jcr-commons Index: src/main/java/org/apache/jackrabbit/commons/JcrUtils.java =================================================================== --- src/main/java/org/apache/jackrabbit/commons/JcrUtils.java (Revision 1751243) +++ src/main/java/org/apache/jackrabbit/commons/JcrUtils.java (Arbeitskopie) @@ -1537,12 +1537,32 @@ String nodeType, boolean autoSave) throws RepositoryException { - if (!createUniqueLeaf && baseNode.hasNode(path)) { // node at path already exists, quicker way 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('/');