Class TreeUtil
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.tree.TreeUtil
-
public final class TreeUtil extends Object
Utility providing common operations for theTreethat are not provided by the API.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @NotNull org.apache.jackrabbit.oak.api.TreeaddChild(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull String childName, @NotNull String primaryTypeName)Adds a new child tree with the given name and primary type name.static @NotNull org.apache.jackrabbit.oak.api.TreeaddChild(@NotNull org.apache.jackrabbit.oak.api.Tree parent, @NotNull String name, @Nullable String typeName, @NotNull org.apache.jackrabbit.oak.api.Tree typeRoot, @Nullable String userID)static voidaddMixin(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull String mixinName, @NotNull org.apache.jackrabbit.oak.api.Tree typeRoot, @Nullable String userID)static voidautoCreateItems(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull org.apache.jackrabbit.oak.api.Tree type, @NotNull org.apache.jackrabbit.oak.api.Tree typeRoot, @Nullable String userID)static @Nullable org.apache.jackrabbit.oak.api.PropertyStateautoCreateProperty(@NotNull String name, @NotNull org.apache.jackrabbit.oak.api.Tree definition, @Nullable String userID)static @Nullable StringfindDefaultPrimaryType(@NotNull org.apache.jackrabbit.oak.api.Tree definitions, boolean sns)static booleangetBoolean(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull String propertyName)Returns the boolean representation of the property with the specifiedpropertyName.static @Nullable StringgetDefaultChildType(@NotNull org.apache.jackrabbit.oak.api.Tree typeRoot, @NotNull org.apache.jackrabbit.oak.api.Tree parent, @NotNull String childName)Finds the default primary type for a new child node with the given name.static @NotNull List<org.apache.jackrabbit.oak.api.Tree>getEffectiveType(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull org.apache.jackrabbit.oak.api.Tree typeRoot)Returns the effective node types of the given node.static longgetLong(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull String name, long defaultValue)static @NotNull Iterable<String>getMixinTypeNames(@NotNull org.apache.jackrabbit.oak.api.Tree tree)static @NotNull Iterable<String>getMixinTypeNames(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull org.apache.jackrabbit.oak.commons.LazyValue<org.apache.jackrabbit.oak.api.Tree> readOnlyTree)static @Nullable StringgetName(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull String name)static @NotNull Iterable<String>getNames(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull String name)static @NotNull org.apache.jackrabbit.oak.api.TreegetOrAddChild(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull String childName, @NotNull String primaryTypeName)Combination ofTree.getChild(String)and adding a child including its jcr:primaryType property (i.e.static @Nullable StringgetPrimaryTypeName(@NotNull org.apache.jackrabbit.oak.api.Tree tree)static @Nullable StringgetPrimaryTypeName(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull org.apache.jackrabbit.oak.commons.LazyValue<org.apache.jackrabbit.oak.api.Tree> readOnlyTree)static @Nullable StringgetString(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull String propertyName)static @Nullable StringgetString(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull String name, @Nullable String defaultValue)static @Nullable Iterable<String>getStrings(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull String propertyName)static @Nullable org.apache.jackrabbit.oak.api.TreegetTree(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull String path)Return the possibly non existing tree located at the passedpathfrom the location of the starttreeornullifpathresults in a parent of the root.static booleanisNodeType(@NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull String typeName, @NotNull org.apache.jackrabbit.oak.api.Tree typeRoot)static booleanisReadOnlyTree(@NotNull org.apache.jackrabbit.oak.api.Tree tree)Returnstrueif the specifiedtreeis a read-only tree..
-
-
-
Method Detail
-
getPrimaryTypeName
@Nullable public static @Nullable String getPrimaryTypeName(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree)
-
getPrimaryTypeName
@Nullable public static @Nullable String getPrimaryTypeName(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull org.apache.jackrabbit.oak.commons.LazyValue<org.apache.jackrabbit.oak.api.Tree> readOnlyTree)
-
getMixinTypeNames
@NotNull public static @NotNull Iterable<String> getMixinTypeNames(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree)
-
getMixinTypeNames
@NotNull public static @NotNull Iterable<String> getMixinTypeNames(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull org.apache.jackrabbit.oak.commons.LazyValue<org.apache.jackrabbit.oak.api.Tree> readOnlyTree)
-
getStrings
@Nullable public static @Nullable Iterable<String> getStrings(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull String propertyName)
-
getString
@Nullable public static @Nullable String getString(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull String propertyName)
-
getString
@Nullable public static @Nullable String getString(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull String name, @Nullable @Nullable String defaultValue)
-
getBoolean
public static boolean getBoolean(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull String propertyName)Returns the boolean representation of the property with the specifiedpropertyName. If the property does not exist oris an arraythis method returnsfalse.- Parameters:
tree- The target tree.propertyName- The name of the property.- Returns:
- the boolean representation of the property state with the given
name. This utility returns
falseif the property does not exist or is an multivalued property.
-
getName
@Nullable public static @Nullable String getName(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull String name)
-
getNames
@NotNull public static @NotNull Iterable<String> getNames(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull String name)
-
getLong
public static long getLong(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull String name, long defaultValue)
-
getTree
@Nullable public static @Nullable org.apache.jackrabbit.oak.api.Tree getTree(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull String path)Return the possibly non existing tree located at the passedpathfrom the location of the starttreeornullifpathresults in a parent of the root.- Parameters:
tree- start treepath- path from the start tree- Returns:
- tree located at
pathfromstartornull
-
addChild
@NotNull public static @NotNull org.apache.jackrabbit.oak.api.Tree addChild(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree parent, @NotNull @NotNull String name, @Nullable @Nullable String typeName, @NotNull @NotNull org.apache.jackrabbit.oak.api.Tree typeRoot, @Nullable @Nullable String userID) throws javax.jcr.RepositoryException- Throws:
javax.jcr.RepositoryException
-
addChild
@NotNull public static @NotNull org.apache.jackrabbit.oak.api.Tree addChild(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull String childName, @NotNull @NotNull String primaryTypeName) throws javax.jcr.AccessDeniedExceptionAdds a new child tree with the given name and primary type name. This method is a shortcut for callingTree.addChild(String)andTree.setProperty(String, Object, org.apache.jackrabbit.oak.api.Type)where the property name isJcrConstants.JCR_PRIMARYTYPE. Note, that this method in addition verifies if the created tree exists and is accessible in order to avoidIllegalStateExceptionupon subsequent modification of the new child.- Parameters:
childName- The Oak name of the child item.primaryTypeName- The Oak name of the primary node type.- Returns:
- The new child tree with the specified name and primary type.
- Throws:
javax.jcr.AccessDeniedException- If the child does not exist after creation.
-
getOrAddChild
@NotNull public static @NotNull org.apache.jackrabbit.oak.api.Tree getOrAddChild(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull String childName, @NotNull @NotNull String primaryTypeName) throws javax.jcr.AccessDeniedExceptionCombination ofTree.getChild(String)and adding a child including its jcr:primaryType property (i.e.Tree.addChild(String)andTree.setProperty(PropertyState)) in case no tree exists with the specified name.- Parameters:
childName- The Oak name of the child item.primaryTypeName- The Oak name of the primary node type.- Returns:
- The new child node with the specified name and primary type.
- Throws:
javax.jcr.AccessDeniedException- If the child does not exist after creation.
-
addMixin
public static void addMixin(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull String mixinName, @NotNull @NotNull org.apache.jackrabbit.oak.api.Tree typeRoot, @Nullable @Nullable String userID) throws javax.jcr.RepositoryException- Throws:
javax.jcr.RepositoryException
-
autoCreateItems
public static void autoCreateItems(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull org.apache.jackrabbit.oak.api.Tree type, @NotNull @NotNull org.apache.jackrabbit.oak.api.Tree typeRoot, @Nullable @Nullable String userID) throws javax.jcr.RepositoryException- Throws:
javax.jcr.RepositoryException
-
autoCreateProperty
@Nullable public static @Nullable org.apache.jackrabbit.oak.api.PropertyState autoCreateProperty(@NotNull @NotNull String name, @NotNull @NotNull org.apache.jackrabbit.oak.api.Tree definition, @Nullable @Nullable String userID)
-
getDefaultChildType
@Nullable public static @Nullable String getDefaultChildType(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree typeRoot, @NotNull @NotNull org.apache.jackrabbit.oak.api.Tree parent, @NotNull @NotNull String childName)
Finds the default primary type for a new child node with the given name.- Parameters:
typeRoot- root of the/jcr:system/jcr:nodeTypestreeparent- parent nodechildName- name of the new child node- Returns:
- name of the default type, or
nullif not available
-
getEffectiveType
@NotNull public static @NotNull List<org.apache.jackrabbit.oak.api.Tree> getEffectiveType(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull org.apache.jackrabbit.oak.api.Tree typeRoot)
Returns the effective node types of the given node.
-
findDefaultPrimaryType
@Nullable public static @Nullable String findDefaultPrimaryType(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree definitions, boolean sns)
-
isNodeType
public static boolean isNodeType(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree, @NotNull @NotNull String typeName, @NotNull @NotNull org.apache.jackrabbit.oak.api.Tree typeRoot)
-
isReadOnlyTree
public static boolean isReadOnlyTree(@NotNull @NotNull org.apache.jackrabbit.oak.api.Tree tree)Returnstrueif the specifiedtreeis a read-only tree..- Parameters:
tree- The tree object to be tested.- Returns:
trueif the specified tree is an immutable read-only tree.- See Also:
ReadOnly
-
-