Package com.avoka.fc.core.util
Class FormUtils
java.lang.Object
com.avoka.fc.core.util.FormUtils
Provides miscellaneous form related utility methods.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
appendSessionFormRequestParameters
(jakarta.servlet.http.HttpSession session, StringBuilder urlBuilder) Append the session form URL request parameters to the URL string builder.static void
appendSessionFormRequestParameters
(jakarta.servlet.http.HttpSession session, StringBuilder urlBuilder, Map<String, Object> addedParams) Append the session form URL request parameters to the URL string builder.static boolean
checkRequestLogUser
(RequestLog requestLog, String userNameToCheck) Checks if the given user name matches the user name stored in the request log.static void
clearFormRequestParams
(jakarta.servlet.http.HttpServletRequest request) Clear the request parameters in the session under the key 'FormRequestParams'.static String
createOfflineSubmitXML
(Document seedDocument, String actionType, String actionUrl, String errorMessage) Create offline submit XML from a given submission.static boolean
Return true if the form's current template version supports HTML 'Embed with Div'.static String
encodeURLParamsAsJsonPrefillData
(jakarta.servlet.http.HttpServletRequest request) Return the URL request parameters encoded as a JSON prefill data object.static boolean
ensureRequestedFormValid
(org.apache.click.Page page, Form form) Validate a form that is being requested by a user.static boolean
ensureRequestedFormValid
(org.apache.click.Page page, String formCode) Validate a form that is being requested by a user.static String
getAcrobatVersion
(jakarta.servlet.http.HttpServletRequest request) Return the version number of Adobe Acrobat or Reader as contained in the requeststatic String
getFormGuideFilename
(byte[] templateFileData) Return the file name of the Adobe LiveCycle ES form guide contained in the specified template zip file.static Long
getFormGuideFilesize
(byte[] templateFileData) Return the file size of the Adobe LiveCycle ES form guide file contained in the specified template zip file.static Element
getRootDataElement
(Document document) Return the submitted data payload from the submitted XML document.getSafeRequestParams
(jakarta.servlet.http.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.static String
getSavedFormnLastEditInfo
(Submission submission, jakarta.servlet.http.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.static Document
getSubmissionDataDocument
(Document document) Return the form submission data from XML document, stripping out any XFA elements if present.static boolean
hasFormRenderCapacity
(TemplateVersion templateVersion) Return true if the server has capacity and to render the given form template.static boolean
isAcrobatUserAgent
(jakarta.servlet.http.HttpServletRequest request) Determine whether the user agent contained in the request is Adobe Acrobat stand-alone (as opposed to an Adobe browser plugin)static boolean
isAdobeUserAgent
(jakarta.servlet.http.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)static boolean
isOfflineSubmission
(jakarta.servlet.http.HttpServletRequest request) Determine whether a form submission was made using a browser plugin or offline (using Adobe Acrobat or Reader stand-alone)static boolean
isReaderUserAgent
(jakarta.servlet.http.HttpServletRequest request) Determine whether the user agent contained in the request is Adobe Reader stand-alone (as opposed to an Adobe browser plugin)static boolean
isUseComposerHtmlDirectRender
(jakarta.servlet.http.HttpServletRequest request, Form form, TemplateVersion templateVersion) Return true if the Composer HTML Form should be rendered directly.static boolean
isUseComposerHtmlForm
(jakarta.servlet.http.HttpServletRequest request, TemplateVersion templateVersion) Return true if the TemplateVersion has a Composer HTML Form and it should be used for the given request.static void
returnToForm
(String submitKey, jakarta.servlet.http.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.static void
storeFormRequestParams
(jakarta.servlet.http.HttpServletRequest request, boolean createNew) Store the request parameters in the session under the key 'FormRequestParams'.static void
stripXfdfFields
(Document document) Strip XFDF nodes (invalid input: '<'xfdf:field>) from an XML documentstatic String
validatePdfSmartFormTemplate
(byte[] formData, String filename) Check an XDP or PDF template file for correctness.static String
validatePrefillParamXpathMap
(PrefillParamXpathMap prefillParamXpathMap) Check whether a pre-fill parameter XPATH mapping is set up correctly, validating the XPath.static String
validatePropertyPrefillXpathMap
(PropertyPrefillMap propertyPrefillMap) Check whether a property pre-fill parameter XPATH mapping is set up correctly, validating the XPath.static String
validateSchemaExtractMap
(SchemaExtractMap schemaExtractMap) Check whether a schema data extract mapping is set up correctly, validating the XPath.static String
validateSchemaSeed
(String schemaSeed) Check whether a schema seed string can be parsed into an XML document object.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.static String
validateXmlInputMapXpathMap
(XmlInputMap xmlInputMapXpath) Check whether a XmlInputMap XPATH mapping is set up correctly, validating the XPath.
-
Constructor Details
-
FormUtils
public FormUtils()
-
-
Method Details
-
doesFormSupportEmbedWithDiv
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(jakarta.servlet.http.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 requesttemplateVersion
- the form template version- Returns:
- true if a Composer HTML Form can and should be served to the request
-
isUseComposerHtmlDirectRender
public static boolean isUseComposerHtmlDirectRender(jakarta.servlet.http.HttpServletRequest request, Form form, TemplateVersion templateVersion) Return true if the Composer HTML Form should be rendered directly.- Parameters:
request
- the render requestform
- the formtemplateVersion
- the form template version- Returns:
- true if should use direct render servlet
- Since:
- 3.6.0
-
validateSchemaSeed
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
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
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
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
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
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 .pdfformType
- the form type, e.g. HTML Form- Returns:
- null if the file name is acceptable, an error message otherwise
-
getSubmissionDataDocument
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
Strip XFDF nodes (invalid input: '<'xfdf:field>) from an XML document- Parameters:
document
- the document to be modified
-
getRootDataElement
Return the submitted data payload from the submitted XML document.- Parameters:
document
- the XML document submitted- Returns:
- the XML data payload
-
validatePdfSmartFormTemplate
Check an XDP or PDF template file for correctness.- Parameters:
formData
- the template file contentsfilename
- the template file name- Returns:
- null if no validation errors were encountered, an error message otherwise
-
getFormGuideFilename
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
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(jakarta.servlet.http.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(jakarta.servlet.http.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(jakarta.servlet.http.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
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(jakarta.servlet.http.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 documentactionType
- the action typeactionUrl
- the action urlerrorMessage
- the error message- Returns:
- the created offline submit XML
-
ensureRequestedFormValid
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 requestformCode
- the form code of the requested form- Returns:
- true if the form was valid
-
ensureRequestedFormValid
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 requestform
- the requested form- Returns:
- true if the form was valid
-
hasFormRenderCapacity
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, jakarta.servlet.http.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(jakarta.servlet.http.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(jakarta.servlet.http.HttpSession session, StringBuilder urlBuilder) Append the session form URL request parameters to the URL string builder.- Parameters:
session
- the servlet sessionurlBuilder
- the URL string builder
-
appendSessionFormRequestParameters
public static void appendSessionFormRequestParameters(jakarta.servlet.http.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 sessionurlBuilder
- the URL string builderaddedParams
- parameters which should not be added from session- Since:
- 5.1.3
-
getSafeRequestParams
public static Map<String,String> getSafeRequestParams(jakarta.servlet.http.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(jakarta.servlet.http.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 requestcreateNew
- 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(jakarta.servlet.http.HttpServletRequest request) Clear the request parameters in the session under the key 'FormRequestParams'.- Parameters:
request
- the servlet request (required)- Since:
- 4.0.0
-
getSavedFormnLastEditInfo
public static String getSavedFormnLastEditInfo(Submission submission, jakarta.servlet.http.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
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
-