Class ComponentUtils
- java.lang.Object
-
- com.adobe.cq.forms.core.components.util.ComponentUtils
-
public class ComponentUtils extends java.lang.ObjectUtility helper functions for components.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.Dateclone(@Nullable java.util.Date date)Returns clone of the date object (mutable) provided as inputstatic @NotNull java.lang.Object[]coerce(BaseConstraint.Type type, @NotNull java.lang.Object[] objArr)static @NotNull java.lang.StringgetEncodedPath(@NotNull java.lang.String path)Returns the base64 encoded pathstatic <T> TgetExclusiveValue(java.lang.Object exclusiveValue, T value, java.lang.Object exclusiveValueCheck)Retrieves the exclusive value based on certain conditions.static ResourcegetFormContainer(Resource resource)Returns the form container resourcestatic ResourcegetFragmentContainer(ResourceResolver resourceResolver, @NotNull java.lang.String fragmentPath)static com.day.cq.wcm.api.policies.ContentPolicygetPolicy(java.lang.String contentPath, ResourceResolver resourceResolver)static java.util.List<java.lang.String>getSupportedSubmitActions(org.apache.http.osgi.services.HttpClientBuilderFactory clientBuilderFactory)Retrieves a list of supported submit actions from the Adobe Forms service.static @org.jetbrains.annotations.NotNull booleanisAFContainer(@NotNull Resource resource)Checks if the given resource if a core adaptive form containerstatic booleanisFragmentComponent(Resource resource)static java.lang.NumberparseNumber(@Nullable java.lang.String value)Parses a given string value into a Number.static booleanshouldIncludeSubmitProperties(SlingHttpServletRequest request)Determines whether submit properties should be included in the form definition.static @NotNull java.lang.Stringtranslate(@NotNull java.lang.String propertyValue, @NotNull java.lang.String propertyName, @NotNull Resource resource, @Nullable com.day.cq.i18n.I18n i18n)Translates the given property as per theI18nobject passedstatic @NotNull java.lang.Stringtranslate(@NotNull java.lang.String propertyValue, @NotNull java.lang.String propertyName, @NotNull ValueMap valueMap, @Nullable com.day.cq.i18n.I18n i18n)Translates the given property as per theI18nobject passed
-
-
-
Method Detail
-
getEncodedPath
@NotNull public static @NotNull java.lang.String getEncodedPath(@NotNull @NotNull java.lang.String path)Returns the base64 encoded path- Parameters:
path- page path- Returns:
- base64 encoded path
-
isAFContainer
@NotNull public static @org.jetbrains.annotations.NotNull boolean isAFContainer(@NotNull @NotNull Resource resource)Checks if the given resource if a core adaptive form container- Parameters:
resource- reference to theResource- Returns:
- true, if it is an adaptive form container, false otherwise
-
getFormContainer
public static Resource getFormContainer(Resource resource)
Returns the form container resource- Parameters:
resource- reference to theResource- Returns:
- form container resource, null if no form container found
-
translate
@NotNull public static @NotNull java.lang.String translate(@NotNull @NotNull java.lang.String propertyValue, @NotNull @NotNull java.lang.String propertyName, @NotNull @NotNull Resource resource, @Nullable @Nullable com.day.cq.i18n.I18n i18n)Translates the given property as per theI18nobject passed- Parameters:
propertyValue- value of the property (for example, in case of array type property, one needs to pass the value stored in array index)propertyName- name of the propertyresource- reference to theResourcei18n- reference to theI18nobject- Returns:
- translated value
-
translate
@NotNull public static @NotNull java.lang.String translate(@NotNull @NotNull java.lang.String propertyValue, @NotNull @NotNull java.lang.String propertyName, @NotNull @NotNull ValueMap valueMap, @Nullable @Nullable com.day.cq.i18n.I18n i18n)Translates the given property as per theI18nobject passed- Parameters:
propertyValue- value of the property (for example, in case of array type property, one needs to pass the value stored in array index)propertyName- name of the propertyvalueMap- reference to theValueMapi18n- reference to theI18nobject- Returns:
- translated value
-
clone
public static java.util.Date clone(@Nullable @Nullable java.util.Date date)Returns clone of the date object (mutable) provided as input- Parameters:
date- date- Returns:
- clone of date object
-
getExclusiveValue
public static <T> T getExclusiveValue(java.lang.Object exclusiveValue, T value, java.lang.Object exclusiveValueCheck)Retrieves the exclusive value based on certain conditions.- Parameters:
exclusiveValue- The exclusive value to be checked.value- The actual value to be returned if conditions are met.exclusiveValueCheck- An additional check for exclusive value.- Returns:
- The exclusive value if conditions are met; otherwise, null.
-
parseNumber
public static java.lang.Number parseNumber(@Nullable @Nullable java.lang.String value)Parses a given string value into a Number. The method attempts to parse the string as a Long first, and if that fails, it attempts to parse it as a Float. If both parsing attempts fail, it returns null.- Parameters:
value- the string value to be parsed, can be null- Returns:
- the parsed Number (Long or Float), or null if the value cannot be parsed
-
coerce
@NotNull public static @NotNull java.lang.Object[] coerce(@NotNull BaseConstraint.Type type, @NotNull @NotNull java.lang.Object[] objArr)
-
getPolicy
public static com.day.cq.wcm.api.policies.ContentPolicy getPolicy(java.lang.String contentPath, ResourceResolver resourceResolver)
-
getFragmentContainer
public static Resource getFragmentContainer(ResourceResolver resourceResolver, @NotNull @NotNull java.lang.String fragmentPath)
-
isFragmentComponent
public static boolean isFragmentComponent(Resource resource)
-
shouldIncludeSubmitProperties
public static boolean shouldIncludeSubmitProperties(SlingHttpServletRequest request)
Determines whether submit properties should be included in the form definition.This method checks if the request contains x-adobe-form-definition attribute or header and if it is equal to submission that indicates submit properties should be included in the form definition.
- Parameters:
request- theSlingHttpServletRequestto check- Returns:
- true if submit properties should be included, false otherwise
-
getSupportedSubmitActions
public static java.util.List<java.lang.String> getSupportedSubmitActions(org.apache.http.osgi.services.HttpClientBuilderFactory clientBuilderFactory)
Retrieves a list of supported submit actions from the Adobe Forms service.This method makes an HTTP GET request to the Adobe Forms service to fetch the list of supported submit actions. The response is expected to be a JSON object containing a "submissions" array of action names, which is then converted to a list.
If the request fails or an error occurs during processing, an error is logged and an empty list is returned.
- Parameters:
clientBuilderFactory- The HTTP client builder factory used to create the HTTP client- Returns:
- A list of supported submit action names, or an empty list if the request fails
-
-