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 2006/01/21 01:21:00 UTC

svn commit: r370938 [19/50] - in /struts: action/trunk/ action/trunk/conf/java/ action/trunk/src/java/org/apache/struts/ action/trunk/src/java/org/apache/struts/action/ action/trunk/src/java/org/apache/struts/chain/ action/trunk/src/java/org/apache/str...

Modified: struts/action/trunk/src/java/org/apache/struts/validator/LazyValidatorForm.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/validator/LazyValidatorForm.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/validator/LazyValidatorForm.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/validator/LazyValidatorForm.java Fri Jan 20 16:19:02 2006
@@ -15,64 +15,72 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.struts.validator;
 
-import java.util.List;
-import java.util.Map;
-
 import org.apache.commons.beanutils.DynaBean;
 import org.apache.commons.beanutils.LazyDynaBean;
 
+import java.util.List;
+import java.util.Map;
+
 /**
- * <p>Struts <i>Lazy</i> <code>ActionForm</code> which <i>wraps</i> a <code>LazyDynaBean</code>.</p>
+ * <p>Struts <i>Lazy</i> <code>ActionForm</code> which <i>wraps</i> a
+ * <code>LazyDynaBean</code>.</p>
  *
- * <p>There isn't really that much to this implementation as most of the <i>lazy</i> behaviour is in
- *    <code>LazyDynaBean</code> and <i>wrapping</i> the <code>LazyDynaBean<code> is handled in the parent
- *    <code>BeanValidatorForm</code>. The only thing it really does is populate <i>indexed</i> properties
- *    which are a <code>List<code> type with a <code>LazyDynaBean<code> in the <code>get(name, index)</code>
- *    method.</p>
- *
- * <p><i>Lazy</i> DynaBeans provide several types of <i>lazy</i> behaviour:</p>
- * <ul>
- *     <li><b><i>lazy</i> property addition</b> - properties which do not exist
- *         are automatically added.</li>
- *     <li><b><i>lazy</i> List facilities</b> - automatically <i>grows</i> a <code>List</code> or
- *         <code>Array</code> to accomodate the index value being set.</li>
- *     <li><b><i>lazy</i> List creation</b> - automatic creation of a <code>List</code>
- *         or <code>Array</code> for <i>indexed</i> properties, if it doesn't exist.</li>
- *     <li><b><i>lazy</i> Map creation</b> - automatic creation of a <code>Map</code>
- *         for <i>mapped</i> properties, if it doesn't exist.</li>
- * </ul>
- *
- * <p>Using this <i>lazy</i> <code>ActionForm</code> means that you don't have to define the ActionForm's
- *    properties in the <code>struts-config.xml</code>. However, a word of warning, everything in the
- *    Request gets populated into this <code>ActionForm</code> circumventing the normal <i>firewall</i>
- *    function of Struts forms. Therefore you should only <i>take out</i> of this form properties you expect
- *    to be there rather than blindly populating all the properties into the business tier.</p>
- *
- * <p>Having said that it is not necessary to pre-define properties in the <code>struts-config.xml</code>, it is
- *    useful to sometimes do so for <i>mapped</i> or <i>indexed</i> properties. For example, if you want to use
- *    a different <code>Map<code> implementation from the default <code>HashMap</code> or an array for indexed
- *    properties, rather than the default <code>List</code> type:</p>
+ * <p>There isn't really that much to this implementation as most of the
+ * <i>lazy</i> behaviour is in <code>LazyDynaBean</code> and <i>wrapping</i>
+ * the <code>LazyDynaBean<code> is handled in the parent
+ * <code>BeanValidatorForm</code>. The only thing it really does is populate
+ * <i>indexed</i> properties which are a <code>List<code> type with a
+ * <code>LazyDynaBean<code> in the <code>get(name, index)</code> method.</p>
+ *
+ * <p><i>Lazy</i> DynaBeans provide several types of <i>lazy</i>
+ * behaviour:</p> <ul> <li><b><i>lazy</i> property addition</b> - properties
+ * which do not exist are automatically added.</li> <li><b><i>lazy</i> List
+ * facilities</b> - automatically <i>grows</i> a <code>List</code> or
+ * <code>Array</code> to accomodate the index value being set.</li>
+ * <li><b><i>lazy</i> List creation</b> - automatic creation of a
+ * <code>List</code> or <code>Array</code> for <i>indexed</i> properties, if
+ * it doesn't exist.</li> <li><b><i>lazy</i> Map creation</b> - automatic
+ * creation of a <code>Map</code> for <i>mapped</i> properties, if it doesn't
+ * exist.</li> </ul>
+ *
+ * <p>Using this <i>lazy</i> <code>ActionForm</code> means that you don't have
+ * to define the ActionForm's properties in the <code>struts-config.xml</code>.
+ * However, a word of warning, everything in the Request gets populated into
+ * this <code>ActionForm</code> circumventing the normal <i>firewall</i>
+ * function of Struts forms. Therefore you should only <i>take out</i> of this
+ * form properties you expect to be there rather than blindly populating all
+ * the properties into the business tier.</p>
+ *
+ * <p>Having said that it is not necessary to pre-define properties in the
+ * <code>struts-config.xml</code>, it is useful to sometimes do so for
+ * <i>mapped</i> or <i>indexed</i> properties. For example, if you want to use
+ * a different <code>Map<code> implementation from the default
+ * <code>HashMap</code> or an array for indexed properties, rather than the
+ * default <code>List</code> type:</p>
  *
  * <pre><code>
  *   &lt;form-bean name="myForm" type="org.apache.struts.validator.LazyValidatorForm"&gt;
  *     &lt;form-property name="myMap" type="java.util.TreeMap" /&gt;
- *     &lt;form-property name="myBeans" type="org.apache.commons.beanutils.LazyDynaBean[]" /&gt;
+ *     &lt;form-property name="myBeans" type="org.apache.commons.beanutils.LazyDynaBean[]"
+ * /&gt;
  *   &lt;/form-bean&gt;
  * </code></pre>
  *
- * <p>Another reason for defining <i>indexed</i> properties in the <code>struts-config.xml</code> is that
- *    if you are validating indexed properties using the Validator and none are submitted then the indexed
- *    property will be <code>null</code> which causes validator to fail. Pre-defining them in the
- *    <code>struts-config.xml</code> will result in a zero-length indexed property (array or List) being
- *    instantiated, avoiding an issue with validator in that circumstance.</p>
- *
- * <p>This implementation validates using the ActionForm <i>name</i>. If you require a version that
- *    validates according to the <i>path</i> then it can be easily created in the following manner:</p>
+ * <p>Another reason for defining <i>indexed</i> properties in the
+ * <code>struts-config.xml</code> is that if you are validating indexed
+ * properties using the Validator and none are submitted then the indexed
+ * property will be <code>null</code> which causes validator to fail.
+ * Pre-defining them in the <code>struts-config.xml</code> will result in a
+ * zero-length indexed property (array or List) being instantiated, avoiding
+ * an issue with validator in that circumstance.</p>
+ *
+ * <p>This implementation validates using the ActionForm <i>name</i>. If you
+ * require a version that validates according to the <i>path</i> then it can
+ * be easily created in the following manner:</p>
  *
- *  <pre><code>
+ * <pre><code>
  *    public class MyLazyForm extends LazyValidatorForm {
  *
  *        public MyLazyForm () {
@@ -83,27 +91,31 @@
  *    }
  * </code></pre>
  *
- * <p>Rather than using this class, another alternative is to either use a <code>LazyDynaBean</code> or
- *    custom version of <code>LazyDynaBean</code> directly. Struts now automatically <i>wraps</i> objects
- *    which are not <code>ActionForms</code> in a <code>BeanValidatorForm</code>. For example:</p>
+ * <p>Rather than using this class, another alternative is to either use a
+ * <code>LazyDynaBean</code> or custom version of <code>LazyDynaBean</code>
+ * directly. Struts now automatically <i>wraps</i> objects which are not
+ * <code>ActionForms</code> in a <code>BeanValidatorForm</code>. For
+ * example:</p>
  *
  * <pre><code>
  *   &lt;form-bean name="myForm" type="org.apache.commons.beanutils.LazyDynaBean"&gt;
- *     &lt;form-property name="myBeans" type="org.apache.commons.beanutils.LazyDynaBean[]" /&gt;
+ *     &lt;form-property name="myBeans" type="org.apache.commons.beanutils.LazyDynaBean[]"
+ * /&gt;
  *   &lt;/form-bean&gt;
  * </code></pre>
  *
- * @see <a href="http://jakarta.apache.org/commons/beanutils/apidocs/org/apache/commons/beanutils/package-summary.html#dynamic.lazy">Commons BeanUtils JavaDoc</a>
+ * @version $Rev$ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
+ *          $
+ * @see <a href="http://jakarta.apache.org/commons/beanutils/apidocs/org/apache/commons/beanutils/package-summary.html#dynamic.lazy">Commons
+ *      BeanUtils JavaDoc</a>
  * @since Struts 1.2.6
- * @version $Rev$ $Date$
  */
 public class LazyValidatorForm extends BeanValidatorForm {
-
     // ------------------- Constructors ----------------------------------
 
     /**
-     * Default Constructor which creates a <code>LazyDynaBean</code> to <i>back</i>
-     * this form.
+     * Default Constructor which creates a <code>LazyDynaBean</code> to
+     * <i>back</i> this form.
      */
     public LazyValidatorForm() {
         super(new LazyDynaBean());
@@ -117,25 +129,24 @@
 
     // ------------------- DynaBean methods ----------------------------------
 
-   /**
-    * <p>Return an indexed property value.</p>
-    *
-    * <p>If the "indexed" property is a <code>List</code> type then
-    *    any missing values are populated with a bean (created in
-    *    the <code>newIndexedBean(name)</code> method - in this
-    *    implementation this is a <code>LazyDynaBean</code> type.</p>
-    */
+    /**
+     * <p>Return an indexed property value.</p>
+     *
+     * <p>If the "indexed" property is a <code>List</code> type then any
+     * missing values are populated with a bean (created in the
+     * <code>newIndexedBean(name)</code> method - in this implementation this
+     * is a <code>LazyDynaBean</code> type.</p>
+     */
     public Object get(String name, int index) {
-
         int size = size(name);
 
-
         // Get the indexed property
         Object value = dynaBean.get(name, index);
 
         // Create missing beans for Lists
         if (value == null) {
             Object indexedValue = dynaBean.get(name);
+
             if (List.class.isAssignableFrom(indexedValue.getClass())) {
                 for (int i = size; i <= index; i++) {
                     value = newIndexedBean(name);
@@ -145,32 +156,29 @@
         }
 
         return value;
-
     }
 
     // ------------------- Public methods ----------------------------------
 
-   /**
-    * <p>Return the <code>Map</code> containing the property values.</p>
-    *
-    * <p>Provided so that properties can be access using JSTL.</p>
-    */
+    /**
+     * <p>Return the <code>Map</code> containing the property values.</p>
+     *
+     * <p>Provided so that properties can be access using JSTL.</p>
+     */
     public Map getMap() {
-        return ((LazyDynaBean)dynaBean).getMap();
+        return ((LazyDynaBean) dynaBean).getMap();
     }
 
     // ------------------- Protected methods ----------------------------------
 
-   /**
-    * <p>Creates new <code>DynaBean</code> instances to populate
-    *    an 'indexed' property of beans - defaults to <code>LazyDynaBean</code>
-    *    type.</p>
-    *
-    * <p>Override this method if you require a different type of
-    *    <code>DynaBean</code>.</p>
-    */
+    /**
+     * <p>Creates new <code>DynaBean</code> instances to populate an 'indexed'
+     * property of beans - defaults to <code>LazyDynaBean</code> type.</p>
+     *
+     * <p>Override this method if you require a different type of
+     * <code>DynaBean</code>.</p>
+     */
     protected DynaBean newIndexedBean(String name) {
         return new LazyDynaBean();
     }
-
-}
\ No newline at end of file
+}

Modified: struts/action/trunk/src/java/org/apache/struts/validator/Resources.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/validator/Resources.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/validator/Resources.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/validator/Resources.java Fri Jan 20 16:19:02 2006
@@ -15,46 +15,43 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.struts.validator;
 
-import java.util.Locale;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.commons.validator.Arg;
 import org.apache.commons.validator.Field;
 import org.apache.commons.validator.Msg;
-import org.apache.commons.validator.Var;
 import org.apache.commons.validator.Validator;
 import org.apache.commons.validator.ValidatorAction;
 import org.apache.commons.validator.ValidatorResources;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.commons.validator.Var;
 import org.apache.struts.Globals;
 import org.apache.struts.action.ActionMessage;
 import org.apache.struts.action.ActionMessages;
+import org.apache.struts.config.ModuleConfig;
 import org.apache.struts.util.MessageResources;
 import org.apache.struts.util.ModuleUtils;
 import org.apache.struts.util.RequestUtils;
-import org.apache.struts.config.ModuleConfig;
+
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import java.util.Locale;
 
 /**
- * This class helps provides some useful methods for retrieving objects
- * from different scopes of the application.
+ * This class helps provides some useful methods for retrieving objects from
+ * different scopes of the application.
  *
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-09-16 23:34:41 -0400 (Fri, 16 Sep 2005)
+ *          $
  * @since Struts 1.1
  */
 public class Resources {
-
     /**
      * The message resources for this package.
      */
-    private static MessageResources sysmsgs =
-            MessageResources.getMessageResources(
-                    "org.apache.struts.validator.LocalStrings");
+    private static MessageResources sysmsgs = MessageResources
+            .getMessageResources("org.apache.struts.validator.LocalStrings");
 
     /**
      * <p>Commons Logging instance.</p>
@@ -64,130 +61,135 @@
     /**
      * Resources key the <code>ServletContext</code> is stored under.
      */
-    private static String SERVLET_CONTEXT_PARAM = "javax.servlet.ServletContext";
+    private static String SERVLET_CONTEXT_PARAM =
+            "javax.servlet.ServletContext";
 
     /**
      * Resources key the <code>HttpServletRequest</code> is stored under.
      */
     private static String HTTP_SERVLET_REQUEST_PARAM =
-        "javax.servlet.http.HttpServletRequest";
+            "javax.servlet.http.HttpServletRequest";
 
     /**
      * Resources key the <code>ActionMessages</code> is stored under.
      */
     private static String ACTION_MESSAGES_PARAM =
-        "org.apache.struts.action.ActionMessages";
-
+            "org.apache.struts.action.ActionMessages";
 
     /**
      * Retrieve <code>ValidatorResources</code> for the current module.
+     *
      * @param application Application Context
-     * @param request The ServletRequest
+     * @param request     The ServletRequest
      */
     public static ValidatorResources getValidatorResources(
-        ServletContext application,
-        HttpServletRequest request) {
-
-        String prefix =
-            ModuleUtils
-                .getInstance()
+            ServletContext application, HttpServletRequest request) {
+        String prefix = ModuleUtils.getInstance()
                 .getModuleConfig(request, application)
                 .getPrefix();
 
-        return (ValidatorResources) application.getAttribute(
-            ValidatorPlugIn.VALIDATOR_KEY + prefix);
+        return (ValidatorResources) application
+                .getAttribute(ValidatorPlugIn.VALIDATOR_KEY
+                        + prefix);
     }
 
     /**
      * Retrieve <code>MessageResources</code> for the module.
+     *
      * @param request the servlet request
      */
-    public static MessageResources getMessageResources(HttpServletRequest request) {
+    public static MessageResources getMessageResources(
+            HttpServletRequest request) {
         return (MessageResources) request.getAttribute(Globals.MESSAGES_KEY);
     }
 
     /**
      * Retrieve <code>MessageResources</code> for the module and bundle.
+     *
      * @param application the servlet context
-     * @param request the servlet request
-     * @param bundle the bundle key
+     * @param request     the servlet request
+     * @param bundle      the bundle key
      */
     public static MessageResources getMessageResources(
-        ServletContext application,
-        HttpServletRequest request,
-        String bundle) {
-
+            ServletContext application, HttpServletRequest request,
+            String bundle) {
         if (bundle == null) {
             bundle = Globals.MESSAGES_KEY;
         }
 
-        MessageResources resources = (MessageResources)request.getAttribute(bundle);
+        MessageResources resources =
+                (MessageResources) request.getAttribute(bundle);
 
         if (resources == null) {
             ModuleConfig moduleConfig = ModuleUtils.getInstance()
-                                         .getModuleConfig(request, application);
-            resources = (MessageResources)application.getAttribute(bundle + moduleConfig.getPrefix());
+                    .getModuleConfig(request,
+                            application);
+
+            resources = (MessageResources) application.getAttribute(bundle
+                    + moduleConfig.getPrefix());
         }
 
         if (resources == null) {
-            resources = (MessageResources)application.getAttribute(bundle);
+            resources = (MessageResources) application.getAttribute(bundle);
         }
 
         if (resources == null) {
-            throw new NullPointerException("No message resources found for bundle: " + bundle);
+            throw new NullPointerException(
+                    "No message resources found for bundle: " + bundle);
         }
 
         return resources;
-
     }
 
     /**
      * Get the value of a variable.
-     * @param varName The variable name
-     * @param field the validator Field
+     *
+     * @param varName   The variable name
+     * @param field     the validator Field
      * @param validator The Validator
-     * @param request the servlet request
-     * @param required Whether the variable is mandatory
+     * @param request   the servlet request
+     * @param required  Whether the variable is mandatory
      * @return The variable's value
      */
-    public static String getVarValue(String varName,
-                                     Field  field,
+    public static String getVarValue(String varName, Field field,
                                      Validator validator,
                                      HttpServletRequest request,
                                      boolean required) {
-
         Var var = field.getVar(varName);
-        if (var == null) {
 
+        if (var == null) {
             String msg = sysmsgs.getMessage("variable.missing", varName);
+
             if (required) {
                 throw new IllegalArgumentException(msg);
             }
+
             if (log.isDebugEnabled()) {
                 log.debug(field.getProperty() + ": " + msg);
             }
+
             return null;
         }
 
-        ServletContext application = (ServletContext)validator
-                     .getParameterValue(SERVLET_CONTEXT_PARAM);
+        ServletContext application = (ServletContext) validator
+                .getParameterValue(SERVLET_CONTEXT_PARAM);
+
         return getVarValue(var, application, request, required);
     }
 
     /**
      * Get the value of a variable.
-     * @param var the validator variable
+     *
+     * @param var         the validator variable
      * @param application The ServletContext
-     * @param request the servlet request
-     * @param required Whether the variable is mandatory
+     * @param request     the servlet request
+     * @param required    Whether the variable is mandatory
      * @return The variables values
      */
-    public static String getVarValue(Var var,
-                                     ServletContext application,
+    public static String getVarValue(Var var, ServletContext application,
                                      HttpServletRequest request,
                                      boolean required) {
-
-        String varName  = var.getName();
+        String varName = var.getName();
         String varValue = var.getValue();
 
         // Non-resource variable
@@ -197,41 +199,37 @@
 
         // Get the message resources
         String bundle = var.getBundle();
-        MessageResources messages = 
-                getMessageResources(application, request, bundle);
+        MessageResources messages = getMessageResources(application, request,
+                bundle);
 
         // Retrieve variable's value from message resources
         Locale locale = RequestUtils.getUserLocale(request, null);
-        String value  = messages.getMessage(locale, varValue, null);
+        String value = messages.getMessage(locale, varValue, null);
 
         // Not found in message resources
-        if (value == null && required) {
-            throw new IllegalArgumentException(
-                   sysmsgs.getMessage("variable.resource.notfound",
-                              varName, varValue, bundle));
+        if ((value == null) && required) {
+            throw new IllegalArgumentException(sysmsgs.getMessage(
+                    "variable.resource.notfound", varName, varValue, bundle));
         }
 
         if (log.isDebugEnabled()) {
-            log.debug("Var=[" + varName  + "], " +
-                   "bundle=[" + bundle   + "], " +
-                      "key=[" + varValue + "], " +
-                    "value=[" + value    + "]");
+            log.debug("Var=[" + varName + "], " + "bundle=[" + bundle + "], "
+                    + "key=[" + varValue + "], " + "value=[" + value + "]");
         }
 
         return value;
-
     }
 
     /**
-     * Gets the <code>Locale</code> sensitive value based on the key passed in.
+     * Gets the <code>Locale</code> sensitive value based on the key passed
+     * in.
+     *
      * @param messages The Message resources
-     * @param locale The locale.
-     * @param key Key used to lookup the message
+     * @param locale   The locale.
+     * @param key      Key used to lookup the message
      */
-    public static String getMessage(
-        MessageResources messages,
-        Locale locale,
-        String key) {
+    public static String getMessage(MessageResources messages, Locale locale,
+                                    String key) {
         String message = null;
 
         if (messages != null) {
@@ -242,189 +240,185 @@
     }
 
     /**
-     * Gets the <code>Locale</code> sensitive value based on the key passed in.
+     * Gets the <code>Locale</code> sensitive value based on the key passed
+     * in.
+     *
      * @param request servlet request
-     * @param key the request key
+     * @param key     the request key
      */
     public static String getMessage(HttpServletRequest request, String key) {
         MessageResources messages = getMessageResources(request);
 
-        return getMessage(messages, RequestUtils.getUserLocale(request, null), key);
+        return getMessage(messages, RequestUtils.getUserLocale(request, null),
+                key);
     }
 
     /**
-     * Gets the locale sensitive message based on the
-     * <code>ValidatorAction</code> message and the <code>Field</code>'s
-     * arg objects.
-     * @param messages  The Message resources
-     * @param locale The locale
-     * @param va The Validator Action
-     * @param field The Validator Field
-     */
-    public static String getMessage(
-        MessageResources messages,
-        Locale locale,
-        ValidatorAction va,
-        Field field) {
-
-        String args[] = getArgs(va.getName(), messages, locale, field);
-        String msg =
-            field.getMsg(va.getName()) != null
-                ? field.getMsg(va.getName())
-                : va.getMsg();
+     * Gets the locale sensitive message based on the <code>ValidatorAction</code>
+     * message and the <code>Field</code>'s arg objects.
+     *
+     * @param messages The Message resources
+     * @param locale   The locale
+     * @param va       The Validator Action
+     * @param field    The Validator Field
+     */
+    public static String getMessage(MessageResources messages, Locale locale,
+                                    ValidatorAction va, Field field) {
+        String[] args = getArgs(va.getName(), messages, locale, field);
+        String msg = (field.getMsg(va.getName()) != null)
+                ? field.getMsg(va.getName()) : va.getMsg();
 
         return messages.getMessage(locale, msg, args);
     }
+
     /**
-     * Gets the <code>Locale</code> sensitive value based on the key passed in.
-     * @param application the servlet context
-     * @param request the servlet request
+     * Gets the <code>Locale</code> sensitive value based on the key passed
+     * in.
+     *
+     * @param application     the servlet context
+     * @param request         the servlet request
      * @param defaultMessages The default Message resources
-     * @param locale The locale
-     * @param va The Validator Action
-     * @param field The Validator Field
+     * @param locale          The locale
+     * @param va              The Validator Action
+     * @param field           The Validator Field
      */
     public static String getMessage(ServletContext application,
                                     HttpServletRequest request,
                                     MessageResources defaultMessages,
-                                    Locale locale,
-                                    ValidatorAction va,
+                                    Locale locale, ValidatorAction va,
                                     Field field) {
-
         Msg msg = field.getMessage(va.getName());
-        if (msg != null && !msg.isResource()) {
+
+        if ((msg != null) && !msg.isResource()) {
             return msg.getKey();
         }
 
-        String msgKey    = null;
+        String msgKey = null;
         String msgBundle = null;
         MessageResources messages = defaultMessages;
+
         if (msg == null) {
-           msgKey = va.getMsg();
+            msgKey = va.getMsg();
         } else {
-           msgKey    = msg.getKey();
-           msgBundle = msg.getBundle();
-           if (msg.getBundle() != null) {
-               messages = getMessageResources(application, request, msg.getBundle());
-           }
+            msgKey = msg.getKey();
+            msgBundle = msg.getBundle();
+
+            if (msg.getBundle() != null) {
+                messages = getMessageResources(application, request,
+                        msg.getBundle());
+            }
         }
 
-        if (msgKey == null || msgKey.length() == 0) {
+        if ((msgKey == null) || (msgKey.length() == 0)) {
             return "??? " + va.getName() + "." + field.getProperty() + " ???";
         }
 
         // Get the arguments
         Arg[] args = field.getArgs(va.getName());
-        String[] argValues = getArgValues(application, request, messages, locale, args);
+        String[] argValues = getArgValues(application, request, messages,
+                locale, args);
 
         // Return the message
         return messages.getMessage(locale, msgKey, argValues);
-
     }
 
-
     /**
      * Gets the <code>ActionMessage</code> based on the
-     * <code>ValidatorAction</code> message and the <code>Field</code>'s
-     * arg objects.
+     * <code>ValidatorAction</code> message and the <code>Field</code>'s arg
+     * objects.
+     *
      * @param request the servlet request
-     * @param va Validator action
-     * @param field the validator Field
+     * @param va      Validator action
+     * @param field   the validator Field
      */
-    public static ActionMessage getActionMessage(
-        HttpServletRequest request,
-        ValidatorAction va,
-        Field field) {
-
-        String args[] =
-            getArgs(
-                va.getName(),
-                getMessageResources(request),
-                RequestUtils.getUserLocale(request, null),
-                field);
-
-        String msg =
-            field.getMsg(va.getName()) != null
-                ? field.getMsg(va.getName())
-                : va.getMsg();
+    public static ActionMessage getActionMessage(HttpServletRequest request,
+                                                 ValidatorAction va,
+                                                 Field field) {
+        String[] args = getArgs(va.getName(), getMessageResources(request),
+                RequestUtils.getUserLocale(request, null), field);
+
+        String msg = (field.getMsg(va.getName()) != null)
+                ? field.getMsg(va.getName()) : va.getMsg();
 
         return new ActionMessage(msg, args);
     }
 
     /**
      * Gets the <code>ActionMessage</code> based on the
-     * <code>ValidatorAction</code> message and the <code>Field</code>'s
-     * arg objects.
+     * <code>ValidatorAction</code> message and the <code>Field</code>'s arg
+     * objects.
+     *
      * @param validator the Validator
-     * @param request the servlet request
-     * @param va Validator action
-     * @param field the validator Field
-     */
-    public static ActionMessage getActionMessage(
-        Validator validator,
-        HttpServletRequest request,
-        ValidatorAction va,
-        Field field) {
-
+     * @param request   the servlet request
+     * @param va        Validator action
+     * @param field     the validator Field
+     */
+    public static ActionMessage getActionMessage(Validator validator,
+                                                 HttpServletRequest request,
+                                                 ValidatorAction va,
+                                                 Field field) {
         Msg msg = field.getMessage(va.getName());
-        if (msg != null && !msg.isResource()) {
+
+        if ((msg != null) && !msg.isResource()) {
             return new ActionMessage(msg.getKey(), false);
         }
 
-        String msgKey    = null;
+        String msgKey = null;
         String msgBundle = null;
+
         if (msg == null) {
-           msgKey = va.getMsg();
+            msgKey = va.getMsg();
         } else {
-           msgKey    = msg.getKey();
-           msgBundle = msg.getBundle();
+            msgKey = msg.getKey();
+            msgBundle = msg.getBundle();
         }
 
-        if (msgKey == null || msgKey.length() == 0) {
-            return new ActionMessage("??? " + va.getName() + "." + field.getProperty() + " ???", false);
+        if ((msgKey == null) || (msgKey.length() == 0)) {
+            return new ActionMessage("??? " + va.getName() + "."
+                    + field.getProperty() + " ???", false);
         }
 
-        ServletContext application = (ServletContext)validator.getParameterValue(SERVLET_CONTEXT_PARAM);
-        MessageResources messages = getMessageResources(application, request, msgBundle);
+        ServletContext application = (ServletContext) validator
+                .getParameterValue(SERVLET_CONTEXT_PARAM);
+        MessageResources messages = getMessageResources(application, request,
+                msgBundle);
         Locale locale = RequestUtils.getUserLocale(request, null);
 
         Arg[] args = field.getArgs(va.getName());
-        String[] argValues = getArgValues(application, request, messages, locale, args);
+        String[] argValues = getArgValues(application, request, messages,
+                locale, args);
 
         ActionMessage actionMessage = null;
+
         if (msgBundle == null) {
             actionMessage = new ActionMessage(msgKey, argValues);
         } else {
             String message = messages.getMessage(locale, msgKey, argValues);
+
             actionMessage = new ActionMessage(message, false);
         }
-        return actionMessage;
 
+        return actionMessage;
     }
 
-
     /**
-     * Gets the message arguments based on the current
-     * <code>ValidatorAction</code> and <code>Field</code>.
+     * Gets the message arguments based on the current <code>ValidatorAction</code>
+     * and <code>Field</code>.
+     *
      * @param actionName action name
-     * @param messages message resources
-     * @param locale the locale
-     * @param field the validator field
-     */
-    public static String[] getArgs(
-        String actionName,
-        MessageResources messages,
-        Locale locale,
-        Field field) {
-
+     * @param messages   message resources
+     * @param locale     the locale
+     * @param field      the validator field
+     */
+    public static String[] getArgs(String actionName,
+                                   MessageResources messages, Locale locale,
+                                   Field field) {
         String[] argMessages = new String[4];
 
-        Arg[] args =
-            new Arg[] {
-                field.getArg(actionName,0),
-                field.getArg(actionName,1),
-                field.getArg(actionName,2),
-                field.getArg(actionName,3)};
+        Arg[] args = new Arg[]{
+                field.getArg(actionName, 0), field.getArg(actionName, 1),
+                field.getArg(actionName, 2), field.getArg(actionName, 3)
+        };
 
         for (int i = 0; i < args.length; i++) {
             if (args[i] == null) {
@@ -432,86 +426,82 @@
             }
 
             if (args[i].isResource()) {
-                argMessages[i] = getMessage(messages, locale, args[i].getKey());
+                argMessages[i] =
+                        getMessage(messages, locale, args[i].getKey());
             } else {
                 argMessages[i] = args[i].getKey();
             }
-
         }
 
         return argMessages;
     }
 
     /**
-     * Gets the message arguments based on the current
-     * <code>ValidatorAction</code> and <code>Field</code>.
-     * @param application the servlet context
-     * @param request the servlet request
+     * Gets the message arguments based on the current <code>ValidatorAction</code>
+     * and <code>Field</code>.
+     *
+     * @param application     the servlet context
+     * @param request         the servlet request
      * @param defaultMessages Default message resources
-     * @param locale the locale
-     * @param args The arguments for the message
+     * @param locale          the locale
+     * @param args            The arguments for the message
      */
-    private static String[] getArgValues(
-        ServletContext application,
-        HttpServletRequest request,
-        MessageResources defaultMessages,
-        Locale locale,
-        Arg[] args) {
-
-        if (args == null || args.length == 0) {
+    private static String[] getArgValues(ServletContext application,
+                                         HttpServletRequest request,
+                                         MessageResources defaultMessages,
+                                         Locale locale, Arg[] args) {
+        if ((args == null) || (args.length == 0)) {
             return null;
         }
 
         String[] values = new String[args.length];
+
         for (int i = 0; i < args.length; i++) {
             if (args[i] != null) {
                 if (args[i].isResource()) {
-
                     MessageResources messages = defaultMessages;
+
                     if (args[i].getBundle() != null) {
-                        messages = getMessageResources(application, request, args[i].getBundle());
+                        messages = getMessageResources(application, request,
+                                args[i].getBundle());
                     }
-                    values[i] = messages.getMessage(locale, args[i].getKey());
 
+                    values[i] = messages.getMessage(locale, args[i].getKey());
                 } else {
-
                     values[i] = args[i].getKey();
-
                 }
             }
         }
 
         return values;
-
     }
 
     /**
      * Initialize the <code>Validator</code> to perform validation.
      *
-     * @param key The key that the validation rules are under (the form elements
-     * name attribute).
-     * @param bean The bean validation is being performed on.
+     * @param key         The key that the validation rules are under (the
+     *                    form elements name attribute).
+     * @param bean        The bean validation is being performed on.
      * @param application servlet context
-     * @param request The current request object.
-     * @param errors The object any errors will be stored in.
-     * @param page This in conjunction with  the page property of a
-     * <code>Field<code> can control the processing of fields.  If the field's
-     * page is less than or equal to this page value, it will be processed.
-     */
-    public static Validator initValidator(
-        String key,
-        Object bean,
-        ServletContext application,
-        HttpServletRequest request,
-        ActionMessages errors,
-        int page) {
-
+     * @param request     The current request object.
+     * @param errors      The object any errors will be stored in.
+     * @param page        This in conjunction with  the page property of a
+     *                    <code>Field<code> can control the processing of
+     *                    fields.  If the field's page is less than or equal
+     *                    to this page value, it will be processed.
+     */
+    public static Validator initValidator(String key, Object bean,
+                                          ServletContext application,
+                                          HttpServletRequest request,
+                                          ActionMessages errors, int page) {
         ValidatorResources resources =
-            Resources.getValidatorResources(application, request);
+                Resources.getValidatorResources(application,
+                        request);
 
         Locale locale = RequestUtils.getUserLocale(request, null);
 
         Validator validator = new Validator(resources, key);
+
         validator.setUseContextClassLoader(true);
 
         validator.setPage(page);
@@ -524,5 +514,4 @@
 
         return validator;
     }
-
 }

Modified: struts/action/trunk/src/java/org/apache/struts/validator/ValidatorActionForm.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/validator/ValidatorActionForm.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/validator/ValidatorActionForm.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/validator/ValidatorActionForm.java Fri Jan 20 16:19:02 2006
@@ -15,42 +15,38 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.struts.validator;
 
-import java.io.Serializable;
-import javax.servlet.http.HttpServletRequest;
-
 import org.apache.struts.action.ActionMapping;
 
+import javax.servlet.http.HttpServletRequest;
+import java.io.Serializable;
 
 /**
- * <p>This class extends <strong>ValidatorForm</strong> and provides
- * basic field validation based on an XML file.  The key passed into the
- * validator is the action element's 'path' attribute from the
- * struts-config.xml which should match the form element's name attribute
- * in the validation.xml.</p>
+ * <p>This class extends <strong>ValidatorForm</strong> and provides basic
+ * field validation based on an XML file.  The key passed into the validator
+ * is the action element's 'path' attribute from the struts-config.xml which
+ * should match the form element's name attribute in the validation.xml.</p>
  *
  * <ul><li>See <code>ValidatorPlugin</code> definition in struts-config.xml
  * for validation rules.</li></ul>
  *
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
+ *          $
  * @since Struts 1.1
  */
-
-public class ValidatorActionForm extends ValidatorForm implements Serializable {
-
+public class ValidatorActionForm extends ValidatorForm
+        implements Serializable {
     /**
      * Returns the Validation key.
      *
      * @param mapping The mapping used to select this instance
      * @param request The servlet request we are processing
-     * @return validation key - the action element's 'path' attribute in this case
+     * @return validation key - the action element's 'path' attribute in this
+     *         case
      */
     public String getValidationKey(ActionMapping mapping,
                                    HttpServletRequest request) {
-
         return mapping.getPath();
     }
-
 }

Modified: struts/action/trunk/src/java/org/apache/struts/validator/ValidatorForm.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/validator/ValidatorForm.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/validator/ValidatorForm.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/validator/ValidatorForm.java Fri Jan 20 16:19:02 2006
@@ -15,15 +15,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.struts.validator;
 
-import java.io.Serializable;
-import java.util.Map;
-
-import javax.servlet.ServletContext;
-import javax.servlet.http.HttpServletRequest;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.validator.Validator;
@@ -33,30 +26,34 @@
 import org.apache.struts.action.ActionForm;
 import org.apache.struts.action.ActionMapping;
 
+import javax.servlet.ServletContext;
+import javax.servlet.http.HttpServletRequest;
+import java.io.Serializable;
+import java.util.Map;
+
 /**
- * <p>This class extends <strong>ActionForm</strong> and provides
- * basic field validation based on an XML file.  The key passed into the
- * validator is the action element's 'name' attribute from the
- * struts-config.xml which should match the form element's name attribute
- * in the validation.xml.</p>
+ * <p>This class extends <strong>ActionForm</strong> and provides basic field
+ * validation based on an XML file.  The key passed into the validator is the
+ * action element's 'name' attribute from the struts-config.xml which should
+ * match the form element's name attribute in the validation.xml.</p>
  *
  * <ul><li>See <code>ValidatorPlugin</code> definition in struts-config.xml
  * for validation rules.</li></ul>
  *
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-05-07 12:11:38 -0400 (Sat, 07 May 2005)
+ *          $
  * @see org.apache.struts.action.ActionForm
  * @since Struts 1.1
  */
 public class ValidatorForm extends ActionForm implements Serializable {
-
     /**
      * Commons Logging instance.
      */
     private static Log log = LogFactory.getLog(ValidatorForm.class);
 
     /**
-     * The results returned from the validation performed
-     * by the <code>Validator</code>.
+     * The results returned from the validation performed by the
+     * <code>Validator</code>.
      */
     protected ValidatorResults validatorResults = null;
 
@@ -67,6 +64,7 @@
 
     /**
      * Gets page.
+     *
      * @return page number
      */
     public int getPage() {
@@ -75,6 +73,7 @@
 
     /**
      * Sets page.
+     *
      * @param page page number
      */
     public void setPage(int page) {
@@ -82,33 +81,31 @@
     }
 
     /**
-     * Validate the properties that have been set from this HTTP request,
-     * and return an <code>ActionErrors</code> object that encapsulates any
+     * Validate the properties that have been set from this HTTP request, and
+     * return an <code>ActionErrors</code> object that encapsulates any
      * validation errors that have been found.  If no errors are found, return
      * <code>null</code> or an <code>ActionErrors</code> object with no
      * recorded error messages.
      *
      * @param mapping The mapping used to select this instance
      * @param request The servlet request we are processing
-     * @return  <code>ActionErrors</code> object that encapsulates any  validation errors
-
+     * @return <code>ActionErrors</code> object that encapsulates any
+     *         validation errors
      */
     public ActionErrors validate(ActionMapping mapping,
                                  HttpServletRequest request) {
-
         ServletContext application = getServlet().getServletContext();
         ActionErrors errors = new ActionErrors();
 
         String validationKey = getValidationKey(mapping, request);
 
-        Validator validator = Resources.initValidator(validationKey,
-                             this,
-                             application, request,
-                             errors, page);
+        Validator validator = Resources.initValidator(validationKey, this,
+                application, request, errors, page);
 
         try {
             validatorResults = validator.validate();
-        } catch (ValidatorException e) {
+        }
+        catch (ValidatorException e) {
             log.error(e.getMessage(), e);
         }
 
@@ -124,7 +121,6 @@
      */
     public String getValidationKey(ActionMapping mapping,
                                    HttpServletRequest request) {
-
         return mapping.getAttribute();
     }
 
@@ -141,8 +137,8 @@
     }
 
     /**
-     * Get results of the validation performed by the
-     * <code>Validator</code>.
+     * Get results of the validation performed by the <code>Validator</code>.
+     *
      * @return results of the validation
      */
     public ValidatorResults getValidatorResults() {
@@ -150,8 +146,8 @@
     }
 
     /**
-     * Set results of the validation performed by the
-     * <code>Validator</code>.
+     * Set results of the validation performed by the <code>Validator</code>.
+     *
      * @param validatorResults results of validation
      */
     public void setValidatorResults(ValidatorResults validatorResults) {
@@ -159,13 +155,14 @@
     }
 
     /**
-     * Returns a <code>Map</code> of values returned
-     * from any validation that returns a value other than
-     * <code>null</code> or <code>Boolean</code> with the
-     * key the full property path of the field.
-     * @return  <code>Map</code> of non-null values
+     * Returns a <code>Map</code> of values returned from any validation that
+     * returns a value other than <code>null</code> or <code>Boolean</code>
+     * with the key the full property path of the field.
+     *
+     * @return <code>Map</code> of non-null values
      */
     public Map getResultValueMap() {
-        return (validatorResults != null ? validatorResults.getResultValueMap() : null);
+        return ((validatorResults != null)
+                ? validatorResults.getResultValueMap() : null);
     }
 }

Modified: struts/action/trunk/src/java/org/apache/struts/validator/ValidatorPlugIn.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/validator/ValidatorPlugIn.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/validator/ValidatorPlugIn.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/validator/ValidatorPlugIn.java Fri Jan 20 16:19:02 2006
@@ -15,60 +15,46 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.struts.validator;
 
-import org.xml.sax.SAXException;
-
-import java.util.StringTokenizer;
-import java.util.List;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.io.BufferedInputStream;
-import java.io.InputStream;
-import java.io.IOException;
-import java.net.URL;
-import javax.servlet.ServletException;
-import javax.servlet.UnavailableException;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.validator.ValidatorResources;
 import org.apache.struts.action.ActionServlet;
 import org.apache.struts.action.PlugIn;
 import org.apache.struts.config.ModuleConfig;
+import org.xml.sax.SAXException;
+
+import javax.servlet.ServletException;
+import javax.servlet.UnavailableException;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
 
 /**
  * Loads <code>ValidatorResources</code> based on configuration in the
  * struts-config.xml file.
  *
- * @version $Rev$ $Date$
+ * @version $Rev$ $Date: 2005-08-30 00:22:27 -0400 (Tue, 30 Aug 2005)
+ *          $
  * @since Struts 1.1
  */
 public class ValidatorPlugIn implements PlugIn {
-
     /**
      * Commons Logging instance.
      */
     private static Log log = LogFactory.getLog(ValidatorPlugIn.class);
 
     /**
-     * The module configuration for our owning module.
-     */
-    private ModuleConfig config = null;
-
-    /**
-     * The {@link ActionServlet} owning this application.
-     */
-    private ActionServlet servlet = null;
-
-    /**
      * Delimitter for Validator resources.
      */
     private final static String RESOURCE_DELIM = ",";
 
     /**
-     * Application scope key that <code>ValidatorResources</code> is stored under.
+     * Application scope key that <code>ValidatorResources</code> is stored
+     * under.
      */
     public final static String VALIDATOR_KEY =
             "org.apache.commons.validator.VALIDATOR_RESOURCES";
@@ -82,11 +68,20 @@
             "org.apache.struts.validator.STOP_ON_ERROR";
 
     /**
-     * The set of Form instances that have been created and initialized,
-     * keyed by the struts form name.
+     * The module configuration for our owning module.
      */
-    protected ValidatorResources resources = null;
+    private ModuleConfig config = null;
 
+    /**
+     * The {@link ActionServlet} owning this application.
+     */
+    private ActionServlet servlet = null;
+
+    /**
+     * The set of Form instances that have been created and initialized, keyed
+     * by the struts form name.
+     */
+    protected ValidatorResources resources = null;
 
     // ------------------------------------------------------------- Properties
 
@@ -96,6 +91,13 @@
     private String pathnames = null;
 
     /**
+     * Informs the Validators if it has to stop validation when finding the
+     * first error or if it should continue.  Default to <code>true</code> to
+     * keep Struts 1.1 backwards compatibility.
+     */
+    private boolean stopOnFirstError = true;
+
+    /**
      * Gets a comma delimitted list of Validator resources.
      *
      * @return comma delimited list of Validator resource path names
@@ -114,18 +116,11 @@
     }
 
     /**
-     * Informs the Validators if it has to stop validation when finding the
-     * first error or if it should continue.  Default to <code>true</code> to
-     * keep Struts 1.1 backwards compatibility.
-     */
-    private boolean stopOnFirstError = true;
-
-    /**
      * Gets the value for stopOnFirstError.
      *
      * @return A boolean indicating whether JavaScript validation should stop
-     *         when it finds the first error (Struts 1.1 behaviour) or continue
-     *         validation.
+     *         when it finds the first error (Struts 1.1 behaviour) or
+     *         continue validation.
      * @since Struts 1.2
      */
     public boolean isStopOnFirstError() {
@@ -136,8 +131,9 @@
      * Sets the value for stopOnFirstError.
      *
      * @param stopOnFirstError A boolean indicating whether JavaScript
-     *                         validation should stop when it finds the first error
-     *                         (Struts 1.1 behaviour) or continue validation.
+     *                         validation should stop when it finds the first
+     *                         error (Struts 1.1 behaviour) or continue
+     *                         validation.
      * @since Struts 1.2
      */
     public void setStopOnFirstError(boolean stopOnFirstError) {
@@ -153,7 +149,6 @@
      */
     public void init(ActionServlet servlet, ModuleConfig config)
             throws ServletException {
-
         // Remember our associated configuration and servlet
         this.config = config;
         this.servlet = servlet;
@@ -162,25 +157,26 @@
         try {
             this.initResources();
 
-            servlet.getServletContext().setAttribute(VALIDATOR_KEY + config.getPrefix(),
-                                                     resources);
+            servlet.getServletContext().setAttribute(VALIDATOR_KEY
+                    + config.getPrefix(), resources);
 
-            servlet.getServletContext().setAttribute(STOP_ON_ERROR_KEY + '.' + config.getPrefix(),
-                                                     (this.stopOnFirstError ? Boolean.TRUE : Boolean.FALSE));
-
-        } catch (Exception e) {
+            servlet.getServletContext().setAttribute(STOP_ON_ERROR_KEY + '.'
+                    + config.getPrefix(),
+                    (this.stopOnFirstError ? Boolean.TRUE : Boolean.FALSE));
+        }
+        catch (Exception e) {
             log.error(e.getMessage(), e);
-            throw new UnavailableException("Cannot load a validator resource from '" + pathnames + "'");
+            throw new UnavailableException(
+                    "Cannot load a validator resource from '" + pathnames
+                            + "'");
         }
-
     }
 
     /**
-     * Gracefully shut down, releasing any resources
-     * that were allocated at initialization.
+     * Gracefully shut down, releasing any resources that were allocated at
+     * initialization.
      */
     public void destroy() {
-
         if (log.isDebugEnabled()) {
             log.debug("Destroying ValidatorPlugin");
         }
@@ -197,22 +193,27 @@
      * @throws IOException      if an input/output error is encountered
      * @throws ServletException if we cannot initialize these resources
      */
-    protected void initResources() throws IOException, ServletException {
-
-        if (pathnames == null || pathnames.length() <= 0) {
+    protected void initResources()
+            throws IOException, ServletException {
+        if ((pathnames == null) || (pathnames.length() <= 0)) {
             return;
         }
+
         StringTokenizer st = new StringTokenizer(pathnames, RESOURCE_DELIM);
 
         List urlList = new ArrayList();
+
         try {
             while (st.hasMoreTokens()) {
                 String validatorRules = st.nextToken().trim();
+
                 if (log.isInfoEnabled()) {
-                    log.info("Loading validation rules file from '" + validatorRules + "'");
+                    log.info("Loading validation rules file from '"
+                            + validatorRules + "'");
                 }
 
-                URL input = servlet.getServletContext().getResource(validatorRules);
+                URL input = servlet.getServletContext()
+                        .getResource(validatorRules);
 
                 // If the config isn't in the servlet context, try the class loader
                 // which allows the config files to be stored in a jar
@@ -223,22 +224,28 @@
                 if (input != null) {
                     urlList.add(input);
                 } else {
-                    throw new ServletException("Skipping validation rules file from '"
-                              + validatorRules + "'.  No url could be located.");
+                    throw new ServletException(
+                            "Skipping validation rules file from '"
+                                    + validatorRules
+                                    + "'.  No url could be located.");
                 }
             }
+
             int urlSize = urlList.size();
             String[] urlArray = new String[urlSize];
-            for (int urlIndex = 0;urlIndex < urlSize;urlIndex++) {
+
+            for (int urlIndex = 0; urlIndex < urlSize; urlIndex++) {
                 URL url = (URL) urlList.get(urlIndex);
+
                 urlArray[urlIndex] = url.toExternalForm();
             }
 
             this.resources = new ValidatorResources(urlArray);
-        } catch (SAXException sex) {
-            log.error("Skipping all validation",sex);
+        }
+        catch (SAXException sex) {
+            log.error("Skipping all validation", sex);
             throw new ServletException(sex);
-        } 
+        }
     }
 
     /**
@@ -247,5 +254,4 @@
     protected void destroyResources() {
         resources = null;
     }
-
 }

Modified: struts/action/trunk/src/java/org/apache/struts/validator/package.html
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/validator/package.html?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/validator/package.html (original)
+++ struts/action/trunk/src/java/org/apache/struts/validator/package.html Fri Jan 20 16:19:02 2006
@@ -2,32 +2,33 @@
 <html>
 <head>
 </head>
-  <body bgcolor="white">
- 
-<p> The validator package provides a series of classes to validate 
-   <code>ActionForm</code> type of input.</p>
- <br>
- <br>
- <img src="doc-files/validatorUML.jpg" alt="Validator Package UML" >
- <br>
- 
+
+<body bgcolor="white">
+
+<p> The validator package provides a series of classes to validate
+    <code>ActionForm</code> type of input.</p>
+<br>
+<br>
+<img src="doc-files/validatorUML.jpg" alt="Validator Package UML">
+<br>
+
 <h2>Package Specification</h2>
-      ##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####     
+##### FILL IN ANY SPECS NEEDED BY JAVA COMPATIBILITY KIT #####
 <ul>
-   <li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
-   </li>
- 
+    <li><a href="">##### REFER TO ANY FRAMEMAKER SPECIFICATION HERE #####</a>
+    </li>
+
 </ul>
- 
+
 <h2>Related Documentation</h2>
-      For overviews, tutorials, examples, guides, and tool documentation, 
-please  see:     
+For overviews, tutorials, examples, guides, and tool documentation,
+please see:
 <ul>
-   <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
-   </li>
- 
+    <li><a href="">##### REFER TO NON-SPEC DOCUMENTATION HERE #####</a>
+    </li>
+
 </ul>
- <!-- Put @see and @since tags down here. -->
-<since>Struts 1.1</since> 
+<!-- Put @see and @since tags down here. -->
+<since>Struts 1.1</since>
 </body>
 </html>

Modified: struts/action/trunk/src/java/org/apache/struts/validator/validwhen/ValidWhen.java
URL: http://svn.apache.org/viewcvs/struts/action/trunk/src/java/org/apache/struts/validator/validwhen/ValidWhen.java?rev=370938&r1=370937&r2=370938&view=diff
==============================================================================
--- struts/action/trunk/src/java/org/apache/struts/validator/validwhen/ValidWhen.java (original)
+++ struts/action/trunk/src/java/org/apache/struts/validator/validwhen/ValidWhen.java Fri Jan 20 16:19:02 2006
@@ -15,23 +15,21 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package org.apache.struts.validator.validwhen;
 
-import java.io.StringReader;
-
-import javax.servlet.http.HttpServletRequest;
-
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.apache.commons.validator.Field;
 import org.apache.commons.validator.Validator;
 import org.apache.commons.validator.ValidatorAction;
 import org.apache.commons.validator.util.ValidatorUtils;
-import org.apache.struts.action.ActionMessages;
 import org.apache.struts.action.ActionMessage;
-import org.apache.struts.validator.Resources;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.apache.struts.action.ActionMessages;
 import org.apache.struts.util.MessageResources;
+import org.apache.struts.validator.Resources;
+
+import javax.servlet.http.HttpServletRequest;
+import java.io.StringReader;
 
 /**
  * This class contains the validwhen validation that is used in the
@@ -40,18 +38,16 @@
  * @since Struts 1.2
  */
 public class ValidWhen {
-
     /**
-     *  Commons Logging instance.
+     * Commons Logging instance.
      */
     private static final Log log = LogFactory.getLog(ValidWhen.class);
 
     /**
      * The message resources for this package.
      */
-    private static MessageResources sysmsgs =
-            MessageResources.getMessageResources(
-                    "org.apache.struts.validator.LocalStrings");
+    private static MessageResources sysmsgs = MessageResources
+            .getMessageResources("org.apache.struts.validator.LocalStrings");
 
     /**
      * Returns true if <code>obj</code> is null or a String.
@@ -64,30 +60,22 @@
      * Checks if the field matches the boolean expression specified in
      * <code>test</code> parameter.
      *
-     * @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>ActionMessages</code> object to add errors to if any
-     *      validation errors occur.
-     *
+     * @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>ActionMessages</code> object to add errors to
+     *                if any validation errors occur.
      * @param request Current request object.
-     *
      * @return <code>true</code> if meets stated requirements,
-     *      <code>false</code> otherwise.
+     *         <code>false</code> otherwise.
      */
-    public static boolean validateValidWhen(
-        Object bean,
-        ValidatorAction va,
-        Field field,
-        ActionMessages errors,
-        Validator validator,
-        HttpServletRequest request) {
-
+    public static boolean validateValidWhen(Object bean, ValidatorAction va,
+                                            Field field,
+                                            ActionMessages errors,
+                                            Validator validator,
+                                            HttpServletRequest request) {
         Object form = validator.getParameterValue(Validator.BEAN_PARAM);
         String value = null;
         boolean valid = false;
@@ -100,54 +88,78 @@
             final int rightBracket = key.indexOf("]");
 
             if ((leftBracket > -1) && (rightBracket > -1)) {
-                index =
-                    Integer.parseInt(key.substring(leftBracket + 1, rightBracket));
+                index = Integer.parseInt(key.substring(leftBracket + 1,
+                        rightBracket));
             }
         }
 
         if (isString(bean)) {
             value = (String) bean;
         } else {
-            value = ValidatorUtils.getValueAsString(bean, field.getProperty());
+            value = ValidatorUtils
+                    .getValueAsString(bean, field.getProperty());
         }
 
         String test = null;
+
         try {
-            test = Resources.getVarValue("test", field, validator, request, true);
-        } catch(IllegalArgumentException ex) {
+            test = Resources
+                    .getVarValue("test", field, validator, request, true);
+        }
+        catch (IllegalArgumentException ex) {
             String logErrorMsg = sysmsgs.getMessage("validation.failed",
-                              "validwhen", field.getProperty(), ex.toString());
+                    "validwhen", field.getProperty(), ex.toString());
+
             log.error(logErrorMsg);
+
             String userErrorMsg = sysmsgs.getMessage("system.error");
-            errors.add(field.getKey(), new ActionMessage(userErrorMsg, false));
+
+            errors.add(field.getKey(),
+                    new ActionMessage(userErrorMsg, false));
+
             return false;
         }
 
         // Create the Lexer
-        ValidWhenLexer lexer= null;
+        ValidWhenLexer lexer = null;
+
         try {
             lexer = new ValidWhenLexer(new StringReader(test));
-        } catch (Exception ex) {
-            String logErrorMsg = "ValidWhenLexer Error for field ' " + field.getKey() + "' - " + ex;
+        }
+        catch (Exception ex) {
+            String logErrorMsg = "ValidWhenLexer Error for field ' "
+                    + field.getKey() + "' - " + ex;
+
             log.error(logErrorMsg);
+
             String userErrorMsg = sysmsgs.getMessage("system.error");
-            errors.add(field.getKey(), new ActionMessage(userErrorMsg, false));
+
+            errors.add(field.getKey(),
+                    new ActionMessage(userErrorMsg, false));
+
             return false;
         }
 
         // Create the Parser
         ValidWhenParser parser = null;
+
         try {
             parser = new ValidWhenParser(lexer);
-        } catch (Exception ex) {
-            String logErrorMsg = "ValidWhenParser Error for field ' " + field.getKey() + "' - " + ex;
+        }
+        catch (Exception ex) {
+            String logErrorMsg = "ValidWhenParser Error for field ' "
+                    + field.getKey() + "' - " + ex;
+
             log.error(logErrorMsg);
+
             String userErrorMsg = sysmsgs.getMessage("system.error");
-            errors.add(field.getKey(), new ActionMessage(userErrorMsg, false));
+
+            errors.add(field.getKey(),
+                    new ActionMessage(userErrorMsg, false));
+
             return false;
         }
 
-
         parser.setForm(form);
         parser.setIndex(index);
         parser.setValue(value);
@@ -155,26 +167,31 @@
         try {
             parser.expression();
             valid = parser.getResult();
+        }
+        catch (Exception ex) {
+            String logErrorMsg = "ValidWhen Error for field ' "
+                    + field.getKey() + "' - " + ex;
 
-        } catch (Exception ex) {
-
-            String logErrorMsg = "ValidWhen Error for field ' " + field.getKey() + "' - " + ex;
             log.error(logErrorMsg);
+
             String userErrorMsg = sysmsgs.getMessage("system.error");
-            errors.add(field.getKey(), new ActionMessage(userErrorMsg, false));
+
+            errors.add(field.getKey(),
+                    new ActionMessage(userErrorMsg, false));
 
             return false;
         }
 
         if (!valid) {
-            errors.add(
-                field.getKey(),
-                Resources.getActionMessage(validator, request, va, field));
+            errors.add(field.getKey(),
+                    Resources.getActionMessage(validator,
+                            request,
+                            va,
+                            field));
 
             return false;
         }
 
         return true;
     }
-
 }



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