org.infoglue.cms.util.validators
Class CommonsValidator

java.lang.Object
  extended by org.infoglue.cms.util.validators.CommonsValidator

public class CommonsValidator
extends java.lang.Object

Contains validation methods for different unit tests.


Field Summary
static java.lang.String FIELD_TEST_EQUAL
           
static java.lang.String FIELD_TEST_NOTNULL
           
static java.lang.String FIELD_TEST_NULL
           
 
Constructor Summary
CommonsValidator()
           
 
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 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 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 validatePositive(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if field is positive assuming it is an integer
static boolean validateRaiseException(java.lang.Object bean, org.apache.commons.validator.Field field)
          Throws a runtime exception if the value of the argument is "RUNTIME", an exception if the value of the argument is "CHECKED", and a ValidatorException otherwise.
static boolean validateRegexp(java.lang.Object bean, org.apache.commons.validator.Field field)
          Checks if the field value matches a regexp.
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)
           
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

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
Constructor Detail

CommonsValidator

public CommonsValidator()
Method Detail

validateRaiseException

public static boolean validateRaiseException(java.lang.Object bean,
                                             org.apache.commons.validator.Field field)
                                      throws java.lang.Exception
Throws a runtime exception if the value of the argument is "RUNTIME", an exception if the value of the argument is "CHECKED", and a ValidatorException otherwise.

Parameters:
value - string which selects type of exception to generate
Throws:
java.lang.RuntimeException - with "RUNTIME-EXCEPTION as message" if value is "RUNTIME"
java.lang.Exception - with "CHECKED-EXCEPTION" as message if value is "CHECKED"
org.apache.commons.validator.ValidatorException - with "VALIDATOR-EXCEPTION" as message otherwise

validateRequired

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

Parameters:
value - The value validation is being performed on.
Returns:
boolean If the field isn't null and has a length greater than zero, true is returned. Otherwise false.

validateByte

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

Parameters:
value - The value validation is being performed on.
Returns:
boolean If the field can be successfully converted to a byte true is returned. Otherwise false.

validateShort

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

Parameters:
value - The value validation is being performed on.
Returns:
boolean If the field can be successfully converted to a short true is returned. Otherwise false.

validateInt

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

Parameters:
value - The value validation is being performed on.
Returns:
boolean If the field can be successfully converted to a int true is returned. Otherwise false.

validatePositive

public static boolean validatePositive(java.lang.Object bean,
                                       org.apache.commons.validator.Field field)
Checks if field is positive assuming it is an integer

Parameters:
value - The value validation is being performed on.
field - Description of the field to be evaluated
Returns:
boolean If the integer field is greater than zero, returns true, otherwise returns false.

validateLong

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

Parameters:
value - The value validation is being performed on.
Returns:
boolean If the field can be successfully converted to a long true is returned. Otherwise false.

validateFloat

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

Parameters:
value - The value validation is being performed on.
Returns:
boolean If the field can be successfully converted to a float true is returned. Otherwise false.

validateDouble

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

Parameters:
value - The value validation is being performed on.
Returns:
boolean If the field can be successfully converted to a double true is returned. Otherwise false.

validateEmail

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

Parameters:
value - The value validation is being performed on.
Returns:
boolean If the field is an e-mail address true is returned. Otherwise false.

validateRegexp

public static boolean validateRegexp(java.lang.Object bean,
                                     org.apache.commons.validator.Field field)
Checks if the field value matches a regexp.


validateRequiredIf

public static boolean validateRequiredIf(java.lang.Object bean,
                                         org.apache.commons.validator.Field field,
                                         org.apache.commons.validator.Validator validator)


Copyright © 2005 InfoGlue.org All Rights Reserved.