Java Code Examples for org.apache.commons.validator.GenericTypeValidator

The following examples show how to use org.apache.commons.validator.GenericTypeValidator. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hop   Source File: IntegerValidator.java    License: Apache License 2.0 6 votes vote down vote up
public boolean validate( ICheckResultSource source, String propertyName,
                         List<ICheckResult> remarks, ValidatorContext context ) {

  Object result = null;
  String value = null;

  value = ValidatorUtils.getValueAsString( source, propertyName );

  if ( GenericValidator.isBlankOrNull( value ) ) {
    return true;
  }

  result = GenericTypeValidator.formatInt( value );

  if ( result == null ) {
    ActionValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks,
      ActionValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) );
    return false;
  }
  return true;

}
 
Example 2
Source Project: hop   Source File: LongValidator.java    License: Apache License 2.0 6 votes vote down vote up
public boolean validate( ICheckResultSource source, String propertyName,
                         List<ICheckResult> remarks, ValidatorContext context ) {
  Object result = null;
  String value = null;

  value = ValidatorUtils.getValueAsString( source, propertyName );

  if ( GenericValidator.isBlankOrNull( value ) ) {
    return Boolean.TRUE;
  }

  result = GenericTypeValidator.formatLong( value );

  if ( result == null ) {
    ActionValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks,
      ActionValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) );
    return false;
  }
  return true;
}
 
Example 3
Source Project: pentaho-kettle   Source File: IntegerValidator.java    License: Apache License 2.0 6 votes vote down vote up
public boolean validate( CheckResultSourceInterface source, String propertyName,
  List<CheckResultInterface> remarks, ValidatorContext context ) {

  Object result = null;
  String value = null;

  value = ValidatorUtils.getValueAsString( source, propertyName );

  if ( GenericValidator.isBlankOrNull( value ) ) {
    return true;
  }

  result = GenericTypeValidator.formatInt( value );

  if ( result == null ) {
    JobEntryValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks,
        JobEntryValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) );
    return false;
  }
  return true;

}
 
Example 4
Source Project: pentaho-kettle   Source File: LongValidator.java    License: Apache License 2.0 6 votes vote down vote up
public boolean validate( CheckResultSourceInterface source, String propertyName,
  List<CheckResultInterface> remarks, ValidatorContext context ) {
  Object result = null;
  String value = null;

  value = ValidatorUtils.getValueAsString( source, propertyName );

  if ( GenericValidator.isBlankOrNull( value ) ) {
    return Boolean.TRUE;
  }

  result = GenericTypeValidator.formatLong( value );

  if ( result == null ) {
    JobEntryValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks,
        JobEntryValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) );
    return false;
  }
  return true;
}
 
Example 5
/**
 * Checks if field is positive assuming it is an integer
 * 
 * @param    value       The value validation is being performed on.
 * @param    field       Description of the field to be evaluated
 * @return   boolean     If the integer field is greater than zero, returns
 *                        true, otherwise returns false.
 */
public static boolean validatePositive(Object bean, Field field,
        ValidatorResults results, ValidatorAction action) {
   String value = ValidatorUtils.getValueAsString(bean, field.getProperty());

   boolean valid = GenericTypeValidator.formatInt(value).intValue() > 0;
   results.add(field, action.getName(), valid, value);
   return valid;
}
 
Example 6
/**
 * Checks if field is not negative assuming it is an integer
 * 
 * @param    value       The value validation is being performed on.
 * @param    field       Description of the field to be evaluated
 * @return   boolean     If the integer field is greater than or equals zero, returns
 *                        true, otherwise returns false.
 */
public static boolean validatePositiveOrZero(Object bean, Field field,
        ValidatorResults results, ValidatorAction action) {
   String value = ValidatorUtils.getValueAsString(bean, field.getProperty());

   boolean valid = GenericTypeValidator.formatInt(value).intValue() >= 0;
   results.add(field, action.getName(), valid, value);
   return valid;
}