List of usage examples for org.apache.commons.validator.util ValidatorUtils getValueAsString
public static String getValueAsString(Object bean, String property)
String
. From source file:com.panet.imeta.job.entry.validator.FileExistsValidator.java
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; }/*w ww .j av a 2s . com*/ String realFileName = variableSpace.environmentSubstitute(filename); FileObject fileObject = null; try { fileObject = KettleVFS.getFileObject(realFileName); 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) { } } catch (Exception e) { JobEntryValidatorUtils.addExceptionRemark(source, propertyName, VALIDATOR_NAME, remarks, e); return false; } return true; }
From source file:com.panet.imeta.job.entry.validator.FileDoesNotExistValidator.java
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; }/*from www. j a v a 2s . co m*/ String realFileName = variableSpace.environmentSubstitute(filename); FileObject fileObject = null; try { fileObject = KettleVFS.getFileObject(realFileName); 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) { } } catch (Exception e) { JobEntryValidatorUtils.addExceptionRemark(source, propertyName, VALIDATOR_NAME, remarks, e); return false; } return true; }
From source file:com.core.validators.CommonValidator.java
/** * Checks if the field is required.//w w w. ja v a2 s. co m * * @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) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); return !GenericValidator.isBlankOrNull(value); }
From source file:net.sourceforge.fenixedu.presentationTier.validator.form.ValidateDate.java
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; }/*from ww w . j ava2 s . c o m*/ 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; }
From source file:com.core.validators.CommonValidator.java
/** * Checks if the field can be successfully converted to a <code>byte</code>. * * @param value The value validation is being performed on. * @return boolean If the field can be successfully converted * to a <code>byte</code> <code>true</code> is returned. * Otherwise <code>false</code>. *//*from www .j a va 2s.c om*/ public static boolean validateByte(Object bean, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); return GenericValidator.isByte(value); }
From source file:com.core.validators.CommonValidator.java
/** * Checks if the field can be successfully converted to a <code>short</code>. * * @param value The value validation is being performed on. * @return boolean If the field can be successfully converted * to a <code>short</code> <code>true</code> is returned. * Otherwise <code>false</code>. *//*from w ww . j av a 2 s . c o m*/ public static boolean validateShort(Object bean, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); return GenericValidator.isShort(value); }
From source file:com.sapienter.jbilling.server.user.validator.NoUserInfoInPasswordValidator.java
/** * Struts validator. This method retrieves the parameters necessary for * validating the password passed and calls basicValidation() to verify * the value. As such, it only represents a struts wrapper to * the core validation routine.// ww w . ja v a 2 s. c om * @return */ public static boolean validateNoUserInfo(Object bean, ValidatorAction va, Field field, ActionErrors errors, HttpServletRequest request, ServletContext application) { boolean retVal = true; try { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); if (!GenericValidator.isBlankOrNull(value)) { IUserSessionBean user = (IUserSessionBean) Context.getBean(Context.Name.USER_SESSION); ContactDTOEx dto = user.getPrimaryContactDTO( (Integer) request.getSession().getAttribute(Constants.SESSION_USER_ID)); if (dto != null) { retVal = basicValidation(dto, value); } } } catch (Exception e) { retVal = false; } if (retVal == false) { errors.add(field.getKey(), Resources.getActionError(request, va, field)); } return retVal; }
From source file:com.core.validators.CommonValidator.java
/** * Checks if the field can be successfully converted to a <code>int</code>. * * @param value The value validation is being performed on. * @return boolean If the field can be successfully converted * to a <code>int</code> <code>true</code> is returned. * Otherwise <code>false</code>. *///w w w . j ava 2 s . c o m public static boolean validateInt(Object bean, Field field) { String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); if (value == null || value.isEmpty()) { return true; } if (!GenericValidator.isInt(value)) { return false; } if (field.getVarValue("lt") != null) { int lt = Integer.parseInt(field.getVarValue("lt")); int old = Integer.parseInt(value); if (old < lt) { return false; } } return true; }
From source file:com.panet.imeta.job.entry.validator.JobEntryValidatorUtils.java
/** * Fails if a field's value does not match the given mask. *//* w w w . j a v a 2 s . c om*/ public static boolean validateMask(CheckResultSourceInterface source, String propertyName, int levelOnFail, List<CheckResultInterface> remarks, String mask) { final String VALIDATOR_NAME = "matches"; //$NON-NLS-1$ String value = null; value = ValidatorUtils.getValueAsString(source, propertyName); try { if (null == mask) { addGeneralRemark(source, propertyName, VALIDATOR_NAME, remarks, "errors.missingVar", //$NON-NLS-1$ 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; } }
From source file:com.sapienter.jbilling.server.user.validator.RepeatedPasswordValidator.java
/** * Struts validator that checks whether the password that is being set * by the user has been already used in the last two years. * @param bean/*from w w w . j ava2s . c o m*/ * @param va * @param field * @param errors * @param request * @param application * @return <code>true</code> if the validation passes and the password * has not been used, otherwise <code>false</code>. */ public static boolean validateRepeatedPassword(Object bean, ValidatorAction va, Field field, ActionErrors errors, HttpServletRequest request, ServletContext application) { boolean result = true; String value = ValidatorUtils.getValueAsString(bean, field.getProperty()); // Determine the id and role of the user changing his password Integer userId = (Integer) request.getSession().getAttribute(Constants.SESSION_USER_ID); Integer userRole = null; try { IUserSessionBean user = (IUserSessionBean) Context.getBean(Context.Name.USER_SESSION); userRole = user.getUserDTOEx(userId).getMainRoleId(); } catch (Exception e) { result = false; } // Perform the check in the event_log table to see if the user has // previously used the password he's trying to set now. if (result && !GenericValidator.isBlankOrNull(value)) { result = basicValidation(userId, userRole, value); } if (result == false) { errors.add(field.getKey(), Resources.getActionError(request, va, field)); } return result; }