Class ComponentUtils

java.lang.Object
com.adobe.cq.wcm.core.components.util.ComponentUtils

public final class ComponentUtils extends Object
Utility helper functions for components.
  • Field Details

    • NN_SLING_CONFIGS

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

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

    • isDataLayerEnabled

      public static boolean isDataLayerEnabled(@Nullable @Nullable SlingHttpServletRequest request, @NotNull @NotNull Resource resource)
      Check if data layer is enabled.
      Parameters:
      request - The request in which context this happens
      resource - The resource to check.
      Returns:
      True if data layer is enabled for this resource, false otherwise.
    • 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 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 String getId(@NotNull @NotNull Resource resource, @Nullable @Nullable Page currentPage, @Nullable @Nullable 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 String generateId(@NotNull @NotNull String prefix, @NotNull @NotNull 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
    • getEffectiveResource

      @NotNull public static @NotNull Resource getEffectiveResource(@NotNull @NotNull Resource resource, @Nullable @Nullable SlingHttpServletRequest request)
      Gets the effective TemplatedResource for the specified resource.
      Parameters:
      resource - The resource for which to get the TemplateResource.
      request - The current request. This is needed if the resource is potentially part of the template structure.
      Returns:
      The TemplatedResource, or the current resource if it cannot be adapted to a TemplatedResource.
    • getChildComponents

      @NotNull public static @NotNull List<Resource> getChildComponents(@NotNull @NotNull Resource resource, @Nullable @Nullable SlingHttpServletRequest request)
      Gets a list of all child resources that are components.
      Parameters:
      resource - The resource for which to get the children.
      request - The current request. This is needed if the resource is potentially part of the template structure.
      Returns:
      The list of child resources that are components.
    • getComponentModels

      public static LinkedHashMap<String,ComponentExporter> getComponentModels(@NotNull @NotNull SlingModelFilter slingModelFilter, @NotNull @NotNull ModelFactory modelFactory, @NotNull @NotNull SlingHttpServletRequest request, @NotNull @NotNull Class<ComponentExporter> modelClass)
      Gets the models for the child resources that are components, filtered by the Sling Model Filter. This should only be used for JSON export, for other usages refer to Container.getChildren().
      Parameters:
      request - The current request.
      modelClass - The child model class.
      Returns:
      Map of models wherein the key is the child name, and the value is it's model.
    • getComponentModels

      public static LinkedHashMap<String,ComponentExporter> getComponentModels(@NotNull @NotNull SlingModelFilter slingModelFilter, @NotNull @NotNull ModelFactory modelFactory, @NotNull @NotNull List<Resource> childComponents, @NotNull @NotNull SlingHttpServletRequest request, @NotNull @NotNull Class<ComponentExporter> modelClass)
      Gets the models for the child resources that are components, filtered by the Sling Model Filter. This should only be used for JSON export, for other usages refer to Container.getChildren()
      Parameters:
      request - The current request.
      modelClass - The child model class.
      Returns:
      Map of models wherein the key is the child name, and the value is it's model.