Author: jukka
Date: Wed Feb 19 10:10:28 2014
New Revision: 1569668
URL: http://svn.apache.org/r1569668
Log:
OAK-1431: Handling of empty or invalid names
Enfoce basic name constraints (non-empty, no / character) in NodeBuilder
and during property construction
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java?rev=1569668&r1=1569667&r2=1569668&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/SecureNodeBuilder.java
Wed Feb 19 10:10:28 2014
@@ -326,7 +326,7 @@ class SecureNodeBuilder implements NodeB
@Override
public NodeBuilder getChildNode(@Nonnull String name) {
- return new SecureNodeBuilder(this, checkNotNull(name));
+ return new SecureNodeBuilder(this, name);
}
@Override
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java?rev=1569668&r1=1569667&r2=1569668&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeBuilder.java
Wed Feb 19 10:10:28 2014
@@ -22,6 +22,7 @@ import org.apache.jackrabbit.oak.spi.sta
import org.apache.jackrabbit.oak.spi.state.NodeState;
import static com.google.common.base.Preconditions.checkNotNull;
+import static
org.apache.jackrabbit.oak.spi.state.AbstractNodeState.checkValidName;
/**
* This class refines move and copy operations by delegating
@@ -74,7 +75,7 @@ public class KernelNodeBuilder extends M
public boolean moveTo(NodeBuilder newParent, String newName) {
if (newParent instanceof FastMove) {
checkNotNull(newParent);
- checkNotNull(newName);
+ checkValidName(newName);
annotateSourcePath();
boolean success = !isRoot() && exists() &&
!newParent.hasChildNode(newName) &&
((FastMove) newParent).moveFrom(this, newName);
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java?rev=1569668&r1=1569667&r2=1569668&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Wed Feb 19 10:10:28 2014
@@ -18,11 +18,13 @@ package org.apache.jackrabbit.oak.plugin
import java.io.IOException;
import java.io.InputStream;
+
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;
import com.google.common.base.Objects;
import com.google.common.io.ByteStreams;
+
import org.apache.jackrabbit.oak.api.Blob;
import org.apache.jackrabbit.oak.api.PropertyState;
import org.apache.jackrabbit.oak.api.Type;
@@ -36,6 +38,7 @@ import static com.google.common.base.Obj
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static
org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.EMPTY_NODE;
+import static
org.apache.jackrabbit.oak.spi.state.AbstractNodeState.checkValidName;
/**
* In-memory node state builder.
@@ -306,18 +309,19 @@ public class MemoryNodeBuilder implement
@Override
public NodeBuilder getChildNode(String name) {
- return createChildBuilder(checkNotNull(name));
+ checkValidName(name);
+ return createChildBuilder(name);
}
@Override
public NodeBuilder setChildNode(String name) {
- return setChildNode(checkNotNull(name), EMPTY_NODE);
+ return setChildNode(name, EMPTY_NODE);
}
@Override
public NodeBuilder setChildNode(String name, NodeState state) {
checkState(exists(), "This builder does not exist: " + this.name);
- head().getMutableNodeState().setChildNode(checkNotNull(name),
checkNotNull(state));
+ head().getMutableNodeState().setChildNode(name, checkNotNull(state));
MemoryNodeBuilder builder = createChildBuilder(name);
updated();
return builder;
@@ -348,11 +352,14 @@ public class MemoryNodeBuilder implement
* @param newParent builder for the new parent.
* @param newName name of this child at the new parent
* @return {@code true} on success, {@code false} otherwise
+ * @throws IllegalArgumentException if the given name string is empty
+ * or contains the forward slash character
*/
@Override
- public boolean moveTo(NodeBuilder newParent, String newName) {
+ public boolean moveTo(NodeBuilder newParent, String newName)
+ throws IllegalArgumentException {
checkNotNull(newParent);
- checkNotNull(newName);
+ checkValidName(newName);
if (isRoot() || !exists() || newParent.hasChildNode(newName)) {
return false;
} else {
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java?rev=1569668&r1=1569667&r2=1569668&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MutableNodeState.java
Wed Feb 19 10:10:28 2014
@@ -90,9 +90,13 @@ class MutableNodeState extends AbstractN
* child.reset(state);
* return child;
* </pre>
+ *
+ * @throws IllegalArgumentException if the given name string is empty
+ * or contains the forward slash character
*/
@Nonnull
- MutableNodeState setChildNode(String name, NodeState state) {
+ MutableNodeState setChildNode(String name, NodeState state)
+ throws IllegalArgumentException {
assert base != null;
MutableNodeState child = nodes.get(name);
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java?rev=1569668&r1=1569667&r2=1569668&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeBuilder.java
Wed Feb 19 10:10:28 2014
@@ -190,9 +190,11 @@ public interface NodeBuilder {
* @since Oak 0.6
* @param name name of the child node
* @return child builder
+ * @throws IllegalArgumentException if the given name string is empty
+ * or contains the forward slash character
*/
@Nonnull
- NodeBuilder child(@Nonnull String name);
+ NodeBuilder child(@Nonnull String name) throws IllegalArgumentException;
/**
* Returns a builder for constructing changes to the named child node.
@@ -203,9 +205,12 @@ public interface NodeBuilder {
* @since Oak 0.7
* @param name name of the child node
* @return child builder, possibly non-existent
+ * @throws IllegalArgumentException if the given name string is empty
+ * or contains the forward slash character
*/
@Nonnull
- NodeBuilder getChildNode(@Nonnull String name);
+ NodeBuilder getChildNode(@Nonnull String name)
+ throws IllegalArgumentException;
/**
* Adds the named child node and returns a builder for modifying it.
@@ -214,9 +219,12 @@ public interface NodeBuilder {
* @since Oak 0.7
* @param name name of the child node
* @return child builder
+ * @throws IllegalArgumentException if the given name string is empty
+ * or contains the forward slash character
*/
@Nonnull
- NodeBuilder setChildNode(@Nonnull String name);
+ NodeBuilder setChildNode(@Nonnull String name)
+ throws IllegalArgumentException;
/**
* Adds or replaces a subtree.
@@ -224,9 +232,12 @@ public interface NodeBuilder {
* @param name name of the child node containing the new subtree
* @param nodeState subtree
* @return child builder
+ * @throws IllegalArgumentException if the given name string is empty
+ * or contains the forward slash character
*/
@Nonnull
- NodeBuilder setChildNode(String name, @Nonnull NodeState nodeState);
+ NodeBuilder setChildNode(@Nonnull String name, @Nonnull NodeState
nodeState)
+ throws IllegalArgumentException;
/**
* Remove this child node from its parent.
@@ -253,8 +264,11 @@ public interface NodeBuilder {
* @param newParent builder for the new parent.
* @param newName name of this child at the new parent
* @return {@code true} on success, {@code false} otherwise
+ * @throws IllegalArgumentException if the given name string is empty
+ * or contains the forward slash character
*/
- boolean moveTo(@Nonnull NodeBuilder newParent, @Nonnull String newName);
+ boolean moveTo(@Nonnull NodeBuilder newParent, @Nonnull String newName)
+ throws IllegalArgumentException;
/**
* Returns the current number of properties.
@@ -365,9 +379,12 @@ public interface NodeBuilder {
* Set a property state
* @param property The property state to set
* @return this builder
+ * @throws IllegalArgumentException if the property name is empty
+ * or contains the forward slash character
*/
@Nonnull
- NodeBuilder setProperty(@Nonnull PropertyState property);
+ NodeBuilder setProperty(@Nonnull PropertyState property)
+ throws IllegalArgumentException;
/**
* Set a property state
@@ -378,9 +395,12 @@ public interface NodeBuilder {
*
* @param name name of the property
* @return this builder
+ * @throws IllegalArgumentException if the property name is empty
+ * or contains the forward slash character
*/
@Nonnull
- <T> NodeBuilder setProperty(String name, @Nonnull T value);
+ <T> NodeBuilder setProperty(String name, @Nonnull T value)
+ throws IllegalArgumentException;
/**
* Set a property state
@@ -388,9 +408,12 @@ public interface NodeBuilder {
* @param value The value of this property
* @param <T> The type of this property.
* @return this builder
+ * @throws IllegalArgumentException if the property name is empty
+ * or contains the forward slash character
*/
@Nonnull
- <T> NodeBuilder setProperty(String name, @Nonnull T value, Type<T> type);
+ <T> NodeBuilder setProperty(String name, @Nonnull T value, Type<T> type)
+ throws IllegalArgumentException;
/**
* Remove the named property. This method has no effect if a