Class TreeUtil
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.tree.TreeUtil
-
public final class TreeUtil extends java.lang.ObjectUtility 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 TreeaddChild(@NotNull Tree tree, @NotNull java.lang.String childName, @NotNull java.lang.String primaryTypeName)Adds a new child tree with the given name and primary type name.static @NotNull TreeaddChild(@NotNull Tree parent, @NotNull java.lang.String name, @Nullable java.lang.String typeName, @NotNull Tree typeRoot, @Nullable java.lang.String userID)static voidaddMixin(@NotNull Tree tree, @NotNull java.lang.String mixinName, @NotNull Tree typeRoot, @Nullable java.lang.String userID)Add a mixin type to the giventree.static voidaddMixin(@NotNull Tree tree, @NotNull java.util.function.Function<Tree,java.lang.Iterable<java.lang.String>> existingMixins, @NotNull java.lang.String mixinName, @NotNull Tree typeRoot, @Nullable java.lang.String userID)Add a mixin type to the giventree.static voidautoCreateItems(@NotNull Tree tree, @NotNull Tree type, @NotNull Tree typeRoot, @Nullable java.lang.String userID)static @Nullable PropertyStateautoCreateProperty(@NotNull java.lang.String name, @NotNull Tree definition, @Nullable java.lang.String userID)static @Nullable java.lang.StringfindDefaultPrimaryType(@NotNull Tree definitions, boolean sns)static booleangetBoolean(@NotNull Tree tree, @NotNull java.lang.String propertyName)Returns the boolean representation of the property with the specifiedpropertyName.static @Nullable java.lang.StringgetDefaultChildType(@NotNull Tree typeRoot, @NotNull Tree parent, @NotNull java.lang.String childName)Finds the default primary type for a new child node with the given name.static @NotNull java.util.List<Tree>getEffectiveType(@NotNull Tree tree, @NotNull Tree typeRoot)Returns the effective node types of the given node.static longgetLong(@NotNull Tree tree, @NotNull java.lang.String name, long defaultValue)static @NotNull java.lang.Iterable<java.lang.String>getMixinTypeNames(@NotNull Tree tree)static @NotNull java.lang.Iterable<java.lang.String>getMixinTypeNames(@NotNull Tree tree, @NotNull LazyValue<Tree> readOnlyTree)static @Nullable java.lang.StringgetName(@NotNull Tree tree, @NotNull java.lang.String name)static @NotNull java.lang.Iterable<java.lang.String>getNames(@NotNull Tree tree, @NotNull java.lang.String name)static @NotNull TreegetOrAddChild(@NotNull Tree tree, @NotNull java.lang.String childName, @NotNull java.lang.String primaryTypeName)Combination ofTree.getChild(String)and adding a child including its jcr:primaryType property (i.e.static @Nullable java.lang.StringgetPrimaryTypeName(@NotNull Tree tree)static @Nullable java.lang.StringgetPrimaryTypeName(@NotNull Tree tree, @NotNull LazyValue<Tree> readOnlyTree)static @Nullable java.lang.StringgetString(@NotNull Tree tree, @NotNull java.lang.String propertyName)static @Nullable java.lang.StringgetString(@NotNull Tree tree, @NotNull java.lang.String name, @Nullable java.lang.String defaultValue)static @Nullable java.lang.Iterable<java.lang.String>getStrings(@NotNull Tree tree, @NotNull java.lang.String propertyName)static @Nullable TreegetTree(@NotNull Tree tree, @NotNull java.lang.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 Tree tree, @NotNull java.lang.String typeName, @NotNull Tree typeRoot)static booleanisReadOnlyTree(@NotNull Tree tree)Returnstrueif the specifiedtreeis a read-only tree..
-
-
-
Method Detail
-
getPrimaryTypeName
@Nullable public static @Nullable java.lang.String getPrimaryTypeName(@NotNull @NotNull Tree tree)
-
getPrimaryTypeName
@Nullable public static @Nullable java.lang.String getPrimaryTypeName(@NotNull @NotNull Tree tree, @NotNull @NotNull LazyValue<Tree> readOnlyTree)
-
getMixinTypeNames
@NotNull public static @NotNull java.lang.Iterable<java.lang.String> getMixinTypeNames(@NotNull @NotNull Tree tree)
-
getMixinTypeNames
@NotNull public static @NotNull java.lang.Iterable<java.lang.String> getMixinTypeNames(@NotNull @NotNull Tree tree, @NotNull @NotNull LazyValue<Tree> readOnlyTree)
-
getStrings
@Nullable public static @Nullable java.lang.Iterable<java.lang.String> getStrings(@NotNull @NotNull Tree tree, @NotNull @NotNull java.lang.String propertyName)
-
getString
@Nullable public static @Nullable java.lang.String getString(@NotNull @NotNull Tree tree, @NotNull @NotNull java.lang.String propertyName)
-
getString
@Nullable public static @Nullable java.lang.String getString(@NotNull @NotNull Tree tree, @NotNull @NotNull java.lang.String name, @Nullable @Nullable java.lang.String defaultValue)
-
getBoolean
public static boolean getBoolean(@NotNull @NotNull Tree tree, @NotNull @NotNull java.lang.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 java.lang.String getName(@NotNull @NotNull Tree tree, @NotNull @NotNull java.lang.String name)
-
getNames
@NotNull public static @NotNull java.lang.Iterable<java.lang.String> getNames(@NotNull @NotNull Tree tree, @NotNull @NotNull java.lang.String name)
-
getLong
public static long getLong(@NotNull @NotNull Tree tree, @NotNull @NotNull java.lang.String name, long defaultValue)
-
getTree
@Nullable public static @Nullable Tree getTree(@NotNull @NotNull Tree tree, @NotNull @NotNull java.lang.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 Tree addChild(@NotNull @NotNull Tree parent, @NotNull @NotNull java.lang.String name, @Nullable @Nullable java.lang.String typeName, @NotNull @NotNull Tree typeRoot, @Nullable @Nullable java.lang.String userID) throws javax.jcr.RepositoryException
- Throws:
javax.jcr.RepositoryException
-
addChild
@NotNull public static @NotNull Tree addChild(@NotNull @NotNull Tree tree, @NotNull @NotNull java.lang.String childName, @NotNull @NotNull java.lang.String primaryTypeName) throws javax.jcr.AccessDeniedException
Adds 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 Tree getOrAddChild(@NotNull @NotNull Tree tree, @NotNull @NotNull java.lang.String childName, @NotNull @NotNull java.lang.String primaryTypeName) throws javax.jcr.AccessDeniedException
Combination 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 Tree tree, @NotNull @NotNull java.lang.String mixinName, @NotNull @NotNull Tree typeRoot, @Nullable @Nullable java.lang.String userID) throws javax.jcr.RepositoryExceptionAdd a mixin type to the giventree. The implementation checks the effective type of the tree and will not add the mixin if it determines the tree is already of typemixinNamethrough the currently set primary or mixin types, directly or indirectly by type inheritance.- Parameters:
tree- tree where the mixin type is to be added.mixinName- name of the mixin to add.typeRoot- tree where type information is stored.userID- user id ornullif unknown.- Throws:
javax.jcr.RepositoryException- ifmixinNamedoes not refer to an existing type or the type it refers to is abstract or the type it refers to is a primary type.
-
addMixin
public static void addMixin(@NotNull @NotNull Tree tree, @NotNull @NotNull java.util.function.Function<Tree,java.lang.Iterable<java.lang.String>> existingMixins, @NotNull @NotNull java.lang.String mixinName, @NotNull @NotNull Tree typeRoot, @Nullable @Nullable java.lang.String userID) throws javax.jcr.RepositoryExceptionAdd a mixin type to the giventree. The implementation checks the effective type of the tree and will not add the mixin if it determines the tree is already of typemixinNamethrough the currently set primary or mixin types, directly or indirectly by type inheritance.- Parameters:
tree- tree where the mixin type is to be added.existingMixins- function to get the currently set mixin types from a tree.mixinName- name of the mixin to add.typeRoot- tree where type information is stored.userID- user id ornullif unknown.- Throws:
javax.jcr.RepositoryException- ifmixinNamedoes not refer to an existing type or the type it refers to is abstract or the type it refers to is a primary type.
-
autoCreateItems
public static void autoCreateItems(@NotNull @NotNull Tree tree, @NotNull @NotNull Tree type, @NotNull @NotNull Tree typeRoot, @Nullable @Nullable java.lang.String userID) throws javax.jcr.RepositoryException- Throws:
javax.jcr.RepositoryException
-
autoCreateProperty
@Nullable public static @Nullable PropertyState autoCreateProperty(@NotNull @NotNull java.lang.String name, @NotNull @NotNull Tree definition, @Nullable @Nullable java.lang.String userID)
-
getDefaultChildType
@Nullable public static @Nullable java.lang.String getDefaultChildType(@NotNull @NotNull Tree typeRoot, @NotNull @NotNull Tree parent, @NotNull @NotNull java.lang.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 java.util.List<Tree> getEffectiveType(@NotNull @NotNull Tree tree, @NotNull @NotNull Tree typeRoot)
Returns the effective node types of the given node.
-
findDefaultPrimaryType
@Nullable public static @Nullable java.lang.String findDefaultPrimaryType(@NotNull @NotNull Tree definitions, boolean sns)
-
isNodeType
public static boolean isNodeType(@NotNull @NotNull Tree tree, @NotNull @NotNull java.lang.String typeName, @NotNull @NotNull Tree typeRoot)
-
-