husted 2004/02/20 08:16:05 Modified: src/share/org/apache/struts/validator FieldChecks.java Log: Apply #26413 "Indexed Field Date Validation Allows Invalid Dates" submitted by Niall Pemberton. Revision Changes Path 1.17 +93 -76 jakarta-struts/src/share/org/apache/struts/validator/FieldChecks.java Index: FieldChecks.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/validator/FieldChecks.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- FieldChecks.java 10 Jan 2004 21:03:38 -0000 1.16 +++ FieldChecks.java 20 Feb 2004 16:16:05 -0000 1.17 @@ -296,9 +296,9 @@ [EMAIL PROTECTED] errors The <code>ActionMessages</code> object to add errors to if *any validation errors occur. [EMAIL PROTECTED] request Current request object. - [EMAIL PROTECTED] A Byte if valid, null otherwise. + [EMAIL PROTECTED] true if valid, false otherwise. */ - public static Byte validateByte(Object bean, + public static boolean validateByte(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) { @@ -311,15 +311,17 @@ value = ValidatorUtils.getValueAsString(bean, field.getProperty()); } - if (!GenericValidator.isBlankOrNull(value)) { - result = GenericTypeValidator.formatByte(value); + if (GenericValidator.isBlankOrNull(value)) { + return true; + } - if (result == null) { - errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); - } + result = GenericTypeValidator.formatByte(value); + + if (result == null) { + errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); } - return result; + return result == null ? false : true; } @@ -333,9 +335,9 @@ * @param errors The <code>ActionMessages</code> object to add errors to if * any validation errors occur. * @param request Current request object. - * @return A Short if valid, otherwise null. + * @return true if valid, false otherwise. */ - public static Short validateShort(Object bean, + public static boolean validateShort(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) { @@ -347,15 +349,17 @@ value = ValidatorUtils.getValueAsString(bean, field.getProperty()); } - if (!GenericValidator.isBlankOrNull(value)) { - result = GenericTypeValidator.formatShort(value); + if (GenericValidator.isBlankOrNull(value)) { + return true; + } - if (result == null) { - errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); - } + result = GenericTypeValidator.formatShort(value); + + if (result == null) { + errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); } - return result; + return result == null ? false : true; } @@ -369,9 +373,9 @@ * @param errors The <code>ActionMessages</code> object to add errors to if any * validation errors occur. * @param request Current request object. - * @return An Integer if valid, a null otherwise. + * @return true if valid, false otherwise. */ - public static Integer validateInteger(Object bean, + public static boolean validateInteger(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) { @@ -383,15 +387,17 @@ value = ValidatorUtils.getValueAsString(bean, field.getProperty()); } - if (!GenericValidator.isBlankOrNull(value)) { - result = GenericTypeValidator.formatInt(value); + if (GenericValidator.isBlankOrNull(value)) { + return true; + } - if (result == null) { - errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); - } + result = GenericTypeValidator.formatInt(value); + + if (result == null) { + errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); } - return result; + return result == null ? false : true; } @@ -405,9 +411,9 @@ * @param errors The <code>ActionMessages</code> object to add errors to if any * validation errors occur. * @param request Current request object. - * @return A Long if valid, a null otherwise. + * @return true if valid, false otherwise. */ - public static Long validateLong(Object bean, + public static boolean validateLong(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) { @@ -419,15 +425,17 @@ value = ValidatorUtils.getValueAsString(bean, field.getProperty()); } - if (!GenericValidator.isBlankOrNull(value)) { - result = GenericTypeValidator.formatLong(value); + if (GenericValidator.isBlankOrNull(value)) { + return true; + } - if (result == null) { - errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); - } + result = GenericTypeValidator.formatLong(value); + + if (result == null) { + errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); } - return result; + return result == null ? false : true; } @@ -441,9 +449,9 @@ * @param errors The <code>ActionMessages</code> object to add errors to if any * validation errors occur. * @param request Current request object. - * @return A Float if valid, a null otherwise. + * @return true if valid, false otherwise. */ - public static Float validateFloat(Object bean, + public static boolean validateFloat(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) { @@ -455,15 +463,17 @@ value = ValidatorUtils.getValueAsString(bean, field.getProperty()); } - if (!GenericValidator.isBlankOrNull(value)) { - result = GenericTypeValidator.formatFloat(value); + if (GenericValidator.isBlankOrNull(value)) { + return true; + } - if (result == null) { - errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); - } + result = GenericTypeValidator.formatFloat(value); + + if (result == null) { + errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); } - return result; + return result == null ? false : true; } @@ -477,9 +487,9 @@ * @param errors The <code>ActionMessages</code> object to add errors to if any * validation errors occur. * @param request Current request object. - * @return A Double if valid, a null otherwise. + * @return true if valid, false otherwise. */ - public static Double validateDouble(Object bean, + public static boolean validateDouble(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) { @@ -491,15 +501,17 @@ value = ValidatorUtils.getValueAsString(bean, field.getProperty()); } - if (!GenericValidator.isBlankOrNull(value)) { - result = GenericTypeValidator.formatDouble(value); + if (GenericValidator.isBlankOrNull(value)) { + return true; + } - if (result == null) { - errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); - } + result = GenericTypeValidator.formatDouble(value); + + if (result == null) { + errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); } - return result; + return result == null ? false : true; } @@ -519,9 +531,9 @@ * @param errors The <code>ActionMessages</code> object to add errors to if any * validation errors occur. * @param request Current request object. - * @return A Date if valid, a null if blank or invalid. + * @return true if valid, false otherwise. */ - public static Date validateDate(Object bean, + public static boolean validateDate(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) { @@ -537,25 +549,27 @@ String datePatternStrict = field.getVarValue("datePatternStrict"); Locale locale = RequestUtils.getUserLocale(request, null); - if (!GenericValidator.isBlankOrNull(value)) { - try { - if (datePattern != null && datePattern.length() > 0) { - result = GenericTypeValidator.formatDate(value, datePattern, false); - } else if (datePatternStrict != null && datePatternStrict.length() > 0) { - result = GenericTypeValidator.formatDate(value, datePatternStrict, true); - } else { - result = GenericTypeValidator.formatDate(value, locale); - } - } catch (Exception e) { - log.error(e.getMessage(), e); - } + if (GenericValidator.isBlankOrNull(value)) { + return true; + } - if (result == null) { - errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); + try { + if (datePattern != null && datePattern.length() > 0) { + result = GenericTypeValidator.formatDate(value, datePattern, false); + } else if (datePatternStrict != null && datePatternStrict.length() > 0) { + result = GenericTypeValidator.formatDate(value, datePatternStrict, true); + } else { + result = GenericTypeValidator.formatDate(value, locale); } + } catch (Exception e) { + log.error(e.getMessage(), e); } - return result; + if (result == null) { + errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); + } + + return result == null ? false : true; } /** @@ -704,9 +718,9 @@ * @param errors The <code>ActionMessages</code> object to add errors to if any * validation errors occur. * @param request Current request object. - * @return The credit card as a Long, a null if invalid, blank, or null. + * @return true if valid, false otherwise. */ - public static Long validateCreditCard(Object bean, + public static boolean validateCreditCard(Object bean, ValidatorAction va, Field field, ActionMessages errors, HttpServletRequest request) { @@ -719,15 +733,17 @@ value = ValidatorUtils.getValueAsString(bean, field.getProperty()); } - if (!GenericValidator.isBlankOrNull(value)) { - result = GenericTypeValidator.formatCreditCard(value); + if (GenericValidator.isBlankOrNull(value)) { + return true; + } - if (result == null) { - errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); - } + result = GenericTypeValidator.formatCreditCard(value); + + if (result == null) { + errors.add(field.getKey(), Resources.getActionMessage(request, va, field)); } - return result; + return result == null ? false : true; } @@ -895,3 +911,4 @@ } } +
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]