toolbox.web.validation
Class ValidatorImpl

Package class diagram package ValidatorImpl
java.lang.Object
  extended by toolbox.web.validation.ValidatorImpl
All Implemented Interfaces:
Validator

public class ValidatorImpl
extends java.lang.Object
implements Validator

Default validator implementation that takes the form configurations from an XML configuration file.


Field Summary
static java.util.ArrayList NUMBER_TYPES
          Contains a list of supported number wrappers.
static java.lang.String THOUSANDS_SEPARATOR
          Thousands separator replaced when validating numbers.
 
Constructor Summary
ValidatorImpl()
          Default constructor.
 
Method Summary
 java.util.List getFields(java.lang.String form)
          Implemented to comply with interface definition.
 java.util.ResourceBundle getResource(java.util.Locale locale)
          Implemented to comply with interface definition.
 void init(java.lang.String name, XMLProperties xmlProps)
          Initialise all configured forms and place them in the forms map.
 java.util.Map validate(java.lang.String formName, javax.servlet.ServletRequest request)
          Validates the given request and returns a map of validated values.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

THOUSANDS_SEPARATOR

public static java.lang.String THOUSANDS_SEPARATOR
Thousands separator replaced when validating numbers. Default=" ";


NUMBER_TYPES

public static final java.util.ArrayList NUMBER_TYPES
Contains a list of supported number wrappers.

Constructor Detail

ValidatorImpl

public ValidatorImpl()
Default constructor.

Method Detail

init

public void init(java.lang.String name,
                 XMLProperties xmlProps)
          throws ValidationException
Initialise all configured forms and place them in the forms map.

Specified by:
init in interface Validator
Parameters:
name - Name of this validator.
xmlProps - XML configuration properties.
Throws:
ValidationException - if configured forms cannot be initialised.

validate

public java.util.Map validate(java.lang.String formName,
                              javax.servlet.ServletRequest request)
                       throws ValidationException
Validates the given request and returns a map of validated values.

This implementation steps thru a map of FormField instances and tries to validate each field instance with the value obtained from the given SerlvetRequest.

Specified by:
validate in interface Validator
Parameters:
formName - Name of the form to validate.
request - Serlvet request containing form data.
Returns:
Map containing the validated values.
Throws:
ValidationException - if the request could not be validated.

getResource

public java.util.ResourceBundle getResource(java.util.Locale locale)
                                     throws ValidationException
Implemented to comply with interface definition.

Specified by:
getResource in interface Validator
Parameters:
locale - Locale to use. May be null.
Returns:
ResourceBundle instance.
Throws:
ValidationException - if the resource cannot be obtained.

getFields

public java.util.List getFields(java.lang.String form)
Implemented to comply with interface definition.

Specified by:
getFields in interface Validator
Parameters:
form - String containing form grouping name.
Returns:
List containing Field instances for grouping.