Class TreeUtil


  • public final class TreeUtil
    extends Object
    Utility providing common operations for the Tree that are not provided by the API.
    • 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 specified propertyName. If the property does not exist or is an array this method returns false.
        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 passed path from the location of the start tree or null if path results in a parent of the root.
        Parameters:
        tree - start tree
        path - path from the start tree
        Returns:
        tree located at path from start or null
      • getOrAddChild

        @NotNull
        public static @NotNull Tree getOrAddChild​(@NotNull
                                                  @NotNull Tree tree,
                                                  @NotNull
                                                  @NotNull String childName,
                                                  @NotNull
                                                  @NotNull String primaryTypeName)
                                           throws AccessDeniedException
        Combination of Tree.getChild(String) and adding a child including its jcr:primaryType property (i.e. Tree.addChild(String) and Tree.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.
      • 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 tree
        parent - parent node
        childName - 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)
      • isReadOnlyTree

        public static boolean isReadOnlyTree​(@NotNull
                                             @NotNull Tree tree)
        Returns true if the specified tree is a read-only tree..
        Parameters:
        tree - The tree object to be tested.
        Returns:
        true if the specified tree is an immutable read-only tree.
        See Also:
        ReadOnly