Class ComponentUtils


  • public final class ComponentUtils
    extends java.lang.Object
    Utility helper functions for components.
    • Field Detail

      • NN_SLING_CONFIGS

        public static final java.lang.String NN_SLING_CONFIGS
        Name of the node holding the context aware configurations below /conf/{site-name};
        See Also:
        Constant Field Values
      • ID_SEPARATOR

        public static final java.lang.String ID_SEPARATOR
        Name of the separator character used between prefix and hash when generating an ID, e.g. image-5c7e0ef90d
        See Also:
        Constant Field Values
    • Method Detail

      • isDataLayerEnabled

        public static boolean isDataLayerEnabled​(@NotNull
                                                 @NotNull Resource resource)
        Check if data layer is enabled.
        Parameters:
        resource - The resource to check.
        Returns:
        True if data layer is enabled for this resource, false otherwise.
      • getId

        @NotNull
        public static @NotNull java.lang.String getId​(@NotNull
                                                      @NotNull Resource resource,
                                                      @Nullable
                                                      @Nullable Page currentPage,
                                                      @Nullable
                                                      @Nullable ComponentContext componentContext)
        Parameters:
        resource - The resource for which to get or generate an ID.
        currentPage - The current request page.
        componentContext - The current component context.
        Returns:
        The ID property value for the specified resource, or a generated ID if not set.
      • getId

        @NotNull
        public static @NotNull java.lang.String getId​(@NotNull
                                                      @NotNull Resource resource,
                                                      @Nullable
                                                      @Nullable Page currentPage,
                                                      @Nullable
                                                      @Nullable java.lang.String resourceCallerPath,
                                                      @Nullable
                                                      @Nullable ComponentContext componentContext)
        Get the ID property value if set (using getPropertyId(Resource), otherwise generate a new ID (using generateId(Resource, Page, String, ComponentContext).
        Parameters:
        resource - The resource for which to get or generate an ID.
        currentPage - The current request page.
        resourceCallerPath - The path of the page or template resource that references this component.
        componentContext - The current component context.
        Returns:
        The ID property value for the specified resource, or a generated ID if not set.
      • generateId

        @NotNull
        public static @NotNull java.lang.String generateId​(@NotNull
                                                           @NotNull java.lang.String prefix,
                                                           @NotNull
                                                           @NotNull java.lang.String path)
        Returns an ID based on the prefix, the ID_SEPARATOR and a hash of the path, e.g. image-5c7e0ef90d
        Parameters:
        prefix - the prefix for the ID
        path - the resource path
        Returns:
        the generated ID
      • getFeaturedImage

        @Nullable
        public static @Nullable Resource getFeaturedImage​(@NotNull
                                                          @NotNull Page page)
        Returns the resource holding the properties of the featured image of the page.
        Parameters:
        page - the page
        Returns:
        the featured image resource