Class TreeUtil
- java.lang.Object
-
- org.apache.jackrabbit.oak.plugins.tree.TreeUtil
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @NotNull Tree
addChild(@NotNull Tree tree, @NotNull String childName, @NotNull String primaryTypeName)
Adds a new child tree with the given name and primary type name.static @NotNull Tree
addChild(@NotNull Tree parent, @NotNull String name, @Nullable String typeName, @NotNull Tree typeRoot, @Nullable String userID)
static void
addMixin(@NotNull Tree tree, @NotNull String mixinName, @NotNull Tree typeRoot, @Nullable String userID)
Add a mixin type to the giventree
.static void
addMixin(@NotNull Tree tree, @NotNull Function<Tree,Iterable<String>> existingMixins, @NotNull String mixinName, @NotNull Tree typeRoot, @Nullable String userID)
Add a mixin type to the giventree
.static void
autoCreateItems(@NotNull Tree tree, @NotNull Tree type, @NotNull Tree typeRoot, @Nullable String userID)
static @Nullable PropertyState
autoCreateProperty(@NotNull String name, @NotNull Tree definition, @Nullable String userID)
static @Nullable String
findDefaultPrimaryType(@NotNull Tree definitions, boolean sns)
static boolean
getBoolean(@NotNull Tree tree, @NotNull String propertyName)
Returns the boolean representation of the property with the specifiedpropertyName
.static @Nullable String
getDefaultChildType(@NotNull Tree typeRoot, @NotNull Tree parent, @NotNull String childName)
Finds the default primary type for a new child node with the given name.static @NotNull List<Tree>
getEffectiveType(@NotNull Tree tree, @NotNull Tree typeRoot)
Returns the effective node types of the given node.static long
getLong(@NotNull Tree tree, @NotNull String name, long defaultValue)
static @NotNull Iterable<String>
getMixinTypeNames(@NotNull Tree tree)
static @NotNull Iterable<String>
getMixinTypeNames(@NotNull Tree tree, @NotNull LazyValue<Tree> readOnlyTree)
static @Nullable String
getName(@NotNull Tree tree, @NotNull String name)
static @NotNull Iterable<String>
getNames(@NotNull Tree tree, @NotNull String name)
static @NotNull Tree
getOrAddChild(@NotNull 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 String
getPrimaryTypeName(@NotNull Tree tree)
static @Nullable String
getPrimaryTypeName(@NotNull Tree tree, @NotNull LazyValue<Tree> readOnlyTree)
static @Nullable String
getString(@NotNull Tree tree, @NotNull String propertyName)
static @Nullable String
getString(@NotNull Tree tree, @NotNull String name, @Nullable String defaultValue)
static @Nullable Iterable<String>
getStrings(@NotNull Tree tree, @NotNull String propertyName)
static @Nullable Tree
getTree(@NotNull Tree tree, @NotNull String path)
Return the possibly non existing tree located at the passedpath
from the location of the starttree
ornull
ifpath
results in a parent of the root.static boolean
isNodeType(@NotNull Tree tree, @NotNull String typeName, @NotNull Tree typeRoot)
static boolean
isReadOnlyTree(@NotNull Tree tree)
Returnstrue
if the specifiedtree
is a read-only tree..
-
-
-
Method Detail
-
getPrimaryTypeName
@Nullable public static @Nullable String getPrimaryTypeName(@NotNull @NotNull Tree tree)
-
getPrimaryTypeName
@Nullable public static @Nullable String getPrimaryTypeName(@NotNull @NotNull Tree tree, @NotNull @NotNull LazyValue<Tree> readOnlyTree)
-
getMixinTypeNames
@NotNull public static @NotNull Iterable<String> getMixinTypeNames(@NotNull @NotNull Tree tree)
-
getMixinTypeNames
@NotNull public static @NotNull Iterable<String> getMixinTypeNames(@NotNull @NotNull Tree tree, @NotNull @NotNull LazyValue<Tree> readOnlyTree)
-
getStrings
@Nullable public static @Nullable Iterable<String> getStrings(@NotNull @NotNull Tree tree, @NotNull @NotNull String propertyName)
-
getString
@Nullable public static @Nullable String getString(@NotNull @NotNull Tree tree, @NotNull @NotNull String propertyName)
-
getString
@Nullable public static @Nullable String getString(@NotNull @NotNull Tree tree, @NotNull @NotNull String name, @Nullable @Nullable String defaultValue)
-
getBoolean
public static boolean getBoolean(@NotNull @NotNull Tree tree, @NotNull @NotNull String propertyName)
Returns the boolean representation of the property with the specifiedpropertyName
. If the property does not exist oris an array
this 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
false
if the property does not exist or is an multivalued property.
-
getName
@Nullable public static @Nullable String getName(@NotNull @NotNull Tree tree, @NotNull @NotNull String name)
-
getNames
@NotNull public static @NotNull Iterable<String> getNames(@NotNull @NotNull Tree tree, @NotNull @NotNull String name)
-
getLong
public static long getLong(@NotNull @NotNull Tree tree, @NotNull @NotNull String name, long defaultValue)
-
getTree
@Nullable public static @Nullable Tree getTree(@NotNull @NotNull Tree tree, @NotNull @NotNull String path)
Return the possibly non existing tree located at the passedpath
from the location of the starttree
ornull
ifpath
results in a parent of the root.- Parameters:
tree
- start treepath
- path from the start tree- Returns:
- tree located at
path
fromstart
ornull
-
addChild
@NotNull public static @NotNull Tree addChild(@NotNull @NotNull Tree parent, @NotNull @NotNull String name, @Nullable @Nullable String typeName, @NotNull @NotNull Tree typeRoot, @Nullable @Nullable String userID) throws RepositoryException
- Throws:
RepositoryException
-
addChild
@NotNull public static @NotNull Tree addChild(@NotNull @NotNull Tree tree, @NotNull @NotNull String childName, @NotNull @NotNull String primaryTypeName) throws 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 avoidIllegalStateException
upon 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:
AccessDeniedException
- If the child does not exist after creation.
-
getOrAddChild
@NotNull public static @NotNull Tree getOrAddChild(@NotNull @NotNull Tree tree, @NotNull @NotNull String childName, @NotNull @NotNull String primaryTypeName) throws 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:
AccessDeniedException
- If the child does not exist after creation.
-
addMixin
public static void addMixin(@NotNull @NotNull Tree tree, @NotNull @NotNull String mixinName, @NotNull @NotNull Tree typeRoot, @Nullable @Nullable String userID) throws RepositoryException
Add 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 typemixinName
through 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 ornull
if unknown.- Throws:
RepositoryException
- ifmixinName
does 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 Function<Tree,Iterable<String>> existingMixins, @NotNull @NotNull String mixinName, @NotNull @NotNull Tree typeRoot, @Nullable @Nullable String userID) throws RepositoryException
Add 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 typemixinName
through 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 ornull
if unknown.- Throws:
RepositoryException
- ifmixinName
does 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 String userID) throws RepositoryException
- Throws:
RepositoryException
-
autoCreateProperty
@Nullable public static @Nullable PropertyState autoCreateProperty(@NotNull @NotNull String name, @NotNull @NotNull Tree definition, @Nullable @Nullable String userID)
-
getDefaultChildType
@Nullable public static @Nullable String getDefaultChildType(@NotNull @NotNull Tree typeRoot, @NotNull @NotNull 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:nodeTypes
treeparent
- parent nodechildName
- name of the new child node- Returns:
- name of the default type, or
null
if not available
-
getEffectiveType
@NotNull public static @NotNull 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 String findDefaultPrimaryType(@NotNull @NotNull Tree definitions, boolean sns)
-
isNodeType
public static boolean isNodeType(@NotNull @NotNull Tree tree, @NotNull @NotNull String typeName, @NotNull @NotNull Tree typeRoot)
-
-