org.apache.commons.validator.util.ValidatorUtils Java Examples
The following examples show how to use
org.apache.commons.validator.util.ValidatorUtils.
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: Field.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Replace the arg <code>Collection</code> key value with the key/value * pairs passed in. */ private void processArg(String key, String replaceValue) { for (int i = 0; i < this.args.length; i++) { Map<String, Arg> argMap = this.args[i]; if (argMap == null) { continue; } Iterator<Arg> iter = argMap.values().iterator(); while (iter.hasNext()) { Arg arg = iter.next(); if (arg != null) { arg.setKey( ValidatorUtils.replace(arg.getKey(), key, replaceValue)); } } } }
Example #2
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 #3
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 #4
Source File: ValidatorAction.java From lams with GNU General Public License v2.0 | 6 votes |
/** * Modifies the paramValue array with indexed fields. * * @param field * @param pos * @param paramValues */ private void handleIndexedField(Field field, int pos, Object[] paramValues) throws ValidatorException { int beanIndex = this.methodParameterList.indexOf(Validator.BEAN_PARAM); int fieldIndex = this.methodParameterList.indexOf(Validator.FIELD_PARAM); Object indexedList[] = field.getIndexedProperty(paramValues[beanIndex]); // Set current iteration object to the parameter array paramValues[beanIndex] = indexedList[pos]; // Set field clone with the key modified to represent // the current field Field indexedField = (Field) field.clone(); indexedField.setKey( ValidatorUtils.replace( indexedField.getKey(), Field.TOKEN_INDEXED, "[" + pos + "]")); paramValues[fieldIndex] = indexedField; }
Example #5
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 #6
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 #7
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 #8
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 #9
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 #10
Source File: Field.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Replace the args key value with the key/value pairs passed in. */ private void processMessageComponents(String key, String replaceValue) { String varKey = TOKEN_START + TOKEN_VAR; // Process Messages if (key != null && !key.startsWith(varKey)) { for (Iterator<Msg> i = getMsgMap().values().iterator(); i.hasNext();) { Msg msg = i.next(); msg.setKey(ValidatorUtils.replace(msg.getKey(), key, replaceValue)); } } this.processArg(key, replaceValue); }
Example #11
Source File: Field.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Creates and returns a copy of this object. * @return A copy of the Field. */ @Override public Object clone() { Field field = null; try { field = (Field) super.clone(); } catch(CloneNotSupportedException e) { throw new RuntimeException(e.toString()); } @SuppressWarnings("unchecked") // empty array always OK; cannot check this at compile time final Map<String, Arg>[] tempMap = new Map[this.args.length]; field.args = tempMap; for (int i = 0; i < this.args.length; i++) { if (this.args[i] == null) { continue; } Map<String, Arg> argMap = new HashMap<String, Arg>(this.args[i]); Iterator<Entry<String, Arg>> iter = argMap.entrySet().iterator(); while (iter.hasNext()) { Entry<String, Arg> entry = iter.next(); String validatorName = entry.getKey(); Arg arg = entry.getValue(); argMap.put(validatorName, (Arg) arg.clone()); } field.args[i] = argMap; } field.hVars = ValidatorUtils.copyFastHashMap(hVars); field.hMsgs = ValidatorUtils.copyFastHashMap(hMsgs); return field; }
Example #12
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 #13
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 #14
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 #15
Source File: GreaterThen.java From fenixedu-academic with GNU Lesser General Public License v3.0 | 5 votes |
public static boolean validateFloat0(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 #16
Source File: FileExistsValidator.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public boolean validate( CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context ) { String filename = ValidatorUtils.getValueAsString( source, propertyName ); VariableSpace variableSpace = getVariableSpace( source, propertyName, remarks, context ); boolean failIfDoesNotExist = getFailIfDoesNotExist( source, propertyName, remarks, context ); if ( null == variableSpace ) { return false; } String realFileName = variableSpace.environmentSubstitute( filename ); FileObject fileObject = null; try { fileObject = KettleVFS.getFileObject( realFileName, variableSpace ); if ( fileObject == null || ( fileObject != null && !fileObject.exists() && failIfDoesNotExist ) ) { JobEntryValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) ); return false; } try { fileObject.close(); // Just being paranoid } catch ( IOException ignored ) { // Ignore close errors } } catch ( Exception e ) { JobEntryValidatorUtils.addExceptionRemark( source, propertyName, VALIDATOR_NAME, remarks, e ); return false; } return true; }
Example #17
Source File: FileDoesNotExistValidator.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public boolean validate( CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks, ValidatorContext context ) { String filename = ValidatorUtils.getValueAsString( source, propertyName ); VariableSpace variableSpace = getVariableSpace( source, propertyName, remarks, context ); boolean failIfExists = getFailIfExists( source, propertyName, remarks, context ); if ( null == variableSpace ) { return false; } String realFileName = variableSpace.environmentSubstitute( filename ); FileObject fileObject = null; try { fileObject = KettleVFS.getFileObject( realFileName, variableSpace ); if ( fileObject.exists() && failIfExists ) { JobEntryValidatorUtils.addFailureRemark( source, propertyName, VALIDATOR_NAME, remarks, JobEntryValidatorUtils.getLevelOnFail( context, VALIDATOR_NAME ) ); return false; } try { fileObject.close(); // Just being paranoid } catch ( IOException ignored ) { // Ignore close errors } } catch ( Exception e ) { JobEntryValidatorUtils.addExceptionRemark( source, propertyName, VALIDATOR_NAME, remarks, e ); return false; } return true; }
Example #18
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 #19
Source File: JobEntryValidatorUtils.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public static void addOkRemark( CheckResultSourceInterface source, String propertyName, List<CheckResultInterface> remarks ) { final int SUBSTRING_LENGTH = 20; String value = ValidatorUtils.getValueAsString( source, propertyName ); String substr = null; if ( value != null ) { substr = value.substring( 0, Math.min( SUBSTRING_LENGTH, value.length() ) ); if ( value.length() > SUBSTRING_LENGTH ) { substr += "..."; } } remarks.add( new CheckResult( CheckResultInterface.TYPE_RESULT_OK, ValidatorMessages.getString( "messages.passed", propertyName, substr ), source ) ); }
Example #20
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 #21
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; } }
Example #22
Source File: MailingModelChecks.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
public static boolean validateTargetMode(Object bean, Field field, ValidatorResults results, ValidatorAction action) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); boolean valid = MailingModel.targetModeMap.containsKey(value.toLowerCase()); results.add(field, action.getName(), valid, value); return valid; }
Example #23
Source File: GenericModelChecks.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
/** * 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 #24
Source File: GenericModelChecks.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
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 #25
Source File: GenericModelChecks.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
/** * 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 #26
Source File: GenericModelChecks.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
/** * Checks if the field value is in email format. * * @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 validateEmail(Object bean, Field field, ValidatorResults results, ValidatorAction action) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); if (value == null) { return true; } boolean valid = AgnitasEmailValidator.getInstance().isValid(value); results.add(field, action.getName(), valid, value); return valid; }
Example #27
Source File: GenericModelChecks.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
/** * Checks if the field value is in email format or if it is null * * @return if the field is null or has a valid email format - true is returned (false otherwise) */ public static boolean validateEmailOrNull(Object bean, Field field, ValidatorResults results, ValidatorAction action) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); boolean valid = value == null || AgnitasEmailValidator.getInstance().isValid(value); results.add(field, action.getName(), valid, value); return valid; }
Example #28
Source File: GenericModelChecks.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
/** * 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; }
Example #29
Source File: MailingModelChecks.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
public static boolean validateMailingType(Object bean, Field field, ValidatorResults results, ValidatorAction action) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); boolean valid = MailingModel.mailingTypeMap.containsKey(value.toLowerCase()); results.add(field, action.getName(), valid, value); return valid; }
Example #30
Source File: MailingModelChecks.java From openemm with GNU Affero General Public License v3.0 | 5 votes |
public static boolean validateMailingFormat(Object bean, Field field, ValidatorResults results, ValidatorAction action) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); boolean valid = MailingModel.formatMap.containsKey(value.toLowerCase()); results.add(field, action.getName(), valid, value); return valid; }