Class ComponentUtils
java.lang.Object
com.adobe.cq.wcm.core.components.util.ComponentUtils
Utility helper functions for components.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic @NotNull StringgenerateId(@NotNull String prefix, @NotNull String path) Returns an ID based on the prefix, the ID_SEPARATOR and a hash of the path, e.g.getChildComponents(@NotNull Resource resource, @Nullable SlingHttpServletRequest request) Gets a list of all child resources that are components.static LinkedHashMap<String, ComponentExporter> getComponentModels(@NotNull SlingModelFilter slingModelFilter, @NotNull ModelFactory modelFactory, @NotNull List<Resource> childComponents, @NotNull SlingHttpServletRequest request, @NotNull Class<ComponentExporter> modelClass) Gets the models for the child resources that are components, filtered by the Sling Model Filter.static LinkedHashMap<String, ComponentExporter> getComponentModels(@NotNull SlingModelFilter slingModelFilter, @NotNull ModelFactory modelFactory, @NotNull SlingHttpServletRequest request, @NotNull Class<ComponentExporter> modelClass) Gets the models for the child resources that are components, filtered by the Sling Model Filter.static @NotNull ResourcegetEffectiveResource(@NotNull Resource resource, @Nullable SlingHttpServletRequest request) Gets the effectiveTemplatedResourcefor the specified resource.static @Nullable ResourcegetFeaturedImage(@NotNull Page page) Returns the resource holding the properties of the featured image of the page.static @NotNull StringgetId(@NotNull Resource resource, @Nullable Page currentPage, @Nullable ComponentContext componentContext) static @NotNull StringgetId(@NotNull Resource resource, @Nullable Page currentPage, @Nullable String resourceCallerPath, @Nullable ComponentContext componentContext) Get the ID property value if set (usinggetPropertyId(Resource), otherwise generate a new ID (usinggenerateId(Resource, Page, String, ComponentContext).static booleanisDataLayerEnabled(@Nullable SlingHttpServletRequest request, @NotNull Resource resource) Check if data layer is enabled.static booleanisDataLayerEnabled(@NotNull Resource resource) Check if data layer is enabled.
-
Field Details
-
NN_SLING_CONFIGS
Name of the node holding the context aware configurations below /conf/{site-name};- See Also:
-
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 happensresource- The resource to check.- Returns:
- True if data layer is enabled for this resource, false otherwise.
-
isDataLayerEnabled
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 (usinggetPropertyId(Resource), otherwise generate a new ID (usinggenerateId(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 IDpath- the resource path- Returns:
- the generated ID
-
getFeaturedImage
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 effectiveTemplatedResourcefor 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 toContainer.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 toContainer.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.
-