Class GuideUtils


  • public class GuideUtils
    extends java.lang.Object
    • Constructor Detail

      • GuideUtils

        public GuideUtils()
    • Method Detail

      • getSignConfigPath

        public static java.lang.String getSignConfigPath​(Resource guideContainerResource)
        Generic utility to get adobe sign configuration path.
        Parameters:
        guideContainerResource - - resource representing guide container of the form
        Returns:
        String - adobe sign configured path if present
      • getAdobeSignFields

        public static JSONArray getAdobeSignFields​(java.lang.String htmlVal)
        Generic utility to parse adobe sign fields from HTML
        Parameters:
        htmlVal - - html string having adobe sign text tags
        Returns:
        JSONArray - array of names of adobe sign fields
      • getTextVariables

        public static <T> java.util.List<T> getTextVariables​(Resource resource,
                                                             java.lang.Class<T> variableClass)
        Generic utility to get Text variable from text resource
        Parameters:
        resource - - Text resource
        variableClass -
        Returns:
        List - list of document fragment variables
      • formatDateDefaultValues

        public static java.lang.String formatDateDefaultValues​(java.lang.String htmlVal)
        Generic utility to parse adobe sign date fields from HTML and convert date fields default value in its date format.
        Parameters:
        htmlVal - - stringified html having adobe sign text tags
        Returns:
        String html, with correct default values for date
      • updateSigner

        public static java.lang.String updateSigner​(java.lang.String name,
                                                    int signerIndex,
                                                    java.lang.String htmlVal)
        Utility to update signer information in Static text/ guide textdraw HTML, while creating guideJson
      • convertStringToMap

        public static java.util.Map<java.lang.String,​java.lang.String> convertStringToMap​(java.lang.String params)
        Generic utility to convert string into Map
      • hasNestablePanelLayout

        public static boolean hasNestablePanelLayout​(GuideNode parentNode,
                                                     GuideNode node)
      • getGuideContainerPath

        public static java.lang.String getGuideContainerPath​(SlingHttpServletRequest request,
                                                             Resource resource)
        This is a public api used to extract the guideContainer asset from the content. Returns inline guide container if there is no guideRef property present in the guideContainer else returns the guideContainer present inline
        Parameters:
        request - sling http servlet request
        resource - sling resource
        Returns:
        path to the form container
      • getOptions

        public static java.util.ArrayList<java.lang.String> getOptions​(java.lang.String keyValueString,
                                                                       java.lang.String key,
                                                                       I18n i18n,
                                                                       boolean removeEscaping,
                                                                       Resource formResource)
        Parameters:
        keyValueString -
        i18n -
        Returns:
      • isRichTextField

        public static boolean isRichTextField​(JSONObject jsonObject)
                                       throws JSONException
        This API is for checking whether the text box field allows filling rich text or not
        Parameters:
        jsonObject -
        Returns:
        boolean value indicating whether the field allow rich text or not
        Throws:
        JSONException
      • encodeForHtml

        public static java.lang.String encodeForHtml​(java.lang.String str,
                                                     XSSAPI xssapi)
        Encodes the given string as HTML content
        Parameters:
        str - string to encode as HTML content
        xssapi - XSSAPI instance
        Returns:
        encoded HTML content
      • encodeForHtmlAttr

        public static java.lang.String encodeForHtmlAttr​(java.lang.String str,
                                                         XSSAPI xssapi)
        Encodes the given string as HTML attribute
        Parameters:
        str - string to encode as HTML attribute
        xssapi - XSSAPI instance
        Returns:
        encoded HTML attribute
      • encodeForJSString

        public static java.lang.String encodeForJSString​(java.lang.String str,
                                                         XSSAPI xssapi)
        Encodes the given string as java script content
        Parameters:
        str - string to encode as java script content
        xssapi - XSSAPI instance
        Returns:
        encoded JS string
      • filterHtml

        public static java.lang.String filterHtml​(java.lang.String str,
                                                  XSSAPI xssapi)
      • getValidCSSColor

        public static java.lang.String getValidCSSColor​(java.lang.String str,
                                                        XSSAPI xssapi)
      • encodeForCSSString

        public static java.lang.String encodeForCSSString​(java.lang.String str,
                                                          XSSAPI xssapi)
      • sanitizeCSSString

        public static java.lang.String sanitizeCSSString​(java.lang.String str,
                                                         XSSAPI xssapi)
      • getDefaultLocale

        public static java.lang.String getDefaultLocale​(Resource resource)
      • getThemeClientLibName

        public static java.lang.String getThemeClientLibName​(Resource resource)
      • getLocaleParamFromRequest

        public static java.lang.String getLocaleParamFromRequest​(SlingHttpServletRequest request)
        Generic Utility for getting the language parameter from request object
        Parameters:
        request -
        Returns:
        locale from request object
      • getLocale

        public static java.lang.String getLocale​(SlingHttpServletRequest request,
                                                 Resource guideContainerResource)
        Parameters:
        request -
        guideContainerResource -
        Returns:
        the first locale in the accept Lang header, which has a correspoiding guide-i18n clientlib
      • getI18n

        public static I18n getI18n​(SlingHttpServletRequest request,
                                   Resource guideFieldResource)
        Parameters:
        request -
        guideFieldResource -
        Returns:
        the i18n object for the guide level dictionary
      • getAssetPathFromPage

        public static java.lang.String getAssetPathFromPage​(java.lang.String pagePath)
        /** This function returns Asset path from Page path for Adaptive Pages ie : Guide, AF Fragment, Adaptive Document
        Parameters:
        pagePath - path of the asset
      • getDamJcrValueMap

        public static ValueMap getDamJcrValueMap​(ResourceResolver resourceResolver,
                                                 SlingHttpServletRequest request,
                                                 Resource contentResource)
        This function returns Asset path from Page path for Adaptive Pages ie : Guide, AF Fragment, Adaptive Document
        Parameters:
        resourceResolver -
        request -
        contentResource -
      • isEditableTemplateResource

        public static java.lang.Boolean isEditableTemplateResource​(Resource resource)
        Parameters:
        resource -
        desiredLocale - Checks if given resource lies within any editable template or not This API is using the logic of TemplateUtils.isAuthoredTemplate() in CQ/wcm to check for editable template node.
        resource -
        Returns:
      • getPageResource

        public static Resource getPageResource​(Resource resource)
        Returns the cq:Page resource by walking up in the resource hierarchy
      • getI18n

        public static I18n getI18n​(ResourceBundleProvider resourceBundleProvider,
                                   Resource containerResource,
                                   java.util.Locale locale)
        Parameters:
        resourceBundleProvider -
        containerResource -
        locale -
        Returns:
        the i18n object for the guide level dictionary
      • getDataMimeType

        public static java.lang.String getDataMimeType​(Resource formResource)
        Gives the mime type of data which as per the data model configured with the form
        Parameters:
        formResource - resource of adaptive form container
        Returns:
        string representing the mime type
      • getSchemaType

        public static java.lang.String getSchemaType​(JSONObject formContainerJson)
        Deprecated.
        Gives the schema type of data which is configured with the form
        Parameters:
        formContainerJson - json of adaptive form container
        Returns:
        String representing schemaType of form it could have any of the following value - none, formtemplates, xmlschema, jsonschema, formdatamodel
      • getAfDataSom

        public static java.lang.String getAfDataSom​(java.lang.String schemaType,
                                                    java.lang.String name,
                                                    java.lang.String bindRef)
        Gives the afDataSom for an adaptive form field
        Parameters:
        schemaType - of adaptive form
        name - of adaptive form field
        bindRef - of adaptive form field
        Returns:
        afDataSom of adaptive form field
      • somToAdapativeFormItem

        public static JSONObject somToAdapativeFormItem​(JSONObject formContainerJson,
                                                        java.lang.String somExpression)
        Gives JSONObject of Adaptive Form field/panel corresponding to given SOM Expression
        Parameters:
        formContainerJson - adaptive form container JSON
        somExpression - som expression of adaptive form panel/field
        Returns:
        JSONObject of Adaptive Form field/panel corresponding to given SOM Expression
      • paramToString

        public static java.lang.String paramToString​(RequestParameter param)
        Utility to convert a RequestParameter to String
        Parameters:
        param - RequestParameter
      • guideRefToGuidePath

        public static java.lang.String guideRefToGuidePath​(java.lang.String guideRefPath)
        Utility to convert an AF(Adaptive Form) meta data path to the actual adaptive forms path
        Parameters:
        guideRefPath - path of the adaptive forms metadata node
        Returns:
        the path of the adaptive form
      • guideRefToDocPath

        public static java.lang.String guideRefToDocPath​(java.lang.String guideRefPath)
        Utility to convert an MC DOCUMENT meta data path to the actual mc document path
        Parameters:
        guideRefPath - path of the mc document metadata node
        Returns:
        the path of the mc document path
      • manipulateBindRefForFragments

        public static java.lang.String manipulateBindRefForFragments​(java.lang.String bindRefPrefixForFragment,
                                                                     java.lang.String bindRef,
                                                                     java.lang.String fragmentRoot)
        This API is for internal purpose. This will manipulate the bindRef of the element if there is a bindRef prefix present. This means that the binded node is a fragment in adaptive forms so we will need to prefix the schema hierarchy of XFA/XSD if the bindRef passed was xfa[0].form[0].form1[0].Subform1[0].Subform2[0].n[0].NumericField1[0] and fragment Root is n[0] then the new bindref may be like prefix + Fragment root + rest of bindRef after fragment root xfa[0].form[0].form1[0].AnotherSubFormWhereFragReferenced[0].n[0].NumericField1[0]
        Parameters:
        bindRefPrefixForFragment - this the prefix after which the fragment root would be appended
        bindRef - Reference to the
        fragmentRoot - Root of fragment
        Returns:
        the manipulated bindref incorporating the fragment related changes
      • getNamespacedKeys

        public static java.lang.String getNamespacedKeys​(java.lang.String value,
                                                         java.lang.String key,
                                                         Resource formResource)
        Parameters:
        key -
      • getNamespacedKeys

        public static java.lang.String getNamespacedKeys​(java.lang.String value,
                                                         java.lang.String key,
                                                         ValueMap properties)
        Parameters:
        key -
      • translateOrReturnOriginal

        public static java.lang.String translateOrReturnOriginal​(java.lang.String value,
                                                                 java.lang.String key,
                                                                 I18n i18n,
                                                                 @Nullable
                                                                 ValueMap properties)
        Parameters:
        i18n - * @pad.exclude Exclude from Published API.
      • translateOrReturnOriginal

        public static java.lang.String translateOrReturnOriginal​(java.lang.String original,
                                                                 java.lang.String key,
                                                                 I18n i18n,
                                                                 @Nullable
                                                                 Resource formResource)
        Parameters:
        original -
        i18n -
      • escapeXml

        public static java.lang.String escapeXml​(java.lang.String unescaped)
        Parameters:
        unescaped -
      • isGuideFileUploadModel

        public static boolean isGuideFileUploadModel​(java.lang.String guideNodeClass)
        Parameters:
        guideNodeClass -
      • isGuideButtonModel

        public static boolean isGuideButtonModel​(java.lang.String guideNodeClass)
        Parameters:
        guideNodeClass -
      • isGuideFieldModel

        public static boolean isGuideFieldModel​(java.lang.String guideNodeClass)
        Checks if given node class belongs to guide field
        Parameters:
        guideNodeClass -
      • isGuidePanelModel

        public static boolean isGuidePanelModel​(java.lang.String guideNodeClass)
        Checks if given node class belongs to guide panel
        Parameters:
        guideNodeClass -
      • isGuideCompositeField

        public static boolean isGuideCompositeField​(java.lang.String guideNodeClass)
        Parameters:
        guideNodeClass -
        Returns:
      • isGuideTnCModel

        public static boolean isGuideTnCModel​(java.lang.String guideNodeClass)
        Parameters:
        guideNodeClass -
        Returns:
      • getGuideContainer

        public static JSONObject getGuideContainer​(JSONObject guideJson)
                                            throws GuideException
        This API is for internal purpose only. Returns guideContainer node. Input form node or guideContainer node.
        Parameters:
        guideJson -
        Returns:
        guideContainer JSON object
        Throws:
        GuideException
      • getGuideContainer

        public static ValueMap getGuideContainer​(SlingHttpServletRequest request,
                                                 Resource elementResource)
        This API is for internal purpose. Resource here is an ancestor of guideContainer. It returns the value map of inline guideContainer present in the current page and not the reference guide container.
        Parameters:
        request -
        elementResource - elementResource here should be an ancestor if guideContainer, if it a descendent use the generic api getGuideContainerPath present inside GuideELUtils
        Throws:
        javax.jcr.RepositoryException
      • isValidGuide

        public static java.lang.Boolean isValidGuide​(SlingHttpServletRequest request,
                                                     Resource resource)
                                              throws javax.jcr.RepositoryException
        Parameters:
        request -
        resource -
        Returns:
        Throws:
        javax.jcr.RepositoryException
      • getAFLocale

        public static java.util.Locale getAFLocale​(java.lang.String locale,
                                                   GuideLocalizationService guideLocalizationService)
      • getAFPathFromFormContainerResource

        public static java.lang.String getAFPathFromFormContainerResource​(Resource formContainerResource)
      • getNormalizedNodeType

        public static java.lang.String getNormalizedNodeType​(java.lang.String resourceType,
                                                             java.lang.String resourceSuperType)
        Parameters:
        resourceType -
        resourceSuperType -
      • walkThroughContent

        public static void walkThroughContent​(java.util.List<java.lang.String> list,
                                              Resource elementResource,
                                              java.lang.String resourceToBeFound)
        Parameters:
        list -
        elementResource -
        resourceToBeFound -
      • isLayoutablePanel

        public static boolean isLayoutablePanel​(GuideNode node)
        Parameters:
        node -
      • convertFMAssetPathToContainerPath

        public static java.lang.String convertFMAssetPathToContainerPath​(java.lang.String fragRef)
        This API converts DAM asset path to adaptive forms page's container path e.g. if the path was /content/dam/formsanddocument/bla/jcr:content the return vaule will be /content/forms/af/bla/jcr:content/guideContainer
        Parameters:
        fragRef - DAM asset path of Fragment
        Returns:
        adaptive forms container path of fragment
      • convertGuideContainerPathToFMAssetPath

        public static java.lang.String convertGuideContainerPathToFMAssetPath​(java.lang.String guideContainerPath)
        Get Form Asset path from the given form container path
        Parameters:
        guideContainerPath - path to the form container
        Returns:
        corresponding path of Form Manager Form Asset
      • convertGuideContainerPathToFMAssetMetadataPath

        public static java.lang.String convertGuideContainerPathToFMAssetMetadataPath​(java.lang.String guideContainerPath)
        Get Form Asset Meatadata path in form manager for given form container path
        Parameters:
        guideContainerPath - path to the adaptive form container
        Returns:
        corresponding path of Form Manager Form Asset Metadata node
      • getDoRTemplateRef

        public static java.lang.String getDoRTemplateRef​(java.lang.String guideContainerPath,
                                                         java.lang.String runtimeLocale,
                                                         ResourceResolver resourceResolver)
        Returns path of XDP used for DoR Template (auto generated or associated) dorType = none, dorTemplateRef = dorType = generate, dorTemplateRef = /renditions/dorTemplate/runtimeLocale dorType = select, dorTemplateRef
        Parameters:
        guideContainerPath -
        runtimeLocale - locale
        resourceResolver -
        Returns:
        path of XDP used for DoR Template
      • getResolverFromResourceResolverHelper

        public static ResourceResolver getResolverFromResourceResolverHelper​(ResourceResolverHelper resourceResolverHelper)
        Parameters:
        resourceResolverHelper -
      • getResolverFromResource

        public static ResourceResolver getResolverFromResource​(GuideContainer guideContainer)
        Returns resource resolver from GuideContainer
        Parameters:
        guideContainer -
      • getStringSubstitutor

        public static StrSubstitutor getStringSubstitutor​(JSONObject valueMap)
        Parameters:
        valueMap -
      • isPanel

        public static java.lang.Boolean isPanel​(Resource resource)
        Returns wether given resource is of type panel or not.
        Parameters:
        resource -
        Returns:
        Boolean true if given resource is of type panel
      • hasModifyPermission

        public static java.lang.Boolean hasModifyPermission​(Resource resource)
        Checks if session has property modification permission on resource.
        Parameters:
        resource -
        Returns:
      • embedFragmentResources

        public static java.lang.Boolean embedFragmentResources​(Resource fragmentPanelResource,
                                                               java.lang.String fragmentPath,
                                                               java.lang.Boolean processConversion)
      • convertToNewResponsiveLayout

        public static java.lang.Boolean convertToNewResponsiveLayout​(Resource guideContainerResource)
        Converts Form / IC web channel / Fragment having old responsive layout to new responsive layout.
        Parameters:
        guideContainerResource -
        Returns:
        Boolean.TRUE if conversion succeeds otherwise returns Boolean.FALSE
      • convertPanelToNewResponsiveLayout

        public static void convertPanelToNewResponsiveLayout​(Resource panelResource)
        Converts Panel and its decedents having old responsive layout to new responsive layout.
        Parameters:
        panelResource -
      • isOldResponsiveLayout

        public static java.lang.Boolean isOldResponsiveLayout​(Resource panelResource)
        Parameters:
        panelResource -
        Returns:
        Boolean.TRUE on first occurrence of old responsive layout Boolean.FALSE on first occurrence of new responsive layout otherwise null
      • hasOldResponsiveLayout

        public static java.lang.Boolean hasOldResponsiveLayout​(Resource panelResource)
        Returns weather the panel resource or any of its hierarchy has old responsive layout in it.
        Parameters:
        panelResource -
        Returns:
        Boolean true if panel resource or any of its hierarchy has old responsive layout in it
      • getRootPanel

        public static Resource getRootPanel​(Resource resource)
        Parameters:
        resource -
      • removePrefix

        public static java.lang.String removePrefix​(java.lang.String str,
                                                    java.lang.String prefix)
        Parameters:
        str -
        prefix -
      • getLastModifiedTimeFromStaleAssetIndicatorService

        public static java.util.Calendar getLastModifiedTimeFromStaleAssetIndicatorService​(GuideContainer guideContainer,
                                                                                           StaleAssetIndicatorService staleAssetIndicatorService)
        This method calls staleAssetIndicatorService and gets LMT of the form and related assets - Used to validate Caches - both JSON & HTML
        Parameters:
        guideContainer -
        staleAssetIndicatorService -
        Returns:
        lastmodified time from StaleAssetIndicatorService or from jcr:content (parent of guideContainer)
      • isJsonBasedSchema

        public static boolean isJsonBasedSchema​(java.lang.String schemaType)
        Returns if it's a json based schema type.
        Parameters:
        schemaType -
        Returns:
        if it's a json based schema type.
      • isXDPValid

        public static boolean isXDPValid​(Resource guideContainer)
        Checks if the give adaptive forms(using guidecontainer resource) has a valid XDP Reference to it
        Parameters:
        guideContainer - resource of the adaptive form container
        Returns:
        false if the resource is null or xdpRef property is null/empty string, true otherwise
      • isMetaTemplateValid

        public static boolean isMetaTemplateValid​(ResourceResolver resourceResolver,
                                                  java.lang.String metaTemplateRef)
        Checks if path pointed by metaTemplateRef is valid resource.
        Parameters:
        resourceResolver - ResourceResolver to resolve path
        Returns:
        false if the resource is null or metaTemplateRef property is null/empty string, true otherwise
      • getMetaTemplateRef

        public static java.lang.String getMetaTemplateRef​(Resource guideContainerResource)
        Get meta-template path associated with guide container.
        Parameters:
        guideContainerResource - guide container resource object
        Returns:
        returns path to meta-template if exists otherwise empty string
      • getPrintNodeResource

        public static Resource getPrintNodeResource​(Resource guideContainer)
      • isCoreComponentBasedForm

        public static boolean isCoreComponentBasedForm​(Resource guideContainer)
        Checks if form/asset is Core Component based taking input as guidecontainer
        Parameters:
        guideContainer -
        Returns:
        whether the form container resource provided is v2 or not
      • isCoreComponentBasedForm

        public static boolean isCoreComponentBasedForm​(ValueMap propertiesMap)
        Checks if form/asset is Core Component based taking input as Properties Map
        Parameters:
        propertiesMap -
        Returns:
        whether the metadata properties provided is of v2 asset or not
      • isGuideContainerResource

        public static boolean isGuideContainerResource​(Resource resource)
        This is a public api used to identify if a resource is a Guide Container or Wrapper resource Returns true if resource is a GuideContainer or Wrapper else returns false
        Parameters:
        resource -
      • translateOrReturnOriginal

        public static java.lang.String translateOrReturnOriginal​(java.lang.String original,
                                                                 I18n i18n)
        Parameters:
        original -
        i18n -
        Returns:
        * @pad.exclude Exclude from Published API.
      • isCacheableContainerResource

        public static boolean isCacheableContainerResource​(Resource resource)
        This API checks weather the resource's HTML should ever be cached
        Parameters:
        resource - container resource
        Returns:
        boolean stating if resource can be cached
      • isV2GuideContainerResource

        public static boolean isV2GuideContainerResource​(Resource resource)
        This is a public api used to identify if a resource is a v2 Guide Container or Wrapper resource Returns true if resource is a v2 GuideContainer or Wrapper else returns false
        Parameters:
        resource -
      • isTargetEnabled

        public static boolean isTargetEnabled​(Resource guideContainerResource)
        API to identify if targeting is enabled for the Adaptive form requested by the specified guide container
        Parameters:
        guideContainerResource - resource to the adaptive form container
        Returns:
        true if targeting enabled false otherwise
      • isAdobeTargetConfigured

        public static boolean isAdobeTargetConfigured​(Resource resource)
        API to identify if adobe target is configured for the Adaptive form.
        Parameters:
        resource - resource to the adaptive form container
        Returns:
        true if adobe target is configured otherwise false
      • getAlternateContainerPathFromCurrentContainer

        public static java.lang.String getAlternateContainerPathFromCurrentContainer​(RequestPathInfo requestPathInfo)
        The api returns the alternate (Target B scenario for ABTesting) Returns path to the alternate Guide Container
        Parameters:
        requestPathInfo - RequestPathInfo object from the request
        Returns:
        alternateContainerPath
      • validateFormAuthoredState

        public static java.util.List<GuideUtils.AuthoringError> validateFormAuthoredState​(GuideContainer guideContainer,
                                                                                          java.lang.String afInitializationState,
                                                                                          I18n localI18n)
        validates Adaptive Form (having Signature Step) authored state
        Parameters:
        guideContainer - ,
        Returns:
        list of errors if any
      • isDorTemplateRefValid

        public static boolean isDorTemplateRefValid​(Resource guideContainer)
        returns whether the dorTemplateRef present in the resource is valid or not todo: Have to check if the schema of XSD and dorTemplateRef match?
        Parameters:
        guideContainer - ,
        Returns:
        false if the resource is null, dorTemplateRef property is null or empty string, true otherwise
      • getXFALocale

        public static java.lang.String getXFALocale​(java.lang.String locale)
        Returns the xfa compliant locale. If a XFA compliant version is not found then it returns the locale as is Eg. For en it returns en_US.
        Parameters:
        locale - AEM supported locale
        Returns:
        Returns the corresponding XFA compliant locale *
      • getGuideRuntimeLocale

        public static java.lang.String getGuideRuntimeLocale​(SlingHttpServletRequest slingRequest,
                                                             Resource resource)
        Returns the runtime locale in format like en-us
        Parameters:
        resource - resource to the adaptive form container
        slingRequest - client request object
        Returns:
        Returns the runtime locale if localeLib is present otherwise falls back to authoring locale or "en" as last resort
      • getCurrentLMT

        public static java.util.Calendar getCurrentLMT​(Resource containerResource,
                                                       StaleAssetIndicatorService staleAssetIndicatorService)
        Parameters:
        containerResource -
        staleAssetIndicatorService -
        Returns:
        Calendar LMT of the child asset or LONG_MAX value if service missing This method will call form managers' API to check that all related child asset's TS and return eldest modified time
      • getAcceptLang

        public static java.lang.String getAcceptLang​(SlingHttpServletRequest request)
        Parameters:
        request -
        Returns:
        string consisting of appropriate locale code This method will iterate through list of language in "accept-language" request header and provide with the appropriate locale code after finding the clientlibs available for localization Guide Container Locale is the fallback.
      • visitToCollectProperties

        public static void visitToCollectProperties​(JSONObject guideTypeJsonObject,
                                                    java.lang.String toCheck,
                                                    java.lang.String keyToPut,
                                                    java.lang.String valueToPut,
                                                    JSONArray collection)
        Parameters:
        guideTypeJsonObject -
        toCheck -
        keyToPut -
        valueToPut -
        collection -
      • getResourceBundle

        public static java.util.ResourceBundle getResourceBundle​(SlingHttpServletRequest request,
                                                                 Resource guideContainerResource,
                                                                 java.util.Locale desiredLocale)
        Utility API to fetch resource bundle for given form and request
        Parameters:
        request - reference to SlingHttpServletRequest
        guideContainerResource - resource of form container
        desiredLocale - reference to desired Locale
        Returns:
        reference to the ResourceBundle
      • isDesiredLocaleDictPresent

        public static java.lang.Boolean isDesiredLocaleDictPresent​(Resource baseResource,
                                                                   java.util.Locale desiredLocale)
      • getI18nForDesiredLocale

        public static I18n getI18nForDesiredLocale​(SlingHttpServletRequest request,
                                                   Resource guideContainerResource,
                                                   java.util.Locale desiredLocale)
        returns the i18 object for the desired locale
        Returns:
        returns the i18 object for the desired locale
      • getLocaleIndexFromLocale

        public static int getLocaleIndexFromLocale​(java.lang.String locale,
                                                   java.lang.String[] AEM_SUPPORTED_LOCALES)
        returns the index of the locale from the GuideConstants.AEM_SUPPORTED_LOCALES if locale is not suppoted then index of "en" is returned
        Parameters:
        locale -
        Returns:
        returns the index of the locale from the GuideConstants.AEM_SUPPORTED_LOCALES
      • sanitizeLocaleList

        public static java.lang.String[] sanitizeLocaleList​(java.lang.String[] locales)
        This is to sanitize the localisation service locales They are in pt-br format, we will try to sanitize them to ptBR format
        Parameters:
        locales -
        Returns:
        returns a new list of sanitized locales
      • getInheritedProperty

        public static java.lang.String getInheritedProperty​(Resource resource,
                                                            java.lang.String propertyName)
        Returns the inherited property value of the property from the page containing the resource mentioned.
        Parameters:
        resource - resource
        propertyName - name of the property
        Returns:
        string representing the inherited property value
      • getUserSessionFromRequest

        public static javax.jcr.Session getUserSessionFromRequest​(SlingHttpServletRequest slingHttpServletRequest)
        To get user session from sling request
      • getLanguageDirection

        public static java.lang.String getLanguageDirection​(java.lang.String language)
        API to give direction of content for given language This method will iterate through list of languages in "accept-language" request header and provide with the appropriate direction of locale code
        Parameters:
        language -
        Returns:
        string consisting direction of appropriate locale code
      • isLangRTL

        public static boolean isLangRTL​(java.lang.String language)
      • processInternalPostOnRestEndPoint

        public static SlingHttpServletResponse processInternalPostOnRestEndPoint​(SlingHttpServletRequest request,
                                                                                 SlingHttpServletResponse response,
                                                                                 java.lang.String postUrl)
        Forwards the given request using HTTP Post to the given post url
        Parameters:
        request - sling request
        response - sling response
        postUrl - URL to forward the current request
        Returns:
        sling http servlet response
      • addToRequestMap

        public static void addToRequestMap​(ParameterMap requestParameterMap,
                                           java.lang.String key,
                                           RequestParameter[] requestParameter)
        Deprecated.
        Parameters:
        requestParameterMap -
        key -
        requestParameter -
      • getFileAttachmentList

        public static java.util.List getFileAttachmentList​(SlingHttpServletRequest request,
                                                           java.lang.String guideContainerPath)
        Parameters:
        request -
        guideContainerPath -
        Returns:
      • getFileAttachmentList

        public static java.util.List<JSONObject> getFileAttachmentList​(@Nonnull
                                                                       java.lang.String guideJsonString)
        Returns:
      • prepareWrappedRequestWithDataXMLAndAttachments

        public static ParameterMap prepareWrappedRequestWithDataXMLAndAttachments​(SlingHttpServletRequest request)
        Parameters:
        request -
      • getFieldLayout

        public static java.lang.String getFieldLayout​(Resource guideContainerResource,
                                                      java.lang.String propertyName,
                                                      java.lang.String defaultValue)
        Returns the field layout related configuration of the field. If one wishes to write own custom layout, the framework is similar to how we write custom panel layout
      • setEmbedFragButton

        public static boolean setEmbedFragButton​(java.lang.String title,
                                                 EditContext editContext,
                                                 SlingHttpServletRequest request,
                                                 java.lang.String fragRef,
                                                 java.lang.String currentPanelPath,
                                                 java.lang.String bindRef)
        Sets the embed fragment button in the edit bar for the panel based on the title, handler and index.
        Parameters:
        title -
        editContext -
        request -
        fragRef -
        currentPanelPath -
        bindRef -
      • setButtonForPanel

        public static boolean setButtonForPanel​(java.lang.String title,
                                                EditContext editContext,
                                                SlingHttpServletRequest request,
                                                java.lang.String currentPanelPath,
                                                java.lang.String bindRef,
                                                java.lang.String handler)
        Sets the button in the edit bar for the panel based on the title and handler.
        Parameters:
        title -
        editContext -
        request -
        currentPanelPath -
        bindRef -
        handler -
        Returns:
      • setButtonForPanel

        public static boolean setButtonForPanel​(java.lang.String title,
                                                EditContext editContext,
                                                SlingHttpServletRequest request,
                                                java.lang.String currentPanelPath,
                                                java.lang.String bindRef,
                                                java.lang.String handler,
                                                java.lang.Integer index)
        Sets the button in the edit bar for the panel based on the title, handler and index.
        Parameters:
        title -
        editContext -
        request -
        currentPanelPath -
        bindRef -
        handler -
        index -
      • putQueryParamsToRedirectRequest

        public static void putQueryParamsToRedirectRequest​(java.lang.String responseString,
                                                           java.util.Map<java.lang.String,​java.lang.String> redirectParameters)
        Parameters:
        responseString -
        redirectParameters -
      • parseSize

        public static double parseSize​(java.lang.String size)
        Parameters:
        size -
      • trimLazyChildren

        public static JSONObject trimLazyChildren​(java.lang.String guideJsonString)
        Parameters:
        guideJsonString - AF Json
      • findJsonObjectWithProperty

        public static java.lang.String findJsonObjectWithProperty​(JSONObject jsonObject,
                                                                  java.lang.String propertyName,
                                                                  java.lang.String propertyValue,
                                                                  java.lang.String path,
                                                                  boolean ignorePath)
        Finds a fragment/form with the specified property and having the given path (required for getting in context(manipulated bindrefs/ HTML IDs) fragment/form )
        Parameters:
        jsonObject -
        propertyName -
        propertyValue -
        path -
        ignorePath - if true then the resource should have same jcr:path path is ignored
        Returns:
        string having JSON of the fragment/ form
      • findJsonObjectWithProperty

        public static java.lang.String findJsonObjectWithProperty​(JSONObject jsonObject,
                                                                  java.lang.String propertyName,
                                                                  java.lang.String propertyValue,
                                                                  java.lang.String path)
        Finds a fragment/form with the specified property and having the given path (required for getting in context(manipulated bindrefs/ HTML IDs) fragment/form )
        Parameters:
        jsonObject -
        propertyName -
        propertyValue -
        path -
        Returns:
        string having JSON of the fragment/ form
      • getAssetHTMLFromFullHTML

        public static java.lang.String getAssetHTMLFromFullHTML​(java.lang.String templateId,
                                                                java.lang.String html)
        Parameters:
        templateId -
        html -
        Returns:
        HTML String of the templateId provided
      • formJsonHtmlString

        public static java.lang.String formJsonHtmlString​(java.lang.String json,
                                                          java.lang.String html,
                                                          java.lang.String multipleJson)
        Parameters:
        json -
        html -
        Returns:
        String form of JSON object having asset JSON & asset HTML
      • getLayoutScriptFromContainer

        public static java.lang.String getLayoutScriptFromContainer​(GuideContainer guideContainer)
        Parameters:
        guideContainer -
        Returns:
        fetchs layout script from GuideContainer
      • produceHTML

        public static java.lang.String produceHTML​(GuideContainer guideContainer,
                                                   SlingHttpServletResponse slingHttpServletResponse)
        Parameters:
        guideContainer -
        slingHttpServletResponse -
        Returns:
        HTML of Adaptive Form (stringfied)
      • getJsonForGivenTemplateId

        public static java.lang.String getJsonForGivenTemplateId​(JSONObject guideJsonObject,
                                                                 java.lang.String templateId)
        Parameters:
        guideJsonObject -
        templateId -
      • getScriptAsStringFromClientLib

        public static java.lang.String getScriptAsStringFromClientLib​(HtmlLibraryManager htmlLibraryManager,
                                                                      java.lang.String clientLibPath,
                                                                      boolean minify)
        Gets the JavaScript as String from the client lib path specified.
        Parameters:
        htmlLibraryManager - HtmlLibraryManager service.
        clientLibPath - String specifying the path of client lib.
        Returns:
        String representing the java script code of the client lib(not css).
      • getScriptFromClientLibList

        public static java.util.ArrayList<java.lang.String> getScriptFromClientLibList​(HtmlLibraryManager htmlLibraryManager,
                                                                                       java.lang.String[] clientLibCategories,
                                                                                       boolean minify)
        Gets the JavaScript as a string array from clientlib categories.
        Parameters:
        htmlLibraryManager - HtmlLibraryManager service.
        clientLibCategories - Array of all clientlib categories fow which script is required.
        Returns:
        List of Strings for every clientlib specified.
      • getDictionaryInfoFromAssetPaths

        public static JSONObject getDictionaryInfoFromAssetPaths​(JSONArray assetList,
                                                                 java.util.List<java.lang.String> locales,
                                                                 ResourceResolver resourceResolver)
        Need an object like { "languages":[ {"lang":"ja","dicts":["/libs/wcm/core/i18n/ja.json","path":"/libs/wcm/core/i18n/ja2.json"]}, {"lang":"fr","dicts":["/libs/wcm/core/i18n/fr.json","/libs/wcm/core/i18n/fr2.json"]}, {"lang":"de","dicts":[“/libs/wcm/core/i18n/de.json","path":"/libs/wcm/core/i18n/de2.json"]} ] }
        Parameters:
        assetList -
        locales -
      • getDefaultPattern

        public static java.lang.String getDefaultPattern​(java.lang.String componentType)
        Parameters:
        componentType -
        Returns:
      • listContains

        public static java.lang.Boolean listContains​(java.util.List<java.lang.String> list,
                                                     java.lang.String searchString,
                                                     java.lang.Boolean ignoreCase)
        Checks case-insensitively if a string is present in a list of strings
        Parameters:
        list -
        searchString -
        ignoreCase -
      • checkIfForms

        public static boolean checkIfForms​(Resource resource)
        This API check if the given resource is a form by looking for resource type property of jcr:content/guideContainer
        Parameters:
        resource - resource pointing to the page
        Returns:
        boolean Indicating if the given page is a form or not
      • checkIfForms

        public static boolean checkIfForms​(Resource resource,
                                           boolean isV2)
        This API checks if the given resource is a form by looking for resource type property of jcr:content/guideContainer
        Parameters:
        resource - resource pointing to the page
        isV2 - assumes value as true for form created using v2 core components
        Returns:
        boolean Indicating if the given page is a form or not
      • getMergedFormResource

        public static Resource getMergedFormResource​(ResourceResolver resolver,
                                                     java.lang.String formPath)
      • checkIfFormsTemplate

        public static boolean checkIfFormsTemplate​(Resource resource)
        This API check if the given resource(template) is a forms template by looking for guideComponentType property in jcr:content node of template
        Parameters:
        resource -
        Returns:
        true if the resource is an AEM Forms template, false otherwise
      • checkIfFormsTemplate

        public static boolean checkIfFormsTemplate​(Resource resource,
                                                   boolean checkIfV2)
      • isRepeatable

        public static boolean isRepeatable​(JSONObject obj)
      • isCompositeField

        public static boolean isCompositeField​(JSONObject obj)
      • isSubmitableField

        public static boolean isSubmitableField​(JSONObject obj)
      • isStaticTextType

        public static boolean isStaticTextType​(java.lang.String type)
        Returns true if type equals guideTextDraw or guideAdobeSignBlock
      • hasFloatingField

        public static boolean hasFloatingField​(JSONObject obj)
        Returns true if type equals guideTextDraw or guideAdobeSignBlock and have document fragment variables inside it
      • isDeprecatedAD

        public static java.lang.Boolean isDeprecatedAD​(Resource containerResource)
        Checks if the given container resource is a deprecated AD or not
      • getFormResource

        public static Resource getFormResource​(Resource otherResource,
                                               java.lang.String fragRef)
      • getFormBreakpointResource

        public static Resource getFormBreakpointResource​(ResourceResolver resolver,
                                                         java.lang.String formPath)
      • getGuideContainerPathFromResource

        public static java.lang.String getGuideContainerPathFromResource​(SlingHttpServletRequest request,
                                                                         Resource resource)
        This function returns the Guide Container path from any resource in the adaptive form. Eg - if the resource is a header/footer that is outside the guideContainer, then it traverses up to the cq:page and then searches down from cq:page for guideContainer
      • isUnboundObj

        public static boolean isUnboundObj​(JSONObject obj)
        Parameters:
        obj - : guide json obj
        Returns:
      • getThemeContentRef

        public static java.lang.String getThemeContentRef​(Resource guideContainerResource)
        Returns the theme content path from Guide container resource
        Parameters:
        guideContainerResource - resource to the form container
        Returns:
        Path to theme content resource of theme associated with guide container.
      • getGuideName

        public static java.lang.String getGuideName​(Resource rsrc)
                                             throws GuideException
        Return the parameter name for the field
        Parameters:
        rsrc - The resource
        Returns:
        The parameter name.
        Throws:
        GuideException
      • getResource

        public static Resource getResource​(ResourceResolver resourceResolver,
                                           java.lang.String path,
                                           JSONObject json)
        Transform JSON into Resource.
        Parameters:
        resourceResolver - ResourceResolver to be set for resource being returned
        path - path on which resource has to be mounted
        json - input JSON which is to be transformed into resource
        Returns:
        Resource
      • getResource

        public static Resource getResource​(ResourceResolver resourceResolver,
                                           java.lang.String path,
                                           JSONObject json,
                                           Resource parentResource)
        Transform JSON into Resource.
        Parameters:
        resourceResolver - ResourceResolver to be set for resource being returned
        path - path on which resource has to be mounted
        json - input JSON which is to be transformed into resource
        parentResource - parent resource of synthetic resource that is being generated.
        Returns:
        Resource
      • getResource

        public static Resource getResource​(ResourceResolver resourceResolver,
                                           java.lang.String path,
                                           JSONObject json,
                                           Resource parentResource,
                                           boolean useNameAsResourceIdentifier)
        Transform JSON into Resource.
        Parameters:
        resourceResolver - ResourceResolver to be set for resource being returned
        path - path on which resource has to be mounted
        json - input JSON which is to be transformed into resource
        parentResource - parent resource of synthetic resource that is being generated.
        useNameAsResourceIdentifier - use name of resource as the key during resoruce creation from json
        Returns:
        Resource
      • getResourceIterator

        public static java.util.Iterator<Resource> getResourceIterator​(ResourceResolver resourceResolver,
                                                                       java.lang.String path,
                                                                       java.util.Iterator<JSONObject> jsonObjectIterator)
        Transform JSON Iterator into Resource Iterator.
        Parameters:
        resourceResolver - ResourceResolver to be set for resource being returned
        path - path on which resource has to be mounted
        jsonObjectIterator - input JSON Iterator which is to be transformed into resource iterator
        Returns:
        Iterator
      • fillQueue

        public static void fillQueue​(java.util.Queue<Resource> queue,
                                     Resource resource,
                                     java.lang.String type)
        Fill queue with resources (outside guide container) which can be mapped to static text and image in document of record
        Parameters:
        queue - queue to be filled
        resource - parent of guide container
        type - either StaticText or Image
      • getAdaptiveFormBrandingComponents

        public static Resource getAdaptiveFormBrandingComponents​(ResourceResolver resourceResolver,
                                                                 java.lang.String guideContainerPath,
                                                                 java.lang.String templateRef,
                                                                 java.lang.String type,
                                                                 java.lang.String value,
                                                                 I18n i18n)
        Get components outside guide container which could be mapped to branding components in document of record. Only static text and image components can be mapped.
        Parameters:
        resourceResolver -
        guideContainerPath -
        type - either StaticText or Image
        value - component which should be selected
        Returns:
        {Resource} Applicable components as children of items resource
      • getThemeResource

        public static Resource getThemeResource​(Resource formResource)
        Gets the theme resource for a given Adaptive Form
        Parameters:
        formResource - Form resource.
        Returns:
        Theme Resource for the Form Resource
      • isScriptAuthoringAllowed

        public static boolean isScriptAuthoringAllowed​(java.security.Principal userPrincipal,
                                                       UserManager um)
                                                throws javax.jcr.RepositoryException
        Given user principal returns true if principal is allowed to write scripts
        Parameters:
        userPrincipal - Principal user principal
        um - reference to UserManager service
        Returns:
        true if script authoring is allowed
        Throws:
        javax.jcr.RepositoryException
      • showRuleEditor

        public static boolean showRuleEditor​(java.security.Principal userPrincipal,
                                             UserManager um,
                                             java.lang.String[] customGroups)
                                      throws javax.jcr.RepositoryException
        Given user principal and list of groups returns true if principal is to be shown rule editor
        Parameters:
        userPrincipal - Principal user principal
        um - reference to UserManager
        customGroups - list of group names to show rule editor
        Returns:
        true if script authoring is allowed
        Throws:
        javax.jcr.RepositoryException
      • getNakedBoundJsonData

        public static java.lang.Object getNakedBoundJsonData​(java.lang.Object data)
        Gets the naked bound data from the given data
        Parameters:
        data -
        Returns:
      • isDORConfigured

        public static boolean isDORConfigured​(Resource formResource)
        This method will process the given resource and return a boolean value signifying whether DOR is present for the AF or not.
        Parameters:
        formResource - The guideContainer Resource or Form Asset Resource or CQ Page resource.
        Returns:
        true if present, false otherwise.
      • generateSOM

        public static java.lang.String generateSOM​(Resource element)
        Recursively generates the SOM Expression of an element in guide container.
        Parameters:
        element - - Resource, whose SOM Expression needs to be calculated.
        Returns:
        String - SOM Expression
      • marshallDataWithAFWrapper

        public static java.lang.Object marshallDataWithAFWrapper​(java.lang.Object data)
                                                          throws java.lang.Exception
        Marshalls the naked data with AF wrapper tags. Any custom prefill service could make use of this utility for marshalling the data
        Parameters:
        data - form data
        Returns:
        marshalled form data with AF wrapper tags
        Throws:
        java.lang.Exception
      • getRedirectUrl

        public static java.lang.String getRedirectUrl​(java.lang.String redirectUrl,
                                                      java.lang.String formPath)
      • getGuideContainerFromFormPage

        public static java.util.List<Resource> getGuideContainerFromFormPage​(Resource formPageResource)
      • convertFMAssetPathToFormPagePath

        public static java.lang.String convertFMAssetPathToFormPagePath​(java.lang.String FMAssetPath)
      • convertFormPagePathToFMAssetPath

        public static java.lang.String convertFormPagePathToFMAssetPath​(java.lang.String formPagePath)
      • convertADAssetPathToWebChannelPagePath

        public static java.lang.String convertADAssetPathToWebChannelPagePath​(java.lang.String FMDocAssetPath)
      • isWebChannel

        public static boolean isWebChannel​(Resource resource)
        Checks whether resource is a web channel resource. It checks fd:channelType property on jcr:content node.
        Parameters:
        resource -
        Returns:
        boolean
      • getParentResource

        public static Resource getParentResource​(Resource resource,
                                                 java.lang.String parentResourceType)
      • getCommonRepeatableBindRefForTableRow

        public static java.util.Map<java.lang.String,​java.lang.Object> getCommonRepeatableBindRefForTableRow​(GuideModelImporter guideModelImporter,
                                                                                                                   Resource tableRowResource,
                                                                                                                   Resource guideContainerResource)
      • getCommonRepeatableItemForChart

        public static java.util.Map<java.lang.String,​java.lang.Object> getCommonRepeatableItemForChart​(GuideModelImporter guideModelImporter,
                                                                                                             Resource chartResource,
                                                                                                             Resource guideContainerResource)
      • getFileAttachmentWrapperList

        public static java.util.List<FileAttachmentWrapper> getFileAttachmentWrapperList​(ParameterMap parameterMap)
        This method is used to get the List of Attachments passed with the form.
        Parameters:
        parameterMap - Map of request parameters
        Returns:
        List of Attachments sent along with form
      • setMasterAuthoringConfig

        public static void setMasterAuthoringConfig​(java.util.Map<java.lang.String,​java.lang.Object> authoringConfig,
                                                    ValueMap resourceProps)
      • isValidFormResource

        public static boolean isValidFormResource​(ResourceResolver resourceResolver,
                                                  java.lang.String formPath,
                                                  java.lang.String formType)
        Check if formPath points to valid resource of type formType
        Parameters:
        resourceResolver -
        formPath -
        formType - - formType is "guide" for AdaptiveForm and "mcdocument" for IC
        Returns:
        boolean value
      • processChartAddition

        public static boolean processChartAddition​(GuideModelImporter guideModelImporter,
                                                   Resource chartResource,
                                                   Resource guideContainerResource)
                                            throws java.lang.Exception
        Throws:
        java.lang.Exception
      • isDorTemplateAnAcroForm

        public static boolean isDorTemplateAnAcroForm​(java.lang.String templatePath,
                                                      ResourceResolver resourceResolver)
      • syncExcludeFromDorData

        public static java.lang.String syncExcludeFromDorData​(java.lang.String dataJSON,
                                                              java.lang.String ServerSideExcludeFromDorData)
        Aligns the excludeFromDor Data present in the data.json with the one computed in server-side-validation (source of truth)
        Parameters:
        dataJSON - string representing data.json
        ServerSideExcludeFromDorData - string computed as part of server side validation
        Returns:
        updated data xml string.
      • getFormRelativePath

        public static java.lang.String getFormRelativePath​(java.lang.String formContainerPath)
      • getFormResourceFromEncodedPath

        public static Resource getFormResourceFromEncodedPath​(java.lang.String encodedFormPath,
                                                              ResourceResolver resourceResolver)
      • getFormContainerResourceFromEncodedPath

        public static Resource getFormContainerResourceFromEncodedPath​(java.lang.String encodedFormPath,
                                                                       ResourceResolver resourceResolver)
      • sanitizeJSON

        public static java.lang.String sanitizeJSON​(java.lang.String str,
                                                    XSSAPI xssapi)
        sanitize the given json string
      • getFormDataId

        public static java.lang.String getFormDataId​(java.lang.String formContainerPath,
                                                     java.lang.String submissionId,
                                                     java.util.Date date)
      • getFormName

        public static java.lang.String getFormName​(java.lang.String guidePath)
        This function extracts the form name from the guideContainerPath.
        Parameters:
        guidePath - The path to the af guideContainer or a component inside af .
        Returns:
        The name of the form for this guidePath
      • convertArrayValuesToCommaSeparatedValues

        public static JSONObject convertArrayValuesToCommaSeparatedValues​(JSONObject data)
                                                                   throws JSONException
        Utility function to convert the array values to comma separated values Ex: {"key": ["value1", "value2"]} will be converted to {"key": "value1,value2"}
        Parameters:
        data - JSONObject containing the form data
        Returns:
        Throws:
        JSONException