org.apache.commons.validator.GenericTypeValidator Java Examples

The following examples show how to use org.apache.commons.validator.GenericTypeValidator. 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 File: IntegerValidator.java    From hop with 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 File: LongValidator.java    From hop with 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 File: IntegerValidator.java    From pentaho-kettle with 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 File: LongValidator.java    From pentaho-kettle with 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
Source File: GenericModelChecks.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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
Source File: GenericModelChecks.java    From openemm with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}