org.apache.commons.validator.GenericValidator Java Examples
The following examples show how to use
org.apache.commons.validator.GenericValidator.
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: DateEditor.java From sinavi-jfw with Apache License 2.0 | 6 votes |
/** * {@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 #2
Source File: LongValidator.java From pentaho-kettle with Apache License 2.0 | 6 votes |
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 #3
Source File: LongValidator.java From hop with Apache License 2.0 | 6 votes |
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 #4
Source File: IntegerValidator.java From pentaho-kettle with Apache License 2.0 | 6 votes |
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 #5
Source File: IntegerValidator.java From hop with Apache License 2.0 | 6 votes |
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 #6
Source File: ValidateTwoFields.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
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 #7
Source File: ValidateCompareTwoFields.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 6 votes |
/** * 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 #8
Source File: DataSetsSDKServiceImpl.java From Knowage-Server with GNU Affero General Public License v3.0 | 6 votes |
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 #9
Source File: DefaultSchemaValidator.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #10
Source File: DefaultSchemaValidator.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #11
Source File: DefaultSchemaValidator.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 6 votes |
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 #12
Source File: IntegerParameterValidator.java From development with Apache License 2.0 | 6 votes |
@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 #13
Source File: ADMValidator.java From development with Apache License 2.0 | 6 votes |
@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 #14
Source File: ADMValidator.java From development with Apache License 2.0 | 6 votes |
/** * 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 #15
Source File: LongParameterValidator.java From development with Apache License 2.0 | 6 votes |
@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 #16
Source File: BLValidator.java From development with Apache License 2.0 | 6 votes |
/** * 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 #17
Source File: ParameterValueValidator.java From development with Apache License 2.0 | 6 votes |
/** * 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 #18
Source File: LongValidator.java From development with Apache License 2.0 | 6 votes |
/** * 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 #19
Source File: UserDataAssembler.java From development with Apache License 2.0 | 6 votes |
/** * 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 #20
Source File: GreaterThen.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
public static boolean validateFloat(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request, ServletContext application) { String inputString = ValidatorUtils.getValueAsString(bean, field.getProperty()); String lowerValueString = field.getVarValue("value"); if ((inputString == null) || (inputString.length() == 0)) { return true; } Double input = null; Double lowerValue = null; try { input = new Double(inputString); lowerValue = new Double(lowerValueString); } catch (NumberFormatException e) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } if (!GenericValidator.isBlankOrNull(inputString)) { if (input.floatValue() <= lowerValue.floatValue()) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); } return false; } return true; }
Example #21
Source File: ExternalParameterValidation.java From development with Apache License 2.0 | 5 votes |
private static boolean longIsValid(VOParameterDefinition parDefinition, String parValue) { if (GenericValidator.isLong(parValue.toString())) { return LongValidator.isInRange(Long.parseLong(parValue), parDefinition.getMinValue(), parDefinition.getMaxValue()); } else { return false; } }
Example #22
Source File: GenericModelChecks.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
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 #23
Source File: ValidateDate.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
public static boolean threeArgsDate(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request, ServletContext application) { String valueString1 = ValidatorUtils.getValueAsString(bean, field.getProperty()); String sProperty2 = ValidatorUtils.getValueAsString(bean, field.getVarValue("month")); String sProperty3 = ValidatorUtils.getValueAsString(bean, field.getVarValue("day")); if (((valueString1 == null) && (sProperty2 == null) && (sProperty3 == null)) || ((valueString1.length() == 0) && (sProperty2.length() == 0) && (sProperty3.length() == 0))) { // errors.add(field.getKey(),Resources.getActionError(request, va, // field)); return true; } Integer year = null; Integer month = null; Integer day = null; try { year = new Integer(valueString1); month = new Integer(sProperty2); day = new Integer(sProperty3); } catch (NumberFormatException e) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } String date = new String(day.toString() + "/" + month.toString() + "/" + year); String datePattern = "dd/MM/yyyy"; if (!GenericValidator.isDate(date, datePattern, false)) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } return true; }
Example #24
Source File: LangChecker.java From Asqatasun with GNU Affero General Public License v3.0 | 5 votes |
/** * * @param extractedText * @return */ protected boolean isTextTestable(String extractedText) { if (StringUtils.isBlank(extractedText)){ return false; } String textToTest = StringUtils.trim(extractedText); Matcher m = nonAlphanumericPattern.matcher(textToTest); return !m.matches() && !GenericValidator.isEmail(textToTest) && !GenericValidator.isUrl(textToTest); }
Example #25
Source File: ExternalParameterValidation.java From development with Apache License 2.0 | 5 votes |
private static boolean integerIsValid(VOParameterDefinition parDefinition, String parValue) { if (GenericValidator.isInt(parValue.toString())) { return LongValidator.isInRange(Integer.parseInt(parValue), parDefinition.getMinValue(), parDefinition.getMaxValue()); } else { return false; } }
Example #26
Source File: JobEntryValidatorUtils.java From pentaho-kettle with Apache License 2.0 | 5 votes |
/** * Fails if a field's value does not match the given mask. */ public static boolean validateMask( CheckResultSourceInterface source, String propertyName, int levelOnFail, List<CheckResultInterface> 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", CheckResultInterface.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 #27
Source File: NotBlankValidator.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public boolean validate( CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context ) { String value = ValidatorUtils.getValueAsString( source, propertyName ); if ( GenericValidator.isBlankOrNull( value ) ) { JobEntryValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) ); return false; } else { return true; } }
Example #28
Source File: ConfigurationSettingsValidator.java From development with Apache License 2.0 | 5 votes |
private static long parse(PlatformConfigurationKey key, String value, Long minValue, Long maxValue) { if (!GenericValidator.isLong(value)) { minValue = (minValue != null ? minValue : Long .valueOf(Long.MIN_VALUE)); maxValue = (maxValue != null ? maxValue : Long .valueOf(Long.MAX_VALUE)); throw new RuntimeException( "The value for" + key + " is illegal.Please enter a valid integer value within the range of " + minValue + " and " + maxValue + "."); } return Long.parseLong(value); }
Example #29
Source File: ValidateDate.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
public static boolean validate(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request, ServletContext application) { String valueString = ValidatorUtils.getValueAsString(bean, field.getProperty()); String sProperty2 = ValidatorUtils.getValueAsString(bean, field.getVarValue("month")); String sProperty3 = ValidatorUtils.getValueAsString(bean, field.getVarValue("day")); if (((valueString == null) && (sProperty2 == null) && (sProperty3 == null)) || ((valueString.length() == 0) && (sProperty2.length() == 0) && (sProperty3.length() == 0))) { // errors.add(field.getKey(),Resources.getActionError(request, va, // field)); return true; } Integer year = null; Integer month = null; Integer day = null; try { year = new Integer(valueString); month = new Integer(sProperty2); day = new Integer(sProperty3); } catch (NumberFormatException e) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); return false; } if (!GenericValidator.isBlankOrNull(valueString)) { if (!Data.validDate(day, month, year) || year == null || month == null || day == null || year.intValue() < 1 || month.intValue() < 0 || day.intValue() < 1) { errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); } return false; } return true; }
Example #30
Source File: EmailValidator.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public boolean validate( CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context ) { String value = null; value = ValidatorUtils.getValueAsString( source, propertyName ); if ( !GenericValidator.isBlankOrNull( value ) && !GenericValidator.isEmail( value ) ) { JobEntryValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) ); return false; } else { return true; } }