struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmitch...@apache.org
Subject svn commit: r160728 - struts/core/trunk/src/share/org/apache/struts/validator/FieldChecks.java
Date Sun, 10 Apr 2005 02:13:06 GMT
Author: jmitchell
Date: Sat Apr  9 19:13:05 2005
New Revision: 160728

URL: http://svn.apache.org/viewcvs?view=rev&rev=160728
Log:
Extract method for better code reuse - as described by Simion Report

Modified:
    struts/core/trunk/src/share/org/apache/struts/validator/FieldChecks.java

Modified: struts/core/trunk/src/share/org/apache/struts/validator/FieldChecks.java
URL: http://svn.apache.org/viewcvs/struts/core/trunk/src/share/org/apache/struts/validator/FieldChecks.java?view=diff&r1=160727&r2=160728
==============================================================================
--- struts/core/trunk/src/share/org/apache/struts/validator/FieldChecks.java (original)
+++ struts/core/trunk/src/share/org/apache/struts/validator/FieldChecks.java Sat Apr  9 19:13:05
2005
@@ -83,11 +83,7 @@
                                            HttpServletRequest request) {
 
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (GenericValidator.isBlankOrNull(value)) {
             errors.add(field.getKey(), Resources.getActionMessage(validator, request, va,
field));
@@ -123,11 +119,7 @@
         String value = null;
         boolean required = false;
 
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         int i = 0;
         String fieldJoin = "AND";
@@ -227,11 +219,7 @@
 
         String mask = field.getVarValue("mask");
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         try {
             if (!GenericValidator.isBlankOrNull(value)
@@ -274,11 +262,7 @@
 
         Object result = null;
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (GenericValidator.isBlankOrNull(value)) {
             return Boolean.TRUE;
@@ -293,6 +277,21 @@
         return result == null ? Boolean.FALSE : result;
     }
 
+    /**
+     * @param bean
+     * @param field
+     * @return
+     */
+    private static String evaluateBean(Object bean, Field field) {
+        String value;
+        if (isString(bean)) {
+            value = (String) bean;
+        } else {
+            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+        }
+        return value;
+    }
+
 
     /**
      * Checks if the field can safely be converted to a short primitive.
@@ -315,11 +314,7 @@
                                       HttpServletRequest request) {
         Object result = null;
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (GenericValidator.isBlankOrNull(value)) {
             return Boolean.TRUE;
@@ -356,11 +351,7 @@
                                           HttpServletRequest request) {
         Object result = null;
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (GenericValidator.isBlankOrNull(value)) {
             return Boolean.TRUE;
@@ -397,11 +388,7 @@
                                     HttpServletRequest request) {
         Object result = null;
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (GenericValidator.isBlankOrNull(value)) {
             return Boolean.TRUE;
@@ -438,11 +425,7 @@
                                       HttpServletRequest request) {
         Object result = null;
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (GenericValidator.isBlankOrNull(value)) {
             return Boolean.TRUE;
@@ -479,11 +462,7 @@
                                         HttpServletRequest request) {
         Object result = null;
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (GenericValidator.isBlankOrNull(value)) {
             return Boolean.TRUE;
@@ -527,11 +506,7 @@
 
         Object result = null;
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
         String datePattern = field.getVarValue("datePattern");
         String datePatternStrict = field.getVarValue("datePatternStrict");
         Locale locale = RequestUtils.getUserLocale(request, null);
@@ -581,11 +556,7 @@
                                            HttpServletRequest request) {
 
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (!GenericValidator.isBlankOrNull(value)) {
             try {
@@ -629,11 +600,7 @@
                                               HttpServletRequest request) {
 
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (!GenericValidator.isBlankOrNull(value)) {
             try {
@@ -677,11 +644,7 @@
                                              HttpServletRequest request) {
 
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (!GenericValidator.isBlankOrNull(value)) {
             try {
@@ -726,11 +689,7 @@
 
         Object result = null;
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (GenericValidator.isBlankOrNull(value)) {
             return Boolean.TRUE;
@@ -768,11 +727,7 @@
                                         HttpServletRequest request) {
 
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (!GenericValidator.isBlankOrNull(value) && !GenericValidator.isEmail(value))
{
             errors.add(field.getKey(), Resources.getActionMessage(validator, request, va,
field));
@@ -805,11 +760,7 @@
                                             HttpServletRequest request) {
 
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (value != null) {
             try {
@@ -852,11 +803,7 @@
                                             HttpServletRequest request) {
 
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (!GenericValidator.isBlankOrNull(value)) {
             try {
@@ -913,11 +860,7 @@
                                         HttpServletRequest request) {
 
         String value = null;
-        if (isString(bean)) {
-            value = (String) bean;
-        } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
-        }
+        value = evaluateBean(bean, field);
 
         if (GenericValidator.isBlankOrNull(value)) {
             return true;



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message