Class FormUtils


  • public final class FormUtils
    extends Object
    Provides miscellaneous form related utility methods.
    • Constructor Detail

      • FormUtils

        public FormUtils()
    • Method Detail

      • doesFormSupportEmbedWithDiv

        public static boolean doesFormSupportEmbedWithDiv​(Form form)
        Return true if the form's current template version supports HTML 'Embed with Div'.
        Parameters:
        form - the form to test
        Returns:
        true if the form's current template version supports HTML 'Embed with Div'
      • isUseComposerHtmlForm

        public static boolean isUseComposerHtmlForm​(HttpServletRequest request,
                                                    TemplateVersion templateVersion)
        Return true if the TemplateVersion has a Composer HTML Form and it should be used for the given request.
        Parameters:
        request - the user request
        templateVersion - the form template version
        Returns:
        true if a Composer HTML Form can and should be served to the request
      • isUseComposerHtmlDirectRender

        public static boolean isUseComposerHtmlDirectRender​(HttpServletRequest request,
                                                            Form form,
                                                            TemplateVersion templateVersion)
        Return true if the Composer HTML Form should be rendered directly.
        Parameters:
        request - the render request
        form - the form
        templateVersion - the form template version
        Returns:
        true if should use direct render servlet
        Since:
        3.6.0
      • validateSchemaSeed

        public static String validateSchemaSeed​(String schemaSeed)
        Check whether a schema seed string can be parsed into an XML document object.
        Parameters:
        schemaSeed - the schema seed contents as a string
        Returns:
        null if no error occurred during parsing, an error message otherwise
      • validateSchemaExtractMap

        public static String validateSchemaExtractMap​(SchemaExtractMap schemaExtractMap)
        Check whether a schema data extract mapping is set up correctly, validating the XPath.
        Parameters:
        schemaExtractMap - the non-null schema data extract mapping to be investigated
        Returns:
        null if the schema data extract mapping is set up correctly, an error message otherwise
      • validatePrefillParamXpathMap

        public static String validatePrefillParamXpathMap​(PrefillParamXpathMap prefillParamXpathMap)
        Check whether a pre-fill parameter XPATH mapping is set up correctly, validating the XPath.
        Parameters:
        prefillParamXpathMap - the non-null schema data extract mapping to be investigated
        Returns:
        null if the pre-fill parameter xpath mappinggs set up correctly, an error message otherwise
      • validatePropertyPrefillXpathMap

        public static String validatePropertyPrefillXpathMap​(PropertyPrefillMap propertyPrefillMap)
        Check whether a property pre-fill parameter XPATH mapping is set up correctly, validating the XPath.
        Parameters:
        propertyPrefillMap - the non-null schema data extract mapping to be investigated
        Returns:
        null if the pre-fill parameter xpath mappings set up correctly, an error message otherwise
        Since:
        18.11.0
      • validateXmlInputMapXpathMap

        public static String validateXmlInputMapXpathMap​(XmlInputMap xmlInputMapXpath)
        Check whether a XmlInputMap XPATH mapping is set up correctly, validating the XPath.
        Parameters:
        xmlInputMapXpath - the non-null schema data extract mapping to be investigated
        Returns:
        null if the pre-fill parameter xpath mappings set up correctly, an error message otherwise
        Since:
        18.11.0
      • validateTemplateFilename

        public static String validateTemplateFilename​(String templateFileName,
                                                      String formType)
        Check a template version file name to ensure it has the appropriate extension for the specified form type.
        Parameters:
        templateFileName - the name of the template file, generally ending in .xdp or .pdf
        formType - the form type, e.g. HTML Form
        Returns:
        null if the file name is acceptable, an error message otherwise
      • getSubmissionDataDocument

        public static Document getSubmissionDataDocument​(Document document)
        Return the form submission data from XML document, stripping out any XFA elements if present.
        Parameters:
        document - the raw XML document
        Returns:
        the stripped XML document
      • stripXfdfFields

        public static void stripXfdfFields​(Document document)
        Strip XFDF nodes () from an XML document
        Parameters:
        document - the document to be modified
      • getRootDataElement

        public static Element getRootDataElement​(Document document)
        Return the submitted data payload from the submitted XML document.
        Parameters:
        document - the XML document submitted
        Returns:
        the XML data payload
      • validatePdfSmartFormTemplate

        public static String validatePdfSmartFormTemplate​(byte[] formData,
                                                          String filename)
        Check an XDP or PDF template file for correctness.
        Parameters:
        formData - the template file contents
        filename - the template file name
        Returns:
        null if no validation errors were encountered, an error message otherwise
      • getFormGuideFilename

        public static String getFormGuideFilename​(byte[] templateFileData)
        Return the file name of the Adobe LiveCycle ES form guide contained in the specified template zip file. Note that the form guide file must be located in the root folder of the zip file and the file name must end in .xdp
        Parameters:
        templateFileData - a byte array representing the form guide zip file
        Returns:
        the file name of the form guide contained in the zip file
      • getFormGuideFilesize

        public static Long getFormGuideFilesize​(byte[] templateFileData)
        Return the file size of the Adobe LiveCycle ES form guide file contained in the specified template zip file. Note that the form guide file must be located in the root folder of the zip file and the file name must end in .xdp
        Parameters:
        templateFileData - a byte array representing the form guide zip file
        Returns:
        the file size of the form guide contained in the zip file
      • isAcrobatUserAgent

        public static boolean isAcrobatUserAgent​(HttpServletRequest request)
        Determine whether the user agent contained in the request is Adobe Acrobat stand-alone (as opposed to an Adobe browser plugin)
        Parameters:
        request - the HTTP servlet request
        Returns:
        whether the reported user agent is Adobe Acrobat
      • isReaderUserAgent

        public static boolean isReaderUserAgent​(HttpServletRequest request)
        Determine whether the user agent contained in the request is Adobe Reader stand-alone (as opposed to an Adobe browser plugin)
        Parameters:
        request - the HTTP servlet request
        Returns:
        whether the reported user agent is Adobe Reader
      • isAdobeUserAgent

        public static boolean isAdobeUserAgent​(HttpServletRequest request)
        Determine whether the user agent contained in the request is Adobe Acrobat or Reader stand-alone (as opposed to an Adobe browser plugin)
        Parameters:
        request - the HTTP servlet request
        Returns:
        whether the reported user agent is Adobe Acrobat or Reader
      • getAcrobatVersion

        public static String getAcrobatVersion​(HttpServletRequest request)
        Return the version number of Adobe Acrobat or Reader as contained in the request
        Parameters:
        request - the HTTP servlet request
        Returns:
        the Acrobat or Reader version based on the "acrobat-version" header
      • isOfflineSubmission

        public static boolean isOfflineSubmission​(HttpServletRequest request)
        Determine whether a form submission was made using a browser plugin or offline (using Adobe Acrobat or Reader stand-alone)
        Parameters:
        request - the HTTP servlet request
        Returns:
        true the submission was made offline, false otherwise
      • createOfflineSubmitXML

        public static String createOfflineSubmitXML​(Document seedDocument,
                                                    String actionType,
                                                    String actionUrl,
                                                    String errorMessage)
        Create offline submit XML from a given submission.
        Parameters:
        seedDocument - the seed document
        actionType - the action type
        actionUrl - the action url
        errorMessage - the error message
        Returns:
        the created offline submit XML
      • ensureRequestedFormValid

        public static boolean ensureRequestedFormValid​(org.apache.click.Page page,
                                                       String formCode)
        Validate a form that is being requested by a user. If an issue is detected, a redirect to the appropriate page is sent and false returned.
        Parameters:
        page - the page handling the request
        formCode - the form code of the requested form
        Returns:
        true if the form was valid
      • ensureRequestedFormValid

        public static boolean ensureRequestedFormValid​(org.apache.click.Page page,
                                                       Form form)
        Validate a form that is being requested by a user. If an issue is detected, a redirect to the appropriate page is sent and false returned.
        Parameters:
        page - the page handling the request
        form - the requested form
        Returns:
        true if the form was valid
      • hasFormRenderCapacity

        public static boolean hasFormRenderCapacity​(TemplateVersion templateVersion)
        Return true if the server has capacity and to render the given form template.
        Parameters:
        templateVersion - the form version
        Returns:
        true if the server has capacity and to render the given form template
        Since:
        4.0.0
      • returnToForm

        public static void returnToForm​(String submitKey,
                                        HttpServletRequest request,
                                        SubmissionService submissionService)
        Cancels a submission, then returns to the form, preserving the submission but erasing progress from the submission action onwards (e.g. attachments). The submission must be specified by submitKey, either explicitly or as a request parameter.
        Parameters:
        submitKey - the submitKey of the submission (optional - if not present, the request parameter "submitKey" will be interrogated)
        request - the current HTTP servlet request (required)
        submissionService - the submission service to be used to delete the submission (required)
      • encodeURLParamsAsJsonPrefillData

        public static String encodeURLParamsAsJsonPrefillData​(HttpServletRequest request)
        Return the URL request parameters encoded as a JSON prefill data object.
        Parameters:
        request - the servlet request
        Returns:
        the URL request parameters encoded as a JSON prefill data object.
      • appendSessionFormRequestParameters

        public static void appendSessionFormRequestParameters​(HttpSession session,
                                                              StringBuilder urlBuilder)
        Append the session form URL request parameters to the URL string builder.
        Parameters:
        session - the servlet session
        urlBuilder - the URL string builder
      • appendSessionFormRequestParameters

        public static void appendSessionFormRequestParameters​(HttpSession session,
                                                              StringBuilder urlBuilder,
                                                              Map<String,​Object> addedParams)
        Append the session form URL request parameters to the URL string builder. Check if a parameter with a certain key and value should not be added.
        Parameters:
        session - the servlet session
        urlBuilder - the URL string builder
        addedParams - parameters which should not be added from session
        Since:
        5.1.3
      • getSafeRequestParams

        public static Map<String,​String> getSafeRequestParams​(HttpServletRequest request)
        Return a map of safe request parameters, which have XSS script values removed and are normalized into single request parameter and value pair.
        Parameters:
        request - the servlet request
        Returns:
        the normalized and XSS safe request parameter map
        Since:
        3.6.0
      • storeFormRequestParams

        public static void storeFormRequestParams​(HttpServletRequest request,
                                                  boolean createNew)
        Store the request parameters in the session under the key 'FormRequestParams'. If createNew is specified then any existing parameter map will be replace with a new map and no previous values will be preserved. Otherwise the values request parameters will be added to the existing session map.
        Parameters:
        request - the servlet request
        createNew - specify whether to replace the existing parameters entirely, or if false add them to the existing session map
        Since:
        3.5.1
      • clearFormRequestParams

        public static void clearFormRequestParams​(HttpServletRequest request)
        Clear the request parameters in the session under the key 'FormRequestParams'.
        Parameters:
        request - the servlet request (required)
        Since:
        4.0.0
      • requireFormTerms

        public static boolean requireFormTerms​(Submission submission,
                                               Form form,
                                               HttpServletRequest request)
        Check whether the form require form terms.
        Parameters:
        submission - the submission
        form - the form
        request - the request
        Returns:
        true, if the form require form terms
        Since:
        3.5.1
      • getSavedFormnLastEditInfo

        public static String getSavedFormnLastEditInfo​(Submission submission,
                                                       HttpServletRequest request)
        Return the saved form last edit info warning message if the form was opened by another user within the Security Managers configured session timeout period.
        Parameters:
        submission - the saved submission to test (required)
        request - the HTTP servlet request (required)
        Returns:
        the saved form last edit info, or null warning is required
      • checkRequestLogUser

        public static boolean checkRequestLogUser​(RequestLog requestLog,
                                                  String userNameToCheck)
        Checks if the given user name matches the user name stored in the request log.
        Parameters:
        requestLog - the request log (required)
        userNameToCheck - the user name to check, generally obtained from the HTTP servlet request
        Returns:
        true if userNameToCheck matches the request log user (taking into account possible truncation)
        Since:
        3.6.1