jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1463984 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/core/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ oak-core/src/main/java/org/...
Date Wed, 03 Apr 2013 12:54:32 GMT
Author: mduerig
Date: Wed Apr  3 12:54:31 2013
New Revision: 1463984

URL: http://svn.apache.org/r1463984
Log:
OAK-732: Change TreeLocation.getChild() to only accept direct child nodes (not relative paths)

Removed:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/LocationUtil.java
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractTreeLocation.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/ReadOnlyVersionManager.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizablePropertiesImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeLocationTest.java
    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/delegate/NodeDelegate.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java?rev=1463984&r1=1463983&r2=1463984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/api/TreeLocation.java
Wed Apr  3 12:54:31 2013
@@ -39,19 +39,18 @@ public interface TreeLocation {
 
     /**
      * Navigate to the parent or an invalid location for the root of the hierarchy.
-     * @return  a {@code TreeLocation} for the parent of this location.
+     * @return a {@code TreeLocation} for the parent of this location.
      */
     @Nonnull
     TreeLocation getParent();
 
     /**
-     * Navigate to a child through a relative path. A relative path consists of a
-     * possibly empty lists of names separated by forward slashes.
-     * @param relPath  relative path to the child
+     * Navigate to a child of the given {@code name}.
+     * @param name  name of the child
      * @return  a {@code TreeLocation} for a child with the given {@code name}.
      */
     @Nonnull
-    TreeLocation getChild(String relPath);
+    TreeLocation getChild(String name);
 
     /**
      * Determine whether the underlying {@link org.apache.jackrabbit.oak.api.Tree} or

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java?rev=1463984&r1=1463983&r2=1463984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractNodeLocation.java
Wed Apr  3 12:54:31 2013
@@ -17,13 +17,11 @@
 package org.apache.jackrabbit.oak.core;
 
 import static com.google.common.base.Objects.toStringHelper;
-import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.TreeLocation;
-import org.apache.jackrabbit.oak.commons.PathUtils;
 
 /**
  * AbstractNodeLocation... TODO
@@ -58,28 +56,17 @@ abstract class AbstractNodeLocation<T ex
     }
 
     @Override
-    public TreeLocation getChild(String relPath) {
-        checkArgument(!PathUtils.isAbsolute(relPath), "Not a relative path: " + relPath);
-        if (relPath.isEmpty()) {
-            return this;
+    public TreeLocation getChild(String name) {
+        T child = getChildTree(name);
+        if (child != null) {
+            return createNodeLocation(child);
         }
 
-        String parent = PathUtils.getParentPath(relPath);
-        if (parent.isEmpty()) {
-            T child = getChildTree(relPath);
-            if (child != null) {
-                return createNodeLocation(child);
-            }
-
-            PropertyState prop = getPropertyState(relPath);
-            if (prop != null) {
-                return createPropertyLocation(this, relPath);
-            }
-            return new NullLocation(this, relPath);
-        }
-        else {
-            return getChild(parent).getChild(PathUtils.getName(relPath));
+        PropertyState prop = getPropertyState(name);
+        if (prop != null) {
+            return createPropertyLocation(this, name);
         }
+        return new NullLocation(this, name);
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractTreeLocation.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractTreeLocation.java?rev=1463984&r1=1463983&r2=1463984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractTreeLocation.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/AbstractTreeLocation.java
Wed Apr  3 12:54:31 2013
@@ -21,22 +21,12 @@ package org.apache.jackrabbit.oak.core;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.TreeLocation;
-import org.apache.jackrabbit.oak.commons.PathUtils;
-
-import static com.google.common.base.Preconditions.checkArgument;
 
 abstract class AbstractTreeLocation implements TreeLocation {
 
     @Override
-    public TreeLocation getChild(String relPath) {
-        checkArgument(!PathUtils.isAbsolute(relPath), "Not a relative path: " + relPath);
-
-        TreeLocation child = this;
-        for (String e : PathUtils.elements(relPath)) {
-            child = new NullLocation(child, e);
-        }
-
-        return child;
+    public TreeLocation getChild(String name) {
+        return new NullLocation(this, name);
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java?rev=1463984&r1=1463983&r2=1463984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/ImmutableRoot.java
Wed Apr  3 12:54:31 2013
@@ -18,6 +18,9 @@
  */
 package org.apache.jackrabbit.oak.core;
 
+import static com.google.common.base.Preconditions.checkArgument;
+import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -29,8 +32,6 @@ import org.apache.jackrabbit.oak.api.Tre
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 
-import static com.google.common.base.Preconditions.checkArgument;
-
 /**
  * Simple implementation of the Root interface that only supports simple read
  * operations (excluding query) based on the {@code NodeState} (or {@code ImmutableTree})
@@ -82,7 +83,11 @@ public final class ImmutableRoot impleme
     @Override
     public TreeLocation getLocation(String path) {
         checkArgument(PathUtils.isAbsolute(path));
-        return rootTree.getLocation().getChild(path.substring(1));
+        TreeLocation child = rootTree.getLocation();
+        for (String name : elements(path)) {
+            child = child.getChild(name);
+        }
+        return child;
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java?rev=1463984&r1=1463983&r2=1463984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
Wed Apr  3 12:54:31 2013
@@ -20,6 +20,7 @@ package org.apache.jackrabbit.oak.core;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.commons.PathUtils.elements;
 import static org.apache.jackrabbit.oak.commons.PathUtils.getName;
 import static org.apache.jackrabbit.oak.commons.PathUtils.getParentPath;
 
@@ -226,9 +227,13 @@ public class RootImpl implements Root {
 
     @Override
     public TreeLocation getLocation(String path) {
+        checkArgument(PathUtils.isAbsolute(path));
         checkLive();
-        checkArgument(PathUtils.isAbsolute(path), "Not an absolute path: " + path);
-        return rootTree.getLocation().getChild(path.substring(1));
+        TreeLocation child = rootTree.getLocation();
+        for (String name : elements(path)) {
+            child = child.getChild(name);
+        }
+        return child;
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java?rev=1463984&r1=1463983&r2=1463984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
Wed Apr  3 12:54:31 2013
@@ -470,7 +470,7 @@ public class TreeImpl implements Tree {
      */
     @CheckForNull
     TreeImpl getTree(String path) {
-        checkArgument(path.startsWith("/"));
+        checkArgument(PathUtils.isAbsolute(path));
         TreeImpl child = this;
         for (String name : elements(path)) {
             child = child.internalGetChild(name);

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java?rev=1463984&r1=1463983&r2=1463984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/ReadOnlyNodeTypeManager.java
Wed Apr  3 12:54:31 2013
@@ -52,6 +52,7 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.core.ReadOnlyTree;
 import org.apache.jackrabbit.oak.namepath.NameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
@@ -145,17 +146,19 @@ public abstract class ReadOnlyNodeTypeMa
      */
     @Nonnull
     public static ReadOnlyNodeTypeManager getInstance(NodeState root) {
-        Tree tree = new ReadOnlyTree(root).getLocation()
-                .getChild(NODE_TYPES_PATH.substring(1)).getTree();
-
-        final Tree types = tree == null
-            ? new ReadOnlyTree(EMPTY_NODE)  // No node types in content, use an empty node
-            : tree;
+        NodeState typesNode = root;
+        for (String name : PathUtils.elements(NODE_TYPES_PATH)) {
+            typesNode = typesNode.getChildNode(name);
+            if (typesNode == null) {
+                typesNode = EMPTY_NODE;
+            }
+        }
 
+        final Tree typesTree = new ReadOnlyTree(typesNode);
         return new ReadOnlyNodeTypeManager() {
             @Override
             protected Tree getTypes() {
-                return types;
+                return typesTree;
             }
         };
     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/ReadOnlyVersionManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/ReadOnlyVersionManager.java?rev=1463984&r1=1463983&r2=1463984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/ReadOnlyVersionManager.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/version/ReadOnlyVersionManager.java
Wed Apr  3 12:54:31 2013
@@ -18,6 +18,9 @@
  */
 package org.apache.jackrabbit.oak.plugins.version;
 
+import static com.google.common.base.Preconditions.checkArgument;
+import static com.google.common.base.Preconditions.checkNotNull;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.RepositoryException;
@@ -31,9 +34,7 @@ import org.apache.jackrabbit.oak.api.Typ
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.core.IdentifierManager;
 import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
-
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Preconditions.checkNotNull;
+import org.apache.jackrabbit.oak.util.TreeUtil;
 
 /**
  * {@code ReadOnlyVersionManager} provides implementations for read-only
@@ -101,7 +102,7 @@ public abstract class ReadOnlyVersionMan
             RepositoryException {
         checkVersionable(versionable);
         String uuid = versionable.getProperty(VersionConstants.JCR_UUID).getValue(Type.STRING);
-        return getVersionStorageLocation().getChild(getVersionHistoryPath(uuid)).getTree();
+        return TreeUtil.getTree(getVersionStorageLocation(), getVersionHistoryPath(uuid));
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java?rev=1463984&r1=1463983&r2=1463984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/query/Query.java
Wed Apr  3 12:54:31 2013
@@ -54,6 +54,7 @@ import org.apache.jackrabbit.oak.spi.que
 import org.apache.jackrabbit.oak.spi.query.PropertyValues;
 import org.apache.jackrabbit.oak.spi.query.QueryIndex;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
+import org.apache.jackrabbit.oak.util.TreeUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -620,10 +621,7 @@ public class Query {
     }
 
     public Tree getTree(String path) {
-        return rootTree
-                .getLocation()
-                .getChild(PathUtils.isAbsolute(path) ? path.substring(1) : path)
-                .getTree();
+        return TreeUtil.getTree(rootTree, PathUtils.isAbsolute(path) ? path.substring(1)
: path);
     }
 
     /**

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizablePropertiesImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizablePropertiesImpl.java?rev=1463984&r1=1463983&r2=1463984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizablePropertiesImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/AuthorizablePropertiesImpl.java
Wed Apr  3 12:54:31 2013
@@ -36,8 +36,8 @@ import org.apache.jackrabbit.oak.plugins
 import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
 import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
 import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
-import org.apache.jackrabbit.oak.util.LocationUtil;
 import org.apache.jackrabbit.oak.util.NodeUtil;
+import org.apache.jackrabbit.oak.util.TreeUtil;
 import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -164,7 +164,7 @@ class AuthorizablePropertiesImpl impleme
         checkRelativePath(relPath);
 
         Tree node = getTree();
-        TreeLocation propertyLocation = node.getLocation().getChild(relPath);
+        TreeLocation propertyLocation = TreeUtil.getTreeLocation(node, relPath);
         if (propertyLocation.getProperty() != null) {
             if (isAuthorizableProperty(node, propertyLocation, true)) {
                 return propertyLocation.remove();
@@ -292,7 +292,7 @@ class AuthorizablePropertiesImpl impleme
 
     @Nonnull
     private static TreeLocation getLocation(Tree tree, String relativePath) {
-        return LocationUtil.getTreeLocation(tree.getLocation(), relativePath);
+        return TreeUtil.getTreeLocation(tree, relativePath);
     }
 
     private static void checkRelativePath(String relativePath) throws RepositoryException
{

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java?rev=1463984&r1=1463983&r2=1463984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/NodeUtil.java
Wed Apr  3 12:54:31 2013
@@ -16,10 +16,19 @@
  */
 package org.apache.jackrabbit.oak.util;
 
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.api.Type.DATE;
+import static org.apache.jackrabbit.oak.api.Type.LONG;
+import static org.apache.jackrabbit.oak.api.Type.NAME;
+import static org.apache.jackrabbit.oak.api.Type.NAMES;
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+
 import java.util.Arrays;
 import java.util.Calendar;
 import java.util.GregorianCalendar;
 import java.util.List;
+
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.annotation.Nullable;
@@ -42,14 +51,6 @@ import org.apache.jackrabbit.util.Text;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.jackrabbit.oak.api.Type.DATE;
-import static org.apache.jackrabbit.oak.api.Type.LONG;
-import static org.apache.jackrabbit.oak.api.Type.NAME;
-import static org.apache.jackrabbit.oak.api.Type.NAMES;
-import static org.apache.jackrabbit.oak.api.Type.STRING;
-import static org.apache.jackrabbit.oak.api.Type.STRINGS;
-
 /**
  * Utility class for accessing and writing typed content of a tree.
  */
@@ -139,7 +140,7 @@ public class NodeUtil {
         if (relativePath.indexOf('/') == -1) {
             return getOrAddChild(relativePath, primaryTypeName);
         } else {
-            TreeLocation location = LocationUtil.getTreeLocation(tree.getLocation(), relativePath);
+            TreeLocation location = TreeUtil.getTreeLocation(tree, relativePath);
             if (location.getTree() == null) {
                 NodeUtil target = this;
                 for (String segment : Text.explode(relativePath, '/')) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java?rev=1463984&r1=1463983&r2=1463984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/util/TreeUtil.java
Wed Apr  3 12:54:31 2013
@@ -16,16 +16,20 @@
  */
 package org.apache.jackrabbit.oak.util;
 
+import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
+import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+
 import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
 
 import com.google.common.collect.Iterables;
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.TreeLocation;
 import org.apache.jackrabbit.oak.api.Type;
-
-import static org.apache.jackrabbit.oak.api.Type.BOOLEAN;
-import static org.apache.jackrabbit.oak.api.Type.STRINGS;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.util.Text;
 
 /**
  * Utility providing common operations for the {@code Tree} that are not provided
@@ -77,4 +81,70 @@ public final class TreeUtil {
         PropertyState property = tree.getProperty(propertyName);
         return property != null && !property.isArray() && property.getValue(BOOLEAN);
     }
+
+    /**
+     * Return the tree location located at the passed {@code path} from the
+     * {@code start} location.
+     * Parent (<em>..</em>) and current (<em>.</em>) elements in
the path are
+     * interpreted as the parent of the current location and the current
+     * location, respectively. Empty elements are ignored.
+     *
+     * @param start  start location
+     * @param path  path from the start location
+     * @return  tree location located at {@code path} from {@code start}
+     */
+    @Nonnull
+    public static TreeLocation getTreeLocation(TreeLocation start, String path) {
+        TreeLocation loc = start;
+        for (String element : Text.explode(path, '/', false)) {
+            if (PathUtils.denotesParent(element)) {
+                loc = loc.getParent();
+            } else if (!PathUtils.denotesCurrent(element)) {
+                loc = loc.getChild(element);
+            }  // else . -> skip to next element
+        }
+        return loc;
+    }
+
+    /**
+     * Return the tree location located at the passed {@code path} from the
+     * location of the {@code start} tree.
+     * Equivalent to {@code getTreeLocation(start.getLocation(), path)}.
+     *
+     * @param start  start tree
+     * @param path  path from the start tree
+     * @return  tree location located at {@code path} from {@code start}
+     */
+    @Nonnull
+    public static TreeLocation getTreeLocation(Tree start, String path) {
+        return getTreeLocation(start.getLocation(), path);
+    }
+
+    /**
+     * Return the tree located at the passed {@code path} from the {@code start}
+     * location or {@code null} if no such tree exists or is accessible.
+     * Equivalent to {@code getTreeLocation(start, path).getTree()}.
+     *
+     * @param start  start location
+     * @param path  path from the start location
+     * @return  tree located at {@code path} from {@code start} or {@code null}
+     */
+    @CheckForNull
+    public static Tree getTree(TreeLocation start, String path) {
+        return getTreeLocation(start, path).getTree();
+    }
+
+    /**
+     * Return the tree located at the passed {@code path} from the location of
+     * the {@code start} tree or {@code null} if no such tree exists or is accessible.
+     * Equivalent to {@code getTreeLocation(start.getLocation(), path).getTree()}.
+     *
+     * @param start  start tree
+     * @param path  path from the start tree
+     * @return  tree located at {@code path} from {@code start} or {@code null}
+     */
+    @CheckForNull
+    public static Tree getTree(Tree start, String path) {
+        return getTreeLocation(start.getLocation(), path).getTree();
+    }
 }
\ No newline at end of file

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeLocationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeLocationTest.java?rev=1463984&r1=1463983&r2=1463984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeLocationTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/core/TreeLocationTest.java
Wed Apr  3 12:54:31 2013
@@ -18,6 +18,11 @@
  */
 package org.apache.jackrabbit.oak.core;
 
+import static org.apache.jackrabbit.oak.core.NullLocation.NULL;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
 import org.apache.jackrabbit.oak.OakBaseTest;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.ContentSession;
@@ -29,11 +34,6 @@ import org.junit.Assert;
 import org.junit.Before;
 import org.junit.Test;
 
-import static org.apache.jackrabbit.oak.core.NullLocation.NULL;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
 public class TreeLocationTest extends OakBaseTest {
 
     private Root root;
@@ -64,7 +64,7 @@ public class TreeLocationTest extends Oa
 
     @Test
     public void testNullLocation() {
-        TreeLocation xyz = NULL.getChild("x/y/z");
+        TreeLocation xyz = NULL.getChild("x").getChild("y").getChild("z");
         Assert.assertEquals("x/y/z", xyz.getPath());
         assertEquals("x/y", xyz.getParent().getPath());
         assertEquals("x", xyz.getParent().getParent().getPath());
@@ -82,7 +82,7 @@ public class TreeLocationTest extends Oa
         TreeLocation x = root.getLocation("/x");
         assertNotNull(x.getTree());
 
-        TreeLocation xyz = x.getChild("y/z");
+        TreeLocation xyz = x.getChild("y").getChild("z");
         assertEquals("/x/y/z", xyz.getPath());
         assertNull(xyz.getTree());
 
@@ -98,7 +98,7 @@ public class TreeLocationTest extends Oa
         TreeLocation a = root.getLocation("/a");
         assertNotNull(a.getProperty());
 
-        TreeLocation abc = a.getChild("b/c");
+        TreeLocation abc = a.getChild("b").getChild("c");
         assertEquals("/a/b/c", abc.getPath());
         assertNull(abc.getProperty());
 

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=1463984&r1=1463983&r2=1463984&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
Wed Apr  3 12:54:31 2013
@@ -1481,7 +1481,7 @@ public class NodeImpl<T extends NodeDele
 
     private Property internalRemoveProperty(final String jcrName)
             throws RepositoryException {
-        final String oakName = getOakPathOrThrow(checkNotNull(jcrName));
+        final String oakName = getOakName(checkNotNull(jcrName));
         return perform(new ItemWriteOperation<Property>() {
             @Override
             protected Property perform() throws RepositoryException {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java?rev=1463984&r1=1463983&r2=1463984&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
Wed Apr  3 12:54:31 2013
@@ -33,6 +33,7 @@ import org.apache.jackrabbit.oak.api.Pro
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.TreeLocation;
 import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.util.TreeUtil;
 
 /**
  * {@code NodeDelegate} serve as internal representations of {@code Node}s.
@@ -259,15 +260,7 @@ public class NodeDelegate extends ItemDe
             throw new RepositoryException("Not a relative path: " + relPath);
         }
 
-        TreeLocation loc = getLocation();
-        for (String element : PathUtils.elements(relPath)) {
-            if (PathUtils.denotesParent(element)) {
-                loc = loc.getParent();
-            } else if (!PathUtils.denotesCurrent(element)) {
-                loc = loc.getChild(element);
-            }  // else . -> skip to next element
-        }
-        return loc;
+        return TreeUtil.getTreeLocation(getLocation(), relPath);
     }
 
     private Iterator<NodeDelegate> nodeDelegateIterator(



Mime
View raw message