You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2013/05/01 14:39:04 UTC
svn commit: r1477976 - in /jackrabbit/oak/trunk:
oak-core/src/main/java/org/apache/jackrabbit/oak/core/
oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/
oak-core/src/main/java/org/apache/jackrabbit/oak/security/user/ oak-...
Author: mduerig
Date: Wed May 1 12:39:03 2013
New Revision: 1477976
URL: http://svn.apache.org/r1477976
Log:
OAK-798: Review / refactor TreeImpl and related classes
reduce usage of deprecated API: replace getLocation with getTree and exists, replace usages of TreeLocation with Tree
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/IdentifierManager.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.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-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java
jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/IdentifierManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/IdentifierManager.java?rev=1477976&r1=1477975&r2=1477976&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/IdentifierManager.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/IdentifierManager.java Wed May 1 12:39:03 2013
@@ -42,7 +42,6 @@ import org.apache.jackrabbit.oak.api.Res
import org.apache.jackrabbit.oak.api.ResultRow;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.api.TreeLocation;
import org.apache.jackrabbit.oak.api.Type;
import org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
@@ -105,62 +104,51 @@ public class IdentifierManager {
}
/**
- * The tree identified by the specified {@code identifier} or {@code null}.
+ * The possibly non existing tree identified by the specified {@code identifier} or {@code null}.
*
* @param identifier The identifier of the tree such as exposed by {@link #getIdentifier(Tree)}
* @return The tree with the given {@code identifier} or {@code null} if no
- * such tree exists or if the tree is not accessible.
+ * such tree exists.
*/
@CheckForNull
public Tree getTree(String identifier) {
- return getLocation(identifier).getTree();
- }
-
- /**
- * The path of the tree identified by the specified {@code identifier} or {@code null}.
- *
- * @param identifier The identifier of the tree such as exposed by {@link #getIdentifier(Tree)}
- * @return The path of the tree with the given {@code identifier} or {@code null} if no
- * such tree exists or if the tree is not accessible.
- */
- @CheckForNull
- public String getPath(String identifier) {
- TreeLocation location = getLocation(identifier);
- return location.exists()
- ? location.getPath()
- : null;
- }
-
- /**
- * The tree location of the tree identified by the specified {@code identifier}.
- *
- * @param identifier The identifier of the tree such as exposed by {@link #getIdentifier(Tree)}
- * @return The tree location of the tree with the given {@code identifier}.
- */
- @Nonnull
- public TreeLocation getLocation(String identifier) {
if (identifier.startsWith("/")) {
- return root.getLocation(identifier);
+ return root.getTree(identifier);
} else {
int k = identifier.indexOf('/');
String uuid = k == -1
- ? identifier
- : identifier.substring(0, k);
+ ? identifier
+ : identifier.substring(0, k);
checkArgument(isValidUUID(uuid), "Not a valid identifier '" + identifier + '\'');
String basePath = resolveUUID(uuid);
if (basePath == null) {
- return root.getLocation("/").getParent(); // a null location
+ return null;
} else if (k == -1) {
- return root.getLocation(basePath);
+ return root.getTree(basePath);
} else {
- return root.getLocation(PathUtils.concat(basePath, identifier.substring(k + 1)));
+ return root.getTree(PathUtils.concat(basePath, identifier.substring(k + 1)));
}
}
}
/**
+ * The path of the tree identified by the specified {@code identifier} or {@code null}.
+ *
+ * @param identifier The identifier of the tree such as exposed by {@link #getIdentifier(Tree)}
+ * @return The path of the tree with the given {@code identifier} or {@code null} if no
+ * such tree exists or if the tree is not accessible.
+ */
+ @CheckForNull
+ public String getPath(String identifier) {
+ Tree tree = getTree(identifier);
+ return tree != null && tree.exists()
+ ? tree.getPath()
+ : null;
+ }
+
+ /**
* Returns the path of the tree references by the specified (weak)
* reference {@code PropertyState}.
*
@@ -224,8 +212,8 @@ public class IdentifierManager {
paths = Iterables.filter(paths, new Predicate<String>() {
@Override
public boolean apply(String path) {
- Tree tree = root.getTreeOrNull(PathUtils.getParentPath(path));
- if (tree != null) {
+ Tree tree = root.getTree(PathUtils.getParentPath(path));
+ if (tree.exists()) {
for (String ntName : nodeTypeNames) {
if (nodeTypeManager.isNodeType(tree, ntName)) {
return true;
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java?rev=1477976&r1=1477975&r2=1477976&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/security/authentication/token/TokenProviderImpl.java Wed May 1 12:39:03 2013
@@ -16,6 +16,8 @@
*/
package org.apache.jackrabbit.oak.security.authentication.token;
+import static org.apache.jackrabbit.oak.api.Type.STRING;
+
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
@@ -29,6 +31,7 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import javax.jcr.Credentials;
@@ -44,8 +47,8 @@ import org.apache.jackrabbit.oak.api.Com
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Root;
import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.core.IdentifierManager;
+import org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.plugins.name.NamespaceConstants;
import org.apache.jackrabbit.oak.spi.security.ConfigurationParameters;
import org.apache.jackrabbit.oak.spi.security.authentication.ImpersonationCredentials;
@@ -59,8 +62,6 @@ import org.apache.jackrabbit.util.Text;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import static org.apache.jackrabbit.oak.api.Type.STRING;
-
/**
* Default implementation of the {@code TokenProvider} interface with the
* following characteristics.
@@ -218,7 +219,7 @@ public class TokenProviderImpl implement
String nodeId = (pos == -1) ? token : token.substring(0, pos);
Tree tokenTree = identifierManager.getTree(nodeId);
String userId = getUserId(tokenTree);
- if (tokenTree == null || userId == null) {
+ if (tokenTree == null || !tokenTree.exists() || userId == null) {
return null;
} else {
return new TokenInfoImpl(new NodeUtil(tokenTree), token, userId);
@@ -316,7 +317,7 @@ public class TokenProviderImpl implement
@CheckForNull
private String getUserId(Tree tokenTree) {
- if (tokenTree != null) {
+ if (tokenTree != null && tokenTree.exists()) {
try {
String userPath = Text.getRelativeParent(tokenTree.getPath(), 2);
Authorizable authorizable = userManager.getAuthorizableByPath(userPath);
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=1477976&r1=1477975&r2=1477976&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 May 1 12:39:03 2013
@@ -31,13 +31,13 @@ import org.apache.jackrabbit.JcrConstant
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 org.apache.jackrabbit.oak.namepath.NamePathMapper;
import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
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.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 = TreeUtil.getTreeLocation(node, relPath);
+ TreeLocation propertyLocation = getLocation(node, relPath);
if (propertyLocation.getProperty() != null) {
if (isAuthorizableProperty(node, propertyLocation, true)) {
return propertyLocation.remove();
@@ -291,8 +291,17 @@ class AuthorizablePropertiesImpl impleme
}
@Nonnull
+ @Deprecated
private static TreeLocation getLocation(Tree tree, String relativePath) {
- return TreeUtil.getTreeLocation(tree, relativePath);
+ TreeLocation loc = tree.getLocation();
+ for (String element : Text.explode(relativePath, '/', false)) {
+ if (PathUtils.denotesParent(element)) {
+ loc = loc.getParent();
+ } else if (!PathUtils.denotesCurrent(element)) {
+ loc = loc.getChild(element);
+ } // else . -> skip to next element
+ }
+ return loc;
}
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=1477976&r1=1477975&r2=1477976&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 May 1 12:39:03 2013
@@ -39,7 +39,6 @@ import com.google.common.collect.Lists;
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.commons.PathUtils;
import org.apache.jackrabbit.oak.namepath.NameMapper;
import org.apache.jackrabbit.oak.namepath.NamePathMapper;
@@ -137,8 +136,8 @@ public class NodeUtil {
if (relativePath.indexOf('/') == -1) {
return getOrAddChild(relativePath, primaryTypeName);
} else {
- TreeLocation location = TreeUtil.getTreeLocation(tree, relativePath);
- if (location.getTree() == null) {
+ Tree t = TreeUtil.getTree(tree, relativePath);
+ if (t == null || !t.exists()) {
NodeUtil target = this;
for (String segment : Text.explode(relativePath, '/')) {
if (PathUtils.denotesParent(segment)) {
@@ -151,7 +150,7 @@ public class NodeUtil {
}
return target;
} else {
- return new NodeUtil(location.getTree());
+ return new NodeUtil(t);
}
}
}
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=1477976&r1=1477975&r2=1477976&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 May 1 12:39:03 2013
@@ -20,13 +20,11 @@ import static org.apache.jackrabbit.oak.
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 org.apache.jackrabbit.oak.commons.PathUtils;
import org.apache.jackrabbit.util.Text;
@@ -90,61 +88,6 @@ public final class TreeUtil {
}
/**
- * 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
- @Deprecated
- 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
- @Deprecated
- 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
- @Deprecated
- public static Tree getTree(TreeLocation start, String path) {
- return getTreeLocation(start, path).getTree();
- }
-
- /**
* Return the possibly non existing tree located at the passed {@code path} from
* the location of the start {@code tree} or {@code null} if {@code path} results
* in a parent of the root.
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java?rev=1477976&r1=1477975&r2=1477976&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/SessionDelegate.java Wed May 1 12:39:03 2013
@@ -167,7 +167,7 @@ public class SessionDelegate {
@CheckForNull
public NodeDelegate getNodeByIdentifier(String id) {
Tree tree = idManager.getTree(id);
- return (tree == null) ? null : new NodeDelegate(this, tree);
+ return (tree == null || !tree.exists()) ? null : new NodeDelegate(this, tree);
}
/**
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java?rev=1477976&r1=1477975&r2=1477976&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionHistoryDelegate.java Wed May 1 12:39:03 2013
@@ -85,7 +85,7 @@ public class VersionHistoryDelegate exte
}
String id = p.getValue(Type.REFERENCE);
Tree version = sessionDelegate.getIdManager().getTree(id);
- if (version == null) {
+ if (version == null || !version.exists()) {
throw new VersionException("Invalid label: " + label + '(' + id + ')');
}
return VersionDelegate.create(sessionDelegate, version);
Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java?rev=1477976&r1=1477975&r2=1477976&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java (original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/VersionManagerDelegate.java Wed May 1 12:39:03 2013
@@ -103,7 +103,7 @@ public class VersionManagerDelegate {
public VersionDelegate getVersionByIdentifier(@Nonnull String identifier)
throws RepositoryException {
Tree t = sessionDelegate.getIdManager().getTree(identifier);
- if (t == null) {
+ if (t == null || !t.exists()) {
throw new RepositoryException("No such Version with identifier: " +
identifier);
}