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 Summary
Fields Modifier and Type Field Description static String
ID_SEPARATOR
Name of the separator character used between prefix and hash when generating an ID, e.g.static String
NN_SLING_CONFIGS
Name of the node holding the context aware configurations below /conf/{site-name};
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static @NotNull String
generateId(@NotNull String prefix, @NotNull String path)
Returns an ID based on the prefix, the ID_SEPARATOR and a hash of the path, e.g.static @Nullable Resource
getFeaturedImage(@NotNull Page page)
Returns the resource holding the properties of the featured image of the page.static @NotNull String
getId(@NotNull Resource resource, @Nullable Page currentPage, @Nullable ComponentContext componentContext)
static @NotNull String
getId(@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 boolean
isDataLayerEnabled(@NotNull Resource resource)
Check if data layer is enabled.
-
-
-
Field Detail
-
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:
- Constant Field Values
-
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:
- 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 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
-
-