com.ail.core.validator
Class CommonsValidatorFunctions

java.lang.Object
  extended by com.ail.core.validator.CommonsValidatorFunctions

public class CommonsValidatorFunctions
extends java.lang.Object

Commons validator functions

Version:
$Revision: 1.2 $

Field Summary
static java.lang.String FIELD_JOIN_AND
           
static java.lang.String FIELD_TEST_DOUBLE
           
static java.lang.String FIELD_TEST_EQUAL
           
static java.lang.String FIELD_TEST_FLOAT
           
static java.lang.String FIELD_TEST_INTEGER
           
static java.lang.String FIELD_TEST_NOTNULL
           
static java.lang.String FIELD_TEST_NULL
           
static java.lang.String FIELD_TEST_SHORT
           
 
Constructor Summary
CommonsValidatorFunctions()
           
 
Method Summary
static boolean validateByte(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if the field can be successfully converted to a byte.
static boolean validateCreditCard(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if the field is a credit card.
static boolean validateDate(java.lang.Object bean, org.apache.commons.validator.Field field, java.util.Locale locale)
          Checks if the field is a date.
static boolean validateDouble(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if the field can be successfully converted to a double.
static boolean validateEmail(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if the field is an e-mail address.
static boolean validateFloat(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if the field can be successfully converted to a float.
static boolean validateInRange(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if the field is in range.
static boolean validateInt(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if the field can be successfully converted to a int.
static boolean validateLong(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if the field can be successfully converted to a long.
static boolean validateMaximumLength(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if the field is a maximum length.
static boolean validateMinimumLength(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if the field is a minimum length.
static boolean validateRegexp(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if the field matches a regular expresion.
static boolean validateRequired(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if the field is required.
static boolean validateRequiredIf(java.lang.Object bean, org.apache.commons.validator.Field field, org.apache.commons.validator.Validator validator)
          Validate only if a test is successfull on other fields // Optional - default = AND fieldJoin // AND = all field tests required to succeed before this field is required AND // otherwise treat as OR = one field test required to succeed before this field is required field[i] // name of field i (i=0 to n) lastName fieldTest[i] // NULL or NOTNULL or EQUAL EQUAL // NULL = field i must be null // NOTNULL = field i must not be null // EQUALS = field i must be equal to the value specified fieldValue[i] fieldValue[i] // only required if fieldTest[i] = EQUAL Mr // value field[i] must equal
static boolean validateShort(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if the field can be successfully converted to a short.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FIELD_TEST_DOUBLE

public static final java.lang.String FIELD_TEST_DOUBLE
See Also:
Constant Field Values

FIELD_TEST_INTEGER

public static final java.lang.String FIELD_TEST_INTEGER
See Also:
Constant Field Values

FIELD_TEST_FLOAT

public static final java.lang.String FIELD_TEST_FLOAT
See Also:
Constant Field Values

FIELD_TEST_SHORT

public static final java.lang.String FIELD_TEST_SHORT
See Also:
Constant Field Values

FIELD_TEST_NULL

public static final java.lang.String FIELD_TEST_NULL
See Also:
Constant Field Values

FIELD_TEST_NOTNULL

public static final java.lang.String FIELD_TEST_NOTNULL
See Also:
Constant Field Values

FIELD_TEST_EQUAL

public static final java.lang.String FIELD_TEST_EQUAL
See Also:
Constant Field Values

FIELD_JOIN_AND

public static final java.lang.String FIELD_JOIN_AND
See Also:
Constant Field Values
Constructor Detail

CommonsValidatorFunctions

public CommonsValidatorFunctions()
Method Detail

validateRequired

public static boolean validateRequired(java.lang.Object bean,
                                       org.apache.commons.validator.Field field)
                                throws org.exolab.castor.xml.ValidationException
Checks if the field is required.

Parameters:
bean - Object with field to validate
field - Field to validate
Returns:
boolean If the field isn't null and has a length greater than zero, true is returned. Otherwise false. throws ValidationError
Throws:
org.exolab.castor.xml.ValidationException

validateMinimumLength

public static boolean validateMinimumLength(java.lang.Object bean,
                                            org.apache.commons.validator.Field field)
                                     throws org.exolab.castor.xml.ValidationException
Checks if the field is a minimum length. minimumLength // minimum length - Default = no minimum length n

Parameters:
bean - Object with field to validate
field - Field to validate
Returns:
boolean If the field isn't null and has a length greater than the minimum length, true is returned. Otherwise false. throws ValidationException if Minimum length is not a valid integer
Throws:
org.exolab.castor.xml.ValidationException

validateMaximumLength

public static boolean validateMaximumLength(java.lang.Object bean,
                                            org.apache.commons.validator.Field field)
                                     throws org.exolab.castor.xml.ValidationException
Checks if the field is a maximum length. maximumLength // maximum length - Default = no maximum length n

Parameters:
bean - Object with field to validate
field - Field to validate
Returns:
boolean If the field isn't null and has a length less than the maximum length, true is returned. Otherwise false. throws ValidationException if Maximum length is not a valid integer
Throws:
org.exolab.castor.xml.ValidationException

validateByte

public static boolean validateByte(java.lang.Object bean,
                                   org.apache.commons.validator.Field field)
                            throws org.exolab.castor.xml.ValidationException
Checks if the field can be successfully converted to a byte.

Parameters:
bean - Object with field to validate
field - Field to validate
Returns:
boolean If the field can be successfully converted to a byte true is returned. Otherwise false. throws ValidationException
Throws:
org.exolab.castor.xml.ValidationException

validateShort

public static boolean validateShort(java.lang.Object bean,
                                    org.apache.commons.validator.Field field)
                             throws org.exolab.castor.xml.ValidationException
Checks if the field can be successfully converted to a short.

Parameters:
bean - Object with field to validate
field - Field to validate
Returns:
boolean If the field can be successfully converted to a short true is returned. Otherwise false. throws ValidationException
Throws:
org.exolab.castor.xml.ValidationException

validateInt

public static boolean validateInt(java.lang.Object bean,
                                  org.apache.commons.validator.Field field)
                           throws org.exolab.castor.xml.ValidationException
Checks if the field can be successfully converted to a int.

Parameters:
bean - Object with field to validate
field - Field to validate
Returns:
boolean If the field can be successfully converted to a int true is returned. Otherwise false. throws ValidationException
Throws:
org.exolab.castor.xml.ValidationException

validateLong

public static boolean validateLong(java.lang.Object bean,
                                   org.apache.commons.validator.Field field)
                            throws org.exolab.castor.xml.ValidationException
Checks if the field can be successfully converted to a long.

Parameters:
bean - Object with field to validate
field - Field to validate
Returns:
boolean If the field can be successfully converted to a long true is returned. Otherwise false. throws ValidationException
Throws:
org.exolab.castor.xml.ValidationException

validateFloat

public static boolean validateFloat(java.lang.Object bean,
                                    org.apache.commons.validator.Field field)
                             throws org.exolab.castor.xml.ValidationException
Checks if the field can be successfully converted to a float.

Parameters:
bean - Object with field to validate
field - Field to validate
Returns:
boolean If the field can be successfully converted to a float true is returned. Otherwise false. throws ValidationException
Throws:
org.exolab.castor.xml.ValidationException

validateDouble

public static boolean validateDouble(java.lang.Object bean,
                                     org.apache.commons.validator.Field field)
                              throws org.exolab.castor.xml.ValidationException
Checks if the field can be successfully converted to a double.

Parameters:
bean - Object with field to validate
field - Field to validate
Returns:
boolean If the field can be successfully converted to a double true is returned. Otherwise false. throws ValidationException
Throws:
org.exolab.castor.xml.ValidationException

validateEmail

public static boolean validateEmail(java.lang.Object bean,
                                    org.apache.commons.validator.Field field)
                             throws org.exolab.castor.xml.ValidationException
Checks if the field is an e-mail address.

Parameters:
bean - Object with field to validate
field - Field to validate
Returns:
boolean If the field is an e-mail address true is returned. Otherwise false. throws ValidationException
Throws:
org.exolab.castor.xml.ValidationException

validateRegexp

public static boolean validateRegexp(java.lang.Object bean,
                                     org.apache.commons.validator.Field field)
                              throws org.exolab.castor.xml.ValidationException
Checks if the field matches a regular expresion. regularExpression // expression to match *.txt

Parameters:
bean - Object with field to validate
field - Field to validate
Returns:
boolean If the field matches a regular expresion true is returned. Otherwise false. throws ValidationException
Throws:
org.exolab.castor.xml.ValidationException

validateCreditCard

public static boolean validateCreditCard(java.lang.Object bean,
                                         org.apache.commons.validator.Field field)
                                  throws org.exolab.castor.xml.ValidationException
Checks if the field is a credit card.

Parameters:
bean - Object with field to validate
field - Field to validate
Returns:
boolean If the field is a credit card true is returned. Otherwise false. throws ValidationException
Throws:
org.exolab.castor.xml.ValidationException

validateDate

public static boolean validateDate(java.lang.Object bean,
                                   org.apache.commons.validator.Field field,
                                   java.util.Locale locale)
                            throws org.exolab.castor.xml.ValidationException
Checks if the field is a date. datePattern // pattern to match to match dd/MM/yyyy // default = locale strictDate // default = true true // true = validate date length aswell as format

Parameters:
bean - Object with field to validate
field - Field to validate
locale - Date locale format if pattern not being tested
Returns:
boolean If the field is a Date true is returned. Otherwise false. throws ValidationException
Throws:
org.exolab.castor.xml.ValidationException

validateInRange

public static boolean validateInRange(java.lang.Object bean,
                                      org.apache.commons.validator.Field field)
                               throws org.exolab.castor.xml.ValidationException
Checks if the field is in range. dataType // Data type - DOUBLE, INTEGER, FLOAT, SHORT DOUBLE // default = locale minimumValue // Minimum value 5 maximumValue // Maximum value 15

Parameters:
bean - Object with field to validate
field - Field to validate
Returns:
boolean If the field is in range true is returned. Otherwise false. throws ValidationException
Throws:
org.exolab.castor.xml.ValidationException

validateRequiredIf

public static boolean validateRequiredIf(java.lang.Object bean,
                                         org.apache.commons.validator.Field field,
                                         org.apache.commons.validator.Validator validator)
                                  throws org.exolab.castor.xml.ValidationException
Validate only if a test is successfull on other fields // Optional - default = AND fieldJoin // AND = all field tests required to succeed before this field is required AND // otherwise treat as OR = one field test required to succeed before this field is required field[i] // name of field i (i=0 to n) lastName fieldTest[i] // NULL or NOTNULL or EQUAL EQUAL // NULL = field i must be null // NOTNULL = field i must not be null // EQUALS = field i must be equal to the value specified fieldValue[i] fieldValue[i] // only required if fieldTest[i] = EQUAL Mr // value field[i] must equal

Parameters:
bean - Object with field to validate
field - Field to validate
validator - Validation configuration
Returns:
boolean If all specified field tests succeed then: If the field isn't null and has a length greater than zero, true is returned. Otherwise false. Otherwise true is returned. throws ValidationException
Throws:
org.exolab.castor.xml.ValidationException