You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2002/06/25 20:27:52 UTC
cvs commit: jakarta-struts/src/share/org/apache/struts/util StrutsValidatorUtil.java StrutsValidator.java
husted 2002/06/25 11:27:52
Modified: src/share/org/apache/struts/util StrutsValidatorUtil.java
StrutsValidator.java
Log:
JavaDoc updates for 1.1.
Revision Changes Path
1.3 +46 -46 jakarta-struts/src/share/org/apache/struts/util/StrutsValidatorUtil.java
Index: StrutsValidatorUtil.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/StrutsValidatorUtil.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StrutsValidatorUtil.java 2 Apr 2002 04:08:32 -0000 1.2
+++ StrutsValidatorUtil.java 25 Jun 2002 18:27:52 -0000 1.3
@@ -57,8 +57,8 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
-
-
+
+
package org.apache.struts.util;
import java.util.Locale;
@@ -79,12 +79,12 @@
/**
- * <p>This class helps provides some useful methods for retrieving objects
+ * <p>This class helps provides some useful methods for retrieving objects
* from different scopes of the application.</p>
*
* @author David Winterfeldt
* @version $Revision$ $Date$
- * @since 1.1
+ * @since Struts 1.1
*/
public class StrutsValidatorUtil {
@@ -102,7 +102,7 @@
* Resources key the <code>ActionErrors</code> is stored under.
*/
public static String ACTION_ERRORS_KEY = "org.apache.struts.action.ActionErrors";
-
+
private static Locale defaultLocale = Locale.getDefault();
/**
@@ -137,29 +137,29 @@
Locale locale = null;
try {
locale = (Locale) request.getSession().getAttribute(Action.LOCALE_KEY);
- } catch (IllegalStateException e) { // Invalidated session
+ } catch (IllegalStateException e) { // Invalidated session
locale = null;
}
if (locale == null) {
locale = defaultLocale;
}
-
+
return locale;
}
-
+
/**
* Gets the <code>Locale</code> sensitive value based on the key passed in.
*/
public static String getMessage(MessageResources messages, Locale locale, String key) {
- String message = null;
-
+ String message = null;
+
if (messages != null) {
message = messages.getMessage(locale, key);
}
if (message == null) {
message = "";
}
-
+
return message;
}
@@ -168,53 +168,53 @@
*/
public static String getMessage(HttpServletRequest request, String key) {
MessageResources messages = getMessageResources(request);
-
+
return getMessage(messages, getLocale(request), key);
}
/**
- * Gets the locale sensitive message based on the <code>ValidatorAction</code> message and the
+ * Gets the locale sensitive message based on the <code>ValidatorAction</code> message and the
* <code>Field</code>'s arg objects.
*/
- public static String getMessage(MessageResources messages, Locale locale,
+ public static String getMessage(MessageResources messages, Locale locale,
ValidatorAction va, Field field) {
String arg[] = getArgs(va.getName(), messages, locale, field);
String msg = (field.getMsg(va.getName()) != null ? field.getMsg(va.getName()) : va.getMsg());
-
+
return messages.getMessage(locale, msg, arg[0], arg[1], arg[2], arg[3]);
}
/**
- * Gets the <code>ActionError</code> based on the <code>ValidatorAction</code> message and the
+ * Gets the <code>ActionError</code> based on the <code>ValidatorAction</code> message and the
* <code>Field</code>'s arg objects.
*/
- public static ActionError getActionError(HttpServletRequest request,
+ public static ActionError getActionError(HttpServletRequest request,
ValidatorAction va, Field field) {
String arg[] = getArgs(va.getName(), getMessageResources(request), getLocale(request), field);
String msg = (field.getMsg(va.getName()) != null ? field.getMsg(va.getName()) : va.getMsg());
-
+
return new ActionError(msg, arg[0], arg[1], arg[2], arg[3]);
}
/**
- * Gets the message arguments based on the current <code>ValidatorAction</code>
+ * Gets the message arguments based on the current <code>ValidatorAction</code>
* and <code>Field</code>.
*/
- public static String[] getArgs(String actionName, MessageResources messages,
+ public static String[] getArgs(String actionName, MessageResources messages,
Locale locale, Field field) {
-
+
Arg arg0 = field.getArg0(actionName);
Arg arg1 = field.getArg1(actionName);
Arg arg2 = field.getArg2(actionName);
Arg arg3 = field.getArg3(actionName);
-
+
String sArg0 = null;
String sArg1 = null;
String sArg2 = null;
String sArg3 = null;
-
+
if (arg0 != null) {
if (arg0.getResource()) {
sArg0 = getMessage(messages, locale, arg0.getKey());
@@ -222,7 +222,7 @@
sArg0 = arg0.getKey();
}
}
-
+
if (arg1 != null) {
if (arg1.getResource()) {
sArg1 = getMessage(messages, locale, arg1.getKey());
@@ -230,7 +230,7 @@
sArg1 = arg1.getKey();
}
}
-
+
if (arg2 != null) {
if (arg2.getResource()) {
sArg2 = getMessage(messages, locale, arg2.getKey());
@@ -238,19 +238,19 @@
sArg2 = arg2.getKey();
}
}
-
+
if (arg3 != null) {
if (arg3.getResource()) {
sArg3 = getMessage(messages, locale, arg3.getKey());
} else {
sArg3 = arg3.getKey();
}
- }
-
+ }
+
return new String[] { sArg0, sArg1, sArg2, sArg3 };
-
+
}
-
+
/**
* Writes a message based on the <code>Writer</code> defined in <code>MessageResources</code>.
*
@@ -259,7 +259,7 @@
*/
public static void log(ServletContext application, String message) {
MessageResources messages = getMessageResources(application);
-
+
if (messages != null) {
messages.log(message);
}
@@ -273,7 +273,7 @@
*/
public static void log(ServletContext application, String message, Throwable t) {
MessageResources messages = getMessageResources(application);
-
+
if (messages != null) {
messages.log(message, t);
}
@@ -282,30 +282,30 @@
/**
* Initialize the <code>Validator</code> to perform validation.
*
- * @param key The key that the validation rules are under
- * (the form elements name attribute).
- * @param request The current request object.
- * @param errors The object any errors will be stored in.
+ * @param key The key that the validation rules are under
+ * (the form elements name attribute).
+ * @param request The current request object.
+ * @param errors The object any errors will be stored in.
*/
public static Validator initValidator(String key, Object bean,
- ServletContext application, HttpServletRequest request,
+ ServletContext application, HttpServletRequest request,
ActionErrors errors, int page) {
ValidatorResources resources = StrutsValidatorUtil.getValidatorResources(application);
Locale locale = StrutsValidatorUtil.getLocale(request);
-
+
Validator validator = new Validator(resources, key);
validator.setUseContextClassLoader(true);
-
+
validator.setPage(page);
-
+
validator.addResource(SERVLET_CONTEXT_KEY, application);
validator.addResource(HTTP_SERVLET_REQUEST_KEY, request);
validator.addResource(Validator.LOCALE_KEY, locale);
validator.addResource(ACTION_ERRORS_KEY, errors);
validator.addResource(Validator.BEAN_KEY, bean);
-
- return validator;
+
+ return validator;
}
-
+
}
1.3 +241 -241 jakarta-struts/src/share/org/apache/struts/util/StrutsValidator.java
Index: StrutsValidator.java
===================================================================
RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/util/StrutsValidator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- StrutsValidator.java 2 Apr 2002 04:06:21 -0000 1.2
+++ StrutsValidator.java 25 Jun 2002 18:27:52 -0000 1.3
@@ -51,8 +51,8 @@
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
-
-
+
+
package org.apache.struts.util;
import java.io.Serializable;
@@ -71,11 +71,11 @@
/**
- * <p>This class contains the default validations
+ * <p>This class contains the default validations
* that are used in the validator-rules.xml file.</p>
*
- * @since 1.1
* @author David Winterfeldt
+ * @since Struts 1.1
*/
public class StrutsValidator implements Serializable {
@@ -83,320 +83,320 @@
* Commons Logging instance.
*/
private static Log LOG = LogSource.getInstance(StrutsValidator.class.getName());
-
+
/**
- * <p>Checks if the field isn't null and length of the field is greater than zero not
+ * <p>Checks if the field isn't null and length of the field is greater than zero not
* including whitespace.</p>
*
- * @param bean The bean validation is being performed on.
- * @param va The <code>ValidatorAction</code> that is currently being performed.
- * @param field The <code>Field</code> object associated with the current field
- * being validated.
- * @param errors The <code>ActionErrors</code> object to add errors to if any
- * validation errors occur.
- * @param request Current request object.
- */
- public static boolean validateRequired(Object bean,
- ValidatorAction va, Field field,
- ActionErrors errors,
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being performed.
+ * @param field The <code>Field</code> object associated with the current field
+ * being validated.
+ * @param errors The <code>ActionErrors</code> object to add errors to if any
+ * validation errors occur.
+ * @param request Current request object.
+ */
+ public static boolean validateRequired(Object bean,
+ ValidatorAction va, Field field,
+ ActionErrors errors,
HttpServletRequest request) {
String value = null;
if (field.getProperty() != null && field.getProperty().length() > 0)
- value = ValidatorUtil.getValueAsString(bean, field.getProperty());
+ value = ValidatorUtil.getValueAsString(bean, field.getProperty());
if (GenericValidator.isBlankOrNull(value)) {
errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
return false;
} else {
- return true;
+ return true;
}
}
/**
* <p>Checks if the field matches the regular expression in the field's mask attribute.</p>
*
- * @param bean The bean validation is being performed on.
- * @param va The <code>ValidatorAction</code> that is currently being performed.
- * @param field The <code>Field</code> object associated with the current field
- * being validated.
- * @param errors The <code>ActionErrors</code> object to add errors to if any
- * validation errors occur.
- * @param request Current request object.
- */
- public static boolean validateMask(Object bean,
- ValidatorAction va, Field field,
- ActionErrors errors,
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being performed.
+ * @param field The <code>Field</code> object associated with the current field
+ * being validated.
+ * @param errors The <code>ActionErrors</code> object to add errors to if any
+ * validation errors occur.
+ * @param request Current request object.
+ */
+ public static boolean validateMask(Object bean,
+ ValidatorAction va, Field field,
+ ActionErrors errors,
HttpServletRequest request) {
-
+
String mask = field.getVarValue("mask");
-
- if (field.getProperty() != null && field.getProperty().length() > 0) {
- String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
-
+
+ if (field.getProperty() != null && field.getProperty().length() > 0) {
+ String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
+
try {
- if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.matchRegexp(value, mask)) {
- errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
-
+ if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.matchRegexp(value, mask)) {
+ errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
+
return false;
} else {
- return true;
+ return true;
}
- } catch (Exception e) {
- LOG.error(e.getMessage(), e);
- }
+ } catch (Exception e) {
+ LOG.error(e.getMessage(), e);
+ }
}
-
+
return true;
- }
-
+ }
+
/**
* <p>Checks if the field can safely be converted to a byte primitive.</p>
*
- * @param bean The bean validation is being performed on.
- * @param va The <code>ValidatorAction</code> that is currently being performed.
- * @param field The <code>Field</code> object associated with the current field
- * being validated.
- * @param errors The <code>ActionErrors</code> object to add errors to if any
- * validation errors occur.
- * @param request Current request object.
- */
- public static Byte validateByte(Object bean,
- ValidatorAction va, Field field,
- ActionErrors errors,
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being performed.
+ * @param field The <code>Field</code> object associated with the current field
+ * being validated.
+ * @param errors The <code>ActionErrors</code> object to add errors to if any
+ * validation errors occur.
+ * @param request Current request object.
+ */
+ public static Byte validateByte(Object bean,
+ ValidatorAction va, Field field,
+ ActionErrors errors,
HttpServletRequest request) {
-
+
Byte result = null;
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
if (!GenericValidator.isBlankOrNull(value)) {
- result = GenericTypeValidator.formatByte(value);
-
- if (result == null) {
+ result = GenericTypeValidator.formatByte(value);
+
+ if (result == null) {
errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
}
}
-
+
return result;
}
/**
* <p>Checks if the field can safely be converted to a short primitive.</p>
*
- * @param bean The bean validation is being performed on.
- * @param va The <code>ValidatorAction</code> that is currently being performed.
- * @param field The <code>Field</code> object associated with the current field
- * being validated.
- * @param errors The <code>ActionErrors</code> object to add errors to if any
- * validation errors occur.
- * @param request Current request object.
- */
- public static Short validateShort(Object bean,
- ValidatorAction va, Field field,
- ActionErrors errors,
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being performed.
+ * @param field The <code>Field</code> object associated with the current field
+ * being validated.
+ * @param errors The <code>ActionErrors</code> object to add errors to if any
+ * validation errors occur.
+ * @param request Current request object.
+ */
+ public static Short validateShort(Object bean,
+ ValidatorAction va, Field field,
+ ActionErrors errors,
HttpServletRequest request) {
Short result = null;
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
-
+
if (!GenericValidator.isBlankOrNull(value)) {
- result = GenericTypeValidator.formatShort(value);
-
- if (result == null) {
+ result = GenericTypeValidator.formatShort(value);
+
+ if (result == null) {
errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
}
}
-
+
return result;
}
/**
* <p>Checks if the field can safely be converted to an int primitive.</p>
*
- * @param bean The bean validation is being performed on.
- * @param va The <code>ValidatorAction</code> that is currently being performed.
- * @param field The <code>Field</code> object associated with the current field
- * being validated.
- * @param errors The <code>ActionErrors</code> object to add errors to if any
- * validation errors occur.
- * @param request Current request object.
- */
- public static Integer validateInteger(Object bean,
- ValidatorAction va, Field field,
- ActionErrors errors,
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being performed.
+ * @param field The <code>Field</code> object associated with the current field
+ * being validated.
+ * @param errors The <code>ActionErrors</code> object to add errors to if any
+ * validation errors occur.
+ * @param request Current request object.
+ */
+ public static Integer validateInteger(Object bean,
+ ValidatorAction va, Field field,
+ ActionErrors errors,
HttpServletRequest request) {
Integer result = null;
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
-
+
if (!GenericValidator.isBlankOrNull(value)) {
- result = GenericTypeValidator.formatInt(value);
-
- if (result == null) {
+ result = GenericTypeValidator.formatInt(value);
+
+ if (result == null) {
errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
}
}
-
+
return result;
}
/**
* <p>Checks if the field can safely be converted to a long primitive.</p>
*
- * @param bean The bean validation is being performed on.
- * @param va The <code>ValidatorAction</code> that is currently being performed.
- * @param field The <code>Field</code> object associated with the current field
- * being validated.
- * @param errors The <code>ActionErrors</code> object to add errors to if any
- * validation errors occur.
- * @param request Current request object.
- */
- public static Long validateLong(Object bean,
- ValidatorAction va, Field field,
- ActionErrors errors,
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being performed.
+ * @param field The <code>Field</code> object associated with the current field
+ * being validated.
+ * @param errors The <code>ActionErrors</code> object to add errors to if any
+ * validation errors occur.
+ * @param request Current request object.
+ */
+ public static Long validateLong(Object bean,
+ ValidatorAction va, Field field,
+ ActionErrors errors,
HttpServletRequest request) {
Long result = null;
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
-
+
if (!GenericValidator.isBlankOrNull(value)) {
- result = GenericTypeValidator.formatLong(value);
-
- if (result == null) {
+ result = GenericTypeValidator.formatLong(value);
+
+ if (result == null) {
errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
}
}
-
+
return result;
}
/**
* <p>Checks if the field can safely be converted to a float primitive.</p>
*
- * @param bean The bean validation is being performed on.
- * @param va The <code>ValidatorAction</code> that is currently being performed.
- * @param field The <code>Field</code> object associated with the current field
- * being validated.
- * @param errors The <code>ActionErrors</code> object to add errors to if any
- * validation errors occur.
- * @param request Current request object.
- */
- public static Float validateFloat(Object bean,
- ValidatorAction va, Field field,
- ActionErrors errors,
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being performed.
+ * @param field The <code>Field</code> object associated with the current field
+ * being validated.
+ * @param errors The <code>ActionErrors</code> object to add errors to if any
+ * validation errors occur.
+ * @param request Current request object.
+ */
+ public static Float validateFloat(Object bean,
+ ValidatorAction va, Field field,
+ ActionErrors errors,
HttpServletRequest request) {
Float result = null;
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
-
+
if (!GenericValidator.isBlankOrNull(value)) {
result = GenericTypeValidator.formatFloat(value);
-
- if (result == null) {
+
+ if (result == null) {
errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
}
}
-
+
return result;
}
/**
* <p>Checks if the field can safely be converted to a double primitive.</p>
*
- * @param bean The bean validation is being performed on.
- * @param va The <code>ValidatorAction</code> that is currently being performed.
- * @param field The <code>Field</code> object associated with the current field
- * being validated.
- * @param errors The <code>ActionErrors</code> object to add errors to if any
- * validation errors occur.
- * @param request Current request object.
- */
- public static Double validateDouble(Object bean,
- ValidatorAction va, Field field,
- ActionErrors errors,
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being performed.
+ * @param field The <code>Field</code> object associated with the current field
+ * being validated.
+ * @param errors The <code>ActionErrors</code> object to add errors to if any
+ * validation errors occur.
+ * @param request Current request object.
+ */
+ public static Double validateDouble(Object bean,
+ ValidatorAction va, Field field,
+ ActionErrors errors,
HttpServletRequest request) {
Double result = null;
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
-
+
if (!GenericValidator.isBlankOrNull(value)) {
- result = GenericTypeValidator.formatDouble(value);
-
- if (result == null) {
+ result = GenericTypeValidator.formatDouble(value);
+
+ if (result == null) {
errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
}
}
-
+
return result;
}
/**
- * <p>Checks if the field is a valid date. If the field has a datePattern variable,
- * that will be used to format <code>java.text.SimpleDateFormat</code>. If the field
- * has a datePatternStrict variable, that will be used to format
- * <code>java.text.SimpleDateFormat</code> and the length will be checked so '2/12/1999'
+ * <p>Checks if the field is a valid date. If the field has a datePattern variable,
+ * that will be used to format <code>java.text.SimpleDateFormat</code>. If the field
+ * has a datePatternStrict variable, that will be used to format
+ * <code>java.text.SimpleDateFormat</code> and the length will be checked so '2/12/1999'
* will not pass validation with the format 'MM/dd/yyyy' because the month isn't two digits.
- * If no datePattern variable is specified, then the field gets the DateFormat.SHORT
- * format for the locale. The setLenient method is set to <code>false</code> for all
+ * If no datePattern variable is specified, then the field gets the DateFormat.SHORT
+ * format for the locale. The setLenient method is set to <code>false</code> for all
* variations.</p>
*
- * @param bean The bean validation is being performed on.
- * @param va The <code>ValidatorAction</code> that is currently being performed.
- * @param field The <code>Field</code> object associated with the current field
- * being validated.
- * @param errors The <code>ActionErrors</code> object to add errors to if any
- * validation errors occur.
- * @param request Current request object.
- */
- public static Date validateDate(Object bean,
- ValidatorAction va, Field field,
- ActionErrors errors,
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being performed.
+ * @param field The <code>Field</code> object associated with the current field
+ * being validated.
+ * @param errors The <code>ActionErrors</code> object to add errors to if any
+ * validation errors occur.
+ * @param request Current request object.
+ */
+ public static Date validateDate(Object bean,
+ ValidatorAction va, Field field,
+ ActionErrors errors,
HttpServletRequest request) {
- Date result = null;
+ Date result = null;
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
String datePattern = field.getVarValue("datePattern");
String datePatternStrict = field.getVarValue("datePatternStrict");
Locale locale = StrutsValidatorUtil.getLocale(request);
- if (!GenericValidator.isBlankOrNull(value)) {
- try {
+ 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);
+ } else {
+ result = GenericTypeValidator.formatDate(value, locale);
}
- } catch (Exception e) {
- LOG.error(e.getMessage(), e);
+ } catch (Exception e) {
+ LOG.error(e.getMessage(), e);
}
}
if (result == null) {
errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
}
-
+
return result;
- }
+ }
/**
- * <p>Checks if a fields value is within a range (min & max specified
+ * <p>Checks if a fields value is within a range (min & max specified
* in the vars attribute).</p>
*
- * @param bean The bean validation is being performed on.
- * @param va The <code>ValidatorAction</code> that is currently being performed.
- * @param field The <code>Field</code> object associated with the current field
- * being validated.
- * @param errors The <code>ActionErrors</code> object to add errors to if any
- * validation errors occur.
- * @param request Current request object.
- */
- public static boolean validateRange(Object bean,
- ValidatorAction va, Field field,
- ActionErrors errors,
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being performed.
+ * @param field The <code>Field</code> object associated with the current field
+ * being validated.
+ * @param errors The <code>ActionErrors</code> object to add errors to if any
+ * validation errors occur.
+ * @param request Current request object.
+ */
+ public static boolean validateRange(Object bean,
+ ValidatorAction va, Field field,
+ ActionErrors errors,
HttpServletRequest request) {
-
+
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
String sMin = field.getVarValue("min");
String sMax = field.getVarValue("max");
@@ -406,10 +406,10 @@
int iValue = Integer.parseInt(value);
int min = Integer.parseInt(sMin);
int max = Integer.parseInt(sMax);
-
+
if (!GenericValidator.isInRange(iValue, min, max)) {
errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
-
+
return false;
}
} catch (Exception e) {
@@ -417,7 +417,7 @@
return false;
}
}
-
+
return true;
}
@@ -426,25 +426,25 @@
* <p>Translated to Java by Ted Husted (<a href="mailto:husted@apache.org">husted@apache.org</a>).<br>
* Reference Sean M. Burke's script at http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl</p>
*
- * @param bean The bean validation is being performed on.
- * @param va The <code>ValidatorAction</code> that is currently being performed.
- * @param field The <code>Field</code> object associated with the current field
- * being validated.
- * @param errors The <code>ActionErrors</code> object to add errors to if any
- * validation errors occur.
- * @param request Current request object.
- */
- public static Long validateCreditCard(Object bean,
- ValidatorAction va, Field field,
- ActionErrors errors,
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being performed.
+ * @param field The <code>Field</code> object associated with the current field
+ * being validated.
+ * @param errors The <code>ActionErrors</code> object to add errors to if any
+ * validation errors occur.
+ * @param request Current request object.
+ */
+ public static Long validateCreditCard(Object bean,
+ ValidatorAction va, Field field,
+ ActionErrors errors,
HttpServletRequest request) {
-
+
Long result = null;
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
-
+
if (!GenericValidator.isBlankOrNull(value)) {
result = GenericTypeValidator.formatCreditCard(value);
-
+
if (result == null) {
errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
}
@@ -455,47 +455,47 @@
/**
* <p>Checks if a field has a valid e-mail address.</p>
- * <p>Based on a script by Sandeep V. Tamhankar (stamhankar@hotmail.com),
+ * <p>Based on a script by Sandeep V. Tamhankar (stamhankar@hotmail.com),
* http://javascript.internet.com</p>
*
- * @param bean The bean validation is being performed on.
- * @param va The <code>ValidatorAction</code> that is currently being performed.
- * @param field The <code>Field</code> object associated with the current field
- * being validated.
- * @param errors The <code>ActionErrors</code> object to add errors to if any
- * validation errors occur.
- * @param request Current request object.
- */
- public static boolean validateEmail(Object bean,
- ValidatorAction va, Field field,
- ActionErrors errors,
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being performed.
+ * @param field The <code>Field</code> object associated with the current field
+ * being validated.
+ * @param errors The <code>ActionErrors</code> object to add errors to if any
+ * validation errors occur.
+ * @param request Current request object.
+ */
+ public static boolean validateEmail(Object bean,
+ ValidatorAction va, Field field,
+ ActionErrors errors,
HttpServletRequest request) {
-
+
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
-
+
if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.isEmail(value)) {
errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
return false;
} else {
- return true;
+ return true;
}
}
/**
- * <p>Checks if the field's length is less than or equal to the maximum value. A <code>Null</code>
+ * <p>Checks if the field's length is less than or equal to the maximum value. A <code>Null</code>
* will be considered an error.</p>
*
- * @param bean The bean validation is being performed on.
- * @param va The <code>ValidatorAction</code> that is currently being performed.
- * @param field The <code>Field</code> object associated with the current field
- * being validated.
- * @param errors The <code>ActionErrors</code> object to add errors to if any
- * validation errors occur.
- * @param request Current request object.
- */
- public static boolean validateMaxLength(Object bean,
- ValidatorAction va, Field field,
- ActionErrors errors,
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being performed.
+ * @param field The <code>Field</code> object associated with the current field
+ * being validated.
+ * @param errors The <code>ActionErrors</code> object to add errors to if any
+ * validation errors occur.
+ * @param request Current request object.
+ */
+ public static boolean validateMaxLength(Object bean,
+ ValidatorAction va, Field field,
+ ActionErrors errors,
HttpServletRequest request) {
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
@@ -504,10 +504,10 @@
if (value != null) {
try {
int max = Integer.parseInt(sMaxLength);
-
+
if (!GenericValidator.maxLength(value, max)) {
errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
-
+
return false;
}
} catch (Exception e) {
@@ -515,26 +515,26 @@
return false;
}
}
-
+
return true;
}
/**
- * <p>Checks if the field's length is greater than or equal to the minimum value.
+ * <p>Checks if the field's length is greater than or equal to the minimum value.
* A <code>Null</code> will be considered an error.</p>
*
- * @param bean The bean validation is being performed on.
- * @param va The <code>ValidatorAction</code> that is currently being performed.
- * @param field The <code>Field</code> object associated with the current field
- * being validated.
- * @param errors The <code>ActionErrors</code> object to add errors to if any
- * validation errors occur.
- * @param request Current request object.
- */
- public static boolean validateMinLength(Object bean,
- ValidatorAction va, Field field,
- ActionErrors errors,
+ * @param bean The bean validation is being performed on.
+ * @param va The <code>ValidatorAction</code> that is currently being performed.
+ * @param field The <code>Field</code> object associated with the current field
+ * being validated.
+ * @param errors The <code>ActionErrors</code> object to add errors to if any
+ * validation errors occur.
+ * @param request Current request object.
+ */
+ public static boolean validateMinLength(Object bean,
+ ValidatorAction va, Field field,
+ ActionErrors errors,
HttpServletRequest request) {
String value = ValidatorUtil.getValueAsString(bean, field.getProperty());
@@ -543,10 +543,10 @@
if (value != null) {
try {
int min = Integer.parseInt(sMinLength);
-
+
if (!GenericValidator.minLength(value, min)) {
errors.add(field.getKey(), StrutsValidatorUtil.getActionError(request, va, field));
-
+
return false;
}
} catch (Exception e) {
@@ -554,7 +554,7 @@
return false;
}
}
-
+
return true;
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>