Annotated formproc.xml

Author: Anthony Eden

The main configuration file for FormProc is called formproc.xml. This configuration file can either be placed in your class path or you can give a specific path when constructing a FormManager. The file format is XML.

The following configuration is taken from the example application which ships with the FormProc distribution.


<?xml version="1.0" encoding="ISO-8859-1"?>

This is required at the begining of every XML document. You can change the encoding value if you need to include foreign characters in your configuration.

<!-- Configuration file for a formproc FormManager -->

The first line is a comment. None of the comments shown here are required, but they can be helpful. The second line signifies the start of the FormProc configuration.

	<!-- map validator types to implementation classes -->
	<validator-map type="script" classname="org.formproc.validation.ScriptValidator">
		<property name="script-root" value=""/>
		<property name="script-root-type" value="classpath"/>
	<validator-map type="expression" classname="org.formproc.validation.REValidator"/>
	<validator-map type="rule" classname="org.formproc.validation.RuleValidator"/>
	<validator-map type="group" classname="org.formproc.validation.ValidatorGroup"/>

The first set of elements in the configuration map validator types to classes. FormProc allows you to create new validator types by extending the org.formproc.validation.Validator abstract base class. After creating the validator class you must then specify the mapping here.

Validator mappings can also include configuration information. And elements which are children of the validator-map element are considered part of the configuration information which is sent to the validator.

	<!-- define shared validators -->
	<shared-validator name="required">
		<validator type="expression">
			<error lang="en">The field is required.</error>
			<error lang="fr">Exigée</error>

This set of tags defines a shared validator with the name "required" with will validate against a regular expression. Wherever the shared validator is used, the submitted data will be compared against the regular expression defined in the pattern element. If the validation fails then an error message will be provided. The system for providing error messages is pluggable.

	<!-- include other configuration files -->
	<include loader="com.anthonyeden.lib.resource.ClassPathResourceLoader" path="formproc-include.xml" monitor="true"/>

This line tells FormProc to load configuration information from the included file. The loader attribute defines which resource loader to use. The ClassPathResourceLoader will look for the included file in the class path. The path attribute is a relative or absolute path to a file. The monitor attribute defines whether or not the included file should be monitored for changes. If the included file is changed then the configuration information within will be reloaded.

In the example configuration, the included file contains additional definitions of shared validators. Please refer to the annotated formproc-include.xml configuration file to find out more about shared validators.

	<!-- define forms -->
	<form name="test" loader="com.anthonyeden.lib.resource.ClassPathResourceLoader" path="example-form.xml" monitor="true"/>

This line defines a form. Each form which is used in your application must be defined here. The format of this element is similar to the include element. The name attribute is the name which will be used to refer to the form. The loader attribute specifies the resource loader which is used to load the form configuration. The path attribute is a relative or absolute path to the form's configuration file. The monitor attribute tells the resource loader whether or not it should monitor the resource file for changes.


Finally, the root element is closed, completing the configuration information.