126 IBM Workplace Forms: Guide to building and integrating a sample Workplace Forms application
The code is supported by an additional helper method to insert in the servlet class - it is pretty
simple to detect any changes to signed items (Example 4-16).
Example 4-16 Signature verification using Forms API
private static boolean allSignaturesAreValid(FormNodeP theForm)
throws Exception {
return (theForm.verifyAllSignatures(false) == FormNodeP.UFL_SIGS_OK);
}
There are other methods available to check validity of a single signature (verifySignature) or
even to read signature validity status on the last signature check to track newly occurred
violations (getSignatureVerificationStatus).
4.8.9 Form storage to local file system
Having all tasks completed, we can store the file to file system. The code provided for now
already created a file name (formName variable). The code to add would perform the
following actions:
Evaluate the form state to determine the target directory to store the form.
Store the form.
Remove earlier versions of this form in any other directory (we just want to keep the actual
form only).
We have already created the file system structure for storage — so we can use it now. Insert
the following code, as shown in Example 4-17, at the right place in the doPost method (see
the comment for file storage there).
Example 4-17 Status indication, target folder calculation, file storage and clean-up
/**
* Store the form into the folder indicated by the formState.
*/
String folderPath = props.getProperty(formState);
ServletContext ctx = conf.getServletContext();
String path = ctx.getRealPath(folderPath);
writeBytesToFile(path + formName, getFormBytes(theForm));
/**
* Remove the previous instance of the form. *STAGE 1*
*
*/
if (previousFormState == null) {
System.out.println("SubmissionServlet: doPost: FormMetaData: ERROR:
PreviousFormState element was null");
} else if (previousFormState.equalsIgnoreCase("2")
|| previousFormState.equalsIgnoreCase("3")
Attention: There is no method to detect which item was changed in the form with a broken
signature, since a signature is basically a hash code including all items to sign in a step. So
the validation will fail, if any item is changed.
Tip: It is not always necessary to store the form. In some cases it can be the right way to
extract only some values and store them to a back-end system.