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

The following examples show how to use org.apache.commons.validator.GenericValidator. 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
private void checkParameterValues(String[] values, DataSetParameterItem dataSetParameterItem) throws InvalidParameterValue {
	logger.debug("IN");
	try {
		String parameterType = dataSetParameterItem.getType();
		if (parameterType.equalsIgnoreCase("Number")) {
			for (int i = 0; i < values.length; i++) {
				String value = values[i];
				if (GenericValidator.isBlankOrNull(value)
						|| (!(GenericValidator.isInt(value) || GenericValidator.isFloat(value) || GenericValidator.isDouble(value)
								|| GenericValidator.isShort(value) || GenericValidator.isLong(value)))) {
					InvalidParameterValue error = new InvalidParameterValue();
					error.setParameterName(dataSetParameterItem.getName());
					error.setParameterType(parameterType);
					error.setWrongParameterValue(value);
					error.setParameterFormat("");
					throw error;
				}
			}
		}
	} finally {
		logger.debug("OUT");
	}
}
 
Example 4
private List<? extends ErrorReport> validateInteger( Class<?> klass, Object propertyObject, Property property )
{
    List<ErrorReport> errorReports = new ArrayList<>();

    if ( !Integer.class.isInstance( propertyObject ) )
    {
        return errorReports;
    }

    Integer value = (Integer) propertyObject;

    if ( !GenericValidator.isInRange( value, property.getMin(), property.getMax() ) )
    {
        errorReports.add( new ErrorReport( klass, ErrorCode.E4008, property.getName(), property.getMin(), property.getMax(), value )
            .setErrorKlass( property.getKlass() ).setErrorProperty( property.getName() ) );
    }

    return errorReports;
}
 
Example 5
private List<? extends ErrorReport> validateFloat( Class<?> klass, Object propertyObject, Property property )
{
    List<ErrorReport> errorReports = new ArrayList<>();

    if ( !Float.class.isInstance( propertyObject ) )
    {
        return errorReports;
    }

    Float value = (Float) propertyObject;

    if ( !GenericValidator.isInRange( value, property.getMin(), property.getMax() ) )
    {
        errorReports.add( new ErrorReport( klass, ErrorCode.E4008, property.getName(), property.getMin(), property.getMax(), value )
            .setErrorKlass( property.getKlass() ).setErrorProperty( property.getName() ) );
    }

    return errorReports;
}
 
Example 6
private List<? extends ErrorReport> validateDouble( Class<?> klass, Object propertyObject, Property property )
{
    List<ErrorReport> errorReports = new ArrayList<>();

    if ( !Double.class.isInstance( propertyObject ) )
    {
        return errorReports;
    }

    Double value = (Double) propertyObject;

    if ( !GenericValidator.isInRange( value, property.getMin(), property.getMax() ) )
    {
        errorReports.add( new ErrorReport( klass, ErrorCode.E4008, property.getName(), property.getMin(), property.getMax(), value )
            .setErrorKlass( property.getKlass() ).setErrorProperty( property.getName() ) );
    }

    return errorReports;
}
 
Example 7
Source Project: development   Source File: ADMValidator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected boolean isValidAuthority(String authority) {
    if (relative && authority == null) {
        return true;
    }

    boolean isValid = super.isValidAuthority(authority);

    if (!isValid && !GenericValidator.isBlankOrNull(authority)) {
        if (isValidAuthorityHostNoDot(authority)) {
            return true;
        } else if (isValidAuthorityHostNoTld(authority)) {
            return true;
        } else {
            return isValidAuthorityIPV6Host(authority);
        }
    } else {
        return isValid;
    }
}
 
Example 8
Source Project: development   Source File: ADMValidator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Check if the authority contains a valid hostname without "."
 * characters and an optional port number
 * 
 * @param authority
 * @return <code>true</code> if the authority is valid
 */
private boolean isValidAuthorityHostNoDot(String authority) {
    Perl5Util authorityMatcher = new Perl5Util();
    if (authority != null
            && authorityMatcher.match(
                    "/^([a-zA-Z\\d\\-\\.]*)(:\\d*)?(.*)?/", authority)) {
        String hostIP = authorityMatcher.group(1);
        if (hostIP.indexOf('.') < 0) {
            // the hostname contains no dot, add domain validation to check invalid hostname like "g08fnstd110825-"
            DomainValidator domainValidator = DomainValidator.getInstance(true);
            if(!domainValidator.isValid(hostIP)) {
                return false;
            }
            String port = authorityMatcher.group(2);
            if (!isValidPort(port)) {
                return false;
            }
            String extra = authorityMatcher.group(3);
            return GenericValidator.isBlankOrNull(extra);
        } else {
            return false;
        }
    } else {
        return false;
    }
}
 
Example 9
Source Project: development   Source File: BLValidator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Either question and answer are not set or both must be set.
 * 
 * @param question
 *            the security question.
 * @param answer
 *            the security answer.
 */
public static void isSecurityInfo(String question, String answer)
        throws ValidationException {
    BLValidator.isDescription("securityQuestion", question, false);
    BLValidator.isDescription("securityAnswer", answer, false);

    if (!GenericValidator.isBlankOrNull(question)
            || !GenericValidator.isBlankOrNull(answer)) {
        if (GenericValidator.isBlankOrNull(question)
                || GenericValidator.isBlankOrNull(answer)) {
            ValidationException vf = new ValidationException(
                    ReasonEnum.SECURITY_INFO, null, null);
            logValidationFailure(vf);
            throw vf;
        }
    }
}
 
Example 10
Source Project: development   Source File: UserDataAssembler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Updates all fields in the platform user object for which a LDAP attribute
 * is configured. <br>
 * The filed "userid", will not be updated since it's possible that the new
 * LDAP user id is not unique in BES. For this reason the field
 * "realmuserid" will be updated to be in sync with LDAP.
 * 
 * @param userDetails
 *            The value object containing the values to be set.
 * @param settingList
 *            The list with the configured LDAP attributes.
 * @param userToBeUpdated
 *            The platform user object to be updated.
 * @return The updated platform user object.
 * @throws ValidationException
 *             Thrown if the validation of the value objects failed.
 */
public static PlatformUser updatePlatformUser(VOUserDetails userDetails,
        List<SettingType> settingList, PlatformUser userToBeUpdated) {
    for (int i = 0; i < settingList.size(); i++) {
        if (settingList.get(i) == SettingType.LDAP_ATTR_ADDITIONAL_NAME) {
            userToBeUpdated.setAdditionalName(userDetails
                    .getAdditionalName());
        } else if (settingList.get(i) == SettingType.LDAP_ATTR_EMAIL) {
            if (!GenericValidator.isBlankOrNull(userDetails.getEMail())) {
                userToBeUpdated.setEmail(userDetails.getEMail());
            }
        } else if (settingList.get(i) == SettingType.LDAP_ATTR_FIRST_NAME) {
            userToBeUpdated.setFirstName(userDetails.getFirstName());
        } else if (settingList.get(i) == SettingType.LDAP_ATTR_LAST_NAME) {
            userToBeUpdated.setLastName(userDetails.getLastName());
        } else if (settingList.get(i) == SettingType.LDAP_ATTR_UID) {
            // Do not update the userid here because a update can violate
            // the unique constraint in BES.
            userToBeUpdated.setRealmUserId((userDetails.getRealmUserId()));
        }
    }
    return userToBeUpdated;
}
 
Example 11
Source Project: development   Source File: LongValidator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Parses the specified string into a long integer.
 * 
 * @param context
 *            FacesContext for the request we are processing
 * @param component
 *            UIComponent we are checking for correctness
 * @param value
 *            the value to parse
 * @throws ValidatorException
 *             if the specified string could not be parsed into a valid long
 *             integer.
 */
public static long parse(FacesContext context, UIComponent uiComponent,
        String value) throws ValidatorException {
    if (!GenericValidator.isLong(value)) {
        Object[] args = null;
        String label = JSFUtils.getLabel(uiComponent);
        if (label != null) {
            args = new Object[] { label };
        }
        ValidationException e = new ValidationException(
                ValidationException.ReasonEnum.LONG, label, null);
        String message = JSFUtils.getText(e.getMessageKey(), args, context);
        throw getException(message);
    }
    return Long.parseLong(value);
}
 
Example 12
Source Project: development   Source File: ParameterValueValidator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Validate integer value.
 * 
 * @param context
 *            JSF context.
 * @param uiComponent
 *            UI component.
 * @param value
 *            Value for validation.
 */
private void validateInteger(FacesContext context, UIComponent uiComponent,
        String value) {
    if (!GenericValidator.isInt(value.toString())) {
        Object[] args = null;
        String label = JSFUtils.getLabel(uiComponent);
        if (label != null) {
            args = new Object[] { label };
        }
        ValidationException e = new ValidationException(
                ValidationException.ReasonEnum.INTEGER, label, null);
        String text = JSFUtils.getText(e.getMessageKey(), args, context);
        throw new ValidatorException(new FacesMessage(
                FacesMessage.SEVERITY_ERROR, text, null));
    }
}
 
Example 13
Source Project: development   Source File: LongParameterValidator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void validate(Object obj) throws ValidationException {
    super.validate(obj);
    VOParameter parameter = (VOParameter) obj;
    VOParameterDefinition parameterDefinition = parameter
            .getParameterDefinition();

    if (isOptionalAndNullOrEmpty(parameter)) {
        return;
    }

    if (!GenericValidator.isLong(parameter.getValue())) {
        throw new ValidationException(ValidationException.ReasonEnum.LONG,
                null, new Object[] { parameter.getParameterDefinition()
                        .getParameterId() });
    }

    if (!isValid(parameter, parameterDefinition)) {
        throw new ValidationException(
                ValidationException.ReasonEnum.VALUE_NOT_IN_RANGE, null,
                new Object[] { parameter.getParameterDefinition()
                        .getParameterId() });
    }
}
 
Example 14
Source Project: development   Source File: IntegerParameterValidator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void validate(Object obj) throws ValidationException {
    super.validate(obj);
    VOParameter parameter = (VOParameter) obj;
    VOParameterDefinition parameterDefinition = parameter
            .getParameterDefinition();

    if(isOptionalAndNullOrEmpty(parameter)) {
        return;
    }
    
    if (!GenericValidator.isInt(parameter.getValue())) {
        throw new ValidationException(
                ValidationException.ReasonEnum.INTEGER, null,
                new Object[] { parameter.getParameterDefinition()
                        .getParameterId() });
    }

    if (!isValid(parameter, parameterDefinition)) {
        throw new ValidationException(
                ValidationException.ReasonEnum.VALUE_NOT_IN_RANGE, null,
                new Object[] { parameter.getParameterDefinition()
                        .getParameterId() });
    }
}
 
Example 15
Source Project: sinavi-jfw   Source File: DateEditor.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setAsText(String text) {

    if (allowEmpty && Strings.isEmpty(text)) {
        setValue(null);
    } else if (GenericValidator.isDate(text, pattern, strict)) {
        try {
            setValue(this.dateFormat.parse(text));
        } catch (ParseException e) {
            throw new PropertyEditingException(CODE, Strings.substitute(message, Maps.hash("pattern", pattern)));
        }
    } else {
        throw new PropertyEditingException(CODE, Strings.substitute(message, Maps.hash("pattern", pattern)));
    }
}
 
Example 16
/**
 * Compares the two fields using the given comparator
 * 
 * @param bean
 * @param va
 * @param field
 * @param errors
 * @param request
 * @param comparator
 * @return
 */
private static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        HttpServletRequest request, Comparator comparator) {
    String greaterInputString = ValidatorUtils.getValueAsString(bean, field.getProperty());
    String secondProperty = field.getVarValue("secondProperty");
    String lowerInputString = ValidatorUtils.getValueAsString(bean, secondProperty);

    if (!GenericValidator.isBlankOrNull(lowerInputString) && !GenericValidator.isBlankOrNull(greaterInputString)) {
        try {
            Double lowerInput = new Double(lowerInputString);
            Double greaterInput = new Double(greaterInputString);
            // if comparator result != VALUE then the condition is false
            if (comparator.compare(lowerInput, greaterInput) != VALUE) {
                errors.add(field.getKey(), Resources.getActionMessage(request, va, field));
                return false;
            }
            return true;
        } catch (NumberFormatException e) {
            errors.add(field.getKey(), new ActionMessage(va.getMsg()));
            return false;
        }
    }
    return true;
}
 
Example 17
public static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors,
        HttpServletRequest request, ServletContext application) {

    String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
    String sProperty2 = field.getVarValue("secondProperty");
    String value2 = ValidatorUtils.getValueAsString(bean, sProperty2);

    if (!GenericValidator.isBlankOrNull(value)) {
        try {
            if (!value.equals(value2)) {
                errors.add(field.getKey(), new ActionMessage("errors.different.passwords"));
                return false;
            }
        } catch (Exception e) {
            errors.add(field.getKey(), new ActionMessage("errors.different.passwords"));
            return false;
        }
    }

    return true;
}
 
Example 18
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 19
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 20
/**
 * Checks if the field is required.
 *
 * @return boolean If the field isn't <code>null</code> and
 * has a length greater than zero, <code>true</code> is returned.  
 * Otherwise <code>false</code>.
 */
public static boolean validateRequired(Object bean, Field field,
        ValidatorResults results, ValidatorAction action) {
   String value = ValidatorUtils.getValueAsString(bean, field.getProperty());

   boolean valid = !GenericValidator.isBlankOrNull(value);
   results.add(field, action.getName(), valid, value);
   return valid;
}
 
Example 21
public static boolean validateMaxLength(Object bean, Field field, ValidatorResults results, ValidatorAction action) {
	String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
	if (value == null) {
		return true;
	}
	int max = Integer.parseInt(field.getVarValue("maxlength"));

	boolean valid = GenericValidator.maxLength(value, max);
	results.add(field, action.getName(), valid, value);
	return valid;
}
 
Example 22
public static boolean validateIntRange(Object bean, Field field, ValidatorResults results, ValidatorAction action) {
	String value = ValidatorUtils.getValueAsString(bean, field.getProperty());
	if (value == null) {
		return true;
	}
	int intValue = Integer.parseInt(value);
	int min = Integer.parseInt(field.getVarValue("min"));
	int max = Integer.parseInt(field.getVarValue("max"));

	boolean valid = GenericValidator.isInRange(intValue, min, max);
	results.add(field, action.getName(), valid, value);
	return valid;
}
 
Example 23
Source Project: openemm   Source File: ComAdminForm.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Validate the properties that have been set from this HTTP request, and
 * return an <code>ActionMessages</code> object that encapsulates any
 * validation errors that have been found. If no errors are found, return
 * <code>null</code> or an <code>ActionMessages</code> object with no
 * recorded error messages.
 * 
 * @param mapping
 *            The mapping used to select this instance
 * @param request
 *            The servlet request we are processing
 * @return errors
 */
@Override
public ActionErrors formSpecificValidate(ActionMapping mapping, HttpServletRequest request) {
	ActionErrors actionErrors = new ActionErrors();
	boolean doNotDelete = request.getParameter("delete") == null || request.getParameter("delete").isEmpty();
	if (doNotDelete && "save".equals(action)) {
		if (username == null || username.length() < 3) {
			actionErrors.add("username", new ActionMessage("error.username.tooShort"));
		} else if(username.length() > 180) {
			actionErrors.add("username", new ActionMessage("error.username.tooLong"));
		}

		if (!StringUtils.equals(password, passwordConfirm)) {
			actionErrors.add("password", new ActionMessage("error.password.mismatch"));
		}

		if (StringUtils.isBlank(fullname) || fullname.length() < 2) {
			actionErrors.add("fullname", new ActionMessage("error.name.too.short"));
		} else if (fullname.length() > 100) {
			actionErrors.add("fullname", new ActionMessage("error.username.tooLong"));
		}

		if (StringUtils.isBlank(firstname) || firstname.length() < 2) {
			actionErrors.add("firstname", new ActionMessage("error.name.too.short"));
		} else if (firstname.length() > 100) {
			actionErrors.add("firstname", new ActionMessage("error.username.tooLong"));
		}

		if (StringUtils.isBlank(companyName) || companyName.length() < 2) {
			actionErrors.add("companyName", new ActionMessage("error.company.tooShort"));
		} else if (companyName.length() > 100) {
			actionErrors.add("companyName", new ActionMessage("error.company.tooLong"));
		}

		if (GenericValidator.isBlankOrNull(this.email) || !AgnitasEmailValidator.getInstance().isValid(email)) {
			actionErrors.add("mailForReport", new ActionMessage("error.invalid.email"));
		}
	}
	return actionErrors;
}
 
Example 24
Source Project: hop   Source File: ActionValidatorUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Fails if a field's value does not match the given mask.
 */
public static boolean validateMask( ICheckResultSource source, String propertyName, int levelOnFail,
                                    List<ICheckResult> remarks, String mask ) {
  final String VALIDATOR_NAME = "matches";
  String value = null;

  value = ValidatorUtils.getValueAsString( source, propertyName );

  try {
    if ( null == mask ) {
      addGeneralRemark(
        source, propertyName, VALIDATOR_NAME, remarks, "errors.missingVar",
        ICheckResult.TYPE_RESULT_ERROR );
      return false;
    }

    if ( StringUtils.isNotBlank( value ) && !GenericValidator.matchRegexp( value, mask ) ) {
      addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, levelOnFail );
      return false;
    } else {
      return true;
    }
  } catch ( Exception e ) {
    addExceptionRemark( source, propertyName, VALIDATOR_NAME, remarks, e );
    return false;
  }
}
 
Example 25
Source Project: hop   Source File: NotBlankValidator.java    License: Apache License 2.0 5 votes vote down vote up
public boolean validate( ICheckResultSource source, String propertyName,
                         List<ICheckResult> remarks, ValidatorContext context ) {
  String value = ValidatorUtils.getValueAsString( source, propertyName );
  if ( GenericValidator.isBlankOrNull( value ) ) {
    ActionValidatorUtils.addFailureRemark(
      source, propertyName, VALIDATOR_NAME, remarks, ActionValidatorUtils.getLevelOnFail(
        context, VALIDATOR_NAME ) );
    return false;
  } else {
    return true;
  }
}
 
Example 26
Source Project: hop   Source File: EmailValidator.java    License: Apache License 2.0 5 votes vote down vote up
public boolean validate( ICheckResultSource source, String propertyName,
                         List<ICheckResult> remarks, ValidatorContext context ) {
  String value = null;

  value = ValidatorUtils.getValueAsString( source, propertyName );

  if ( !GenericValidator.isBlankOrNull( value ) && !GenericValidator.isEmail( value ) ) {
    ActionValidatorUtils.addFailureRemark(
      source, propertyName, VALIDATOR_NAME, remarks, ActionValidatorUtils.getLevelOnFail(
        context, VALIDATOR_NAME ) );
    return false;
  } else {
    return true;
  }
}
 
Example 27
private void validateDate(String value) {
	String dateFormat = GeneralUtilities.getServerDateFormat();
	String timestampFormat = GeneralUtilities.getServerTimeStampFormat();
	if (!GenericValidator.isDate(value, dateFormat, true) && !GenericValidator.isDate(value, timestampFormat, true)) {
		throw new SecurityException(
				"Input value " + value + " is not a valid date according to the date format " + dateFormat + " or timestamp format " + timestampFormat);
	}
}
 
Example 28
Source Project: development   Source File: ADMValidator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Check if the authority contains a hostname without top level domain
 * and an optional port number
 * 
 * @param authority
 * @return <code>true</code> if the authority is valid
 */
private boolean isValidAuthorityHostNoTld(String authority) {
    Perl5Util authorityMatcher = new Perl5Util();
    if (authority != null
            && authorityMatcher.match(
                    "/^([a-zA-Z\\d\\-\\.]*)(:\\d*)?(.*)?/", authority)) {
        String host = authorityMatcher.group(1);
        if (host.indexOf('.') > 0) {
            DomainValidator domainValidator = DomainValidator.getInstance();
            // Make the host have a valid TLD, so that the "no TLD" host can pass the domain validation.
            String patchedHost = host + ".com";
            if(!domainValidator.isValid(patchedHost)) {
                return false;
            }
            String port = authorityMatcher.group(2);
            if (!isValidPort(port)) {
                return false;
            }
            String extra = authorityMatcher.group(3);
            return GenericValidator.isBlankOrNull(extra);
        } else {
            return false;
        }
    } else {
        return false;
    }
}
 
Example 29
Source Project: development   Source File: BLValidator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Checks that the value isn't null and doesn't only contain whitespace.
 * 
 * @param member
 *            the name of the member which holds the value.
 * @param value
 *            the value validation is being performed on.
 */
public static void isNotBlank(String member, String value)
        throws ValidationException {
    if (GenericValidator.isBlankOrNull(value)) {
        ValidationException vf = new ValidationException(
                ReasonEnum.REQUIRED, member, new Object[] { member });
        logValidationFailure(vf);
        throw vf;
    }
}
 
Example 30
Source Project: development   Source File: BLValidator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Validates that the given input is not a negative number.
 * 
 * @param member
 *            The indicator of the field to be validated.
 * @param inputValue
 *            The value to be validated.
 * @throws ValidationException
 *             Thrown in case the value is negative.
 */
public static void isNonNegativeNumber(String member, long inputValue)
        throws ValidationException {
    if (!GenericValidator.isInRange(inputValue, 0L, Long.MAX_VALUE)) {
        ValidationException vf = new ValidationException(
                ReasonEnum.POSITIVE_NUMBER, member,
                new Object[] { Long.valueOf(inputValue) });
        logValidationFailure(vf);
        throw vf;
    }
}