commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dwinterfe...@apache.org
Subject cvs commit: jakarta-commons/validator/src/test/org/apache/commons/validator validator-name-required.xml
Date Wed, 13 Mar 2002 05:39:32 GMT
dwinterfeldt    02/03/12 21:39:32

  Modified:    validator/src/share/org/apache/commons/validator Arg.java
                        Constant.java Field.java Form.java FormSet.java
                        GenericValidator.java Msg.java Validator.java
                        ValidatorAction.java ValidatorException.java
                        ValidatorResources.java ValidatorUtil.java Var.java
               validator/src/test/org/apache/commons/validator
                        validator-name-required.xml
  Added:       validator/src/share/org/apache/commons/validator
                        package.html
  Log:
  Worked on javadoc comments.  Some minor code changes.
  
  Revision  Changes    Path
  1.3       +28 -13    jakarta-commons/validator/src/share/org/apache/commons/validator/Arg.java
  
  Index: Arg.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Arg.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Arg.java	17 Jan 2002 04:14:22 -0000	1.2
  +++ Arg.java	13 Mar 2002 05:39:32 -0000	1.3
  @@ -57,15 +57,26 @@
   
   package org.apache.commons.validator;
   
  +import java.io.Serializable;
  +
   
   /**
  - * <p>This class stores the replacement arguments for a message resource.</p>
  - *
  - * <ul><li>See /WEB-INF/validation.xml for validation rules.</li></ul>
  + * <p>An default argument or an argument for a 
  + * specific validator definition (ex: required) 
  + * can be stored to pass into a message as
  + * as parameters.  This can be used in a 
  + * pluggable validator for constructing locale 
  + * sensitive messages by using <code>java.text.MessageFormat</code> 
  + * or an equivalent class.  The resource field can be 
  + * used to determine if the value stored in the argument 
  + * is a value to be retrieved from a locale sensitive 
  + * message retrieval system like <code>java.util.PropertyResourceBundle</code>.
  + * The resource field defaults to 'true'.</p>
    *
    * @author David Winterfeldt
   */
  -public class Arg implements Cloneable, java.io.Serializable {
  +public class Arg implements Cloneable, Serializable {
  +
       /**
        * The name dependency that this argument goes with (optional).
       */
  @@ -80,7 +91,7 @@
        * Whether or not the key is a message resource (optional).  Defaults to true.  
        * If it is 'true', the value will try to be resolved as a message resource.
       */
  -    protected String resource = "true";
  +    protected boolean resource = true;
   
   
       /**
  @@ -114,39 +125,43 @@
       /**
        * Gets whether or not the key is a resource.
       */
  -    public String getResource() {
  +    public boolean getResource() {
          return resource;	
       }
   
       /**
        * Sets whether or not the key is a resource.
       */
  -    public void setResource(String resource) {
  +    public void setResource(boolean resource) {
          this.resource = resource;	
       }
   
  +    /**
  +     * Creates and returns a copy of this object.
  +    */
       public Object clone() {
          try {
              Arg arg = (Arg)super.clone();
   
              if (name != null) {
  -              arg.name = new String(name);
  +              arg.setName(new String(name));
              }
                 
              if (key != null) {
  -              arg.key = new String(key);
  +              arg.setKey(new String(key));
              }
              
  -           if (resource != null) {
  -              arg.resource = new String(resource);
  -           }
  +           arg.setResource(resource);
   
              return arg;
          } catch (CloneNotSupportedException e) {
             throw new InternalError(e.toString());
          }
       }  
  -          
  +    
  +    /**
  +     * Returns a string representation of the object.
  +    */
       public String toString() {
          StringBuffer results = new StringBuffer();
          
  
  
  
  1.2       +16 -8     jakarta-commons/validator/src/share/org/apache/commons/validator/Constant.java
  
  Index: Constant.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Constant.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Constant.java	6 Jan 2002 05:08:43 -0000	1.1
  +++ Constant.java	13 Mar 2002 05:39:32 -0000	1.2
  @@ -57,19 +57,24 @@
   
   package org.apache.commons.validator;
   
  +import java.io.Serializable;
  +
   
   /**
  - * <p>Used in the Validation framework for creating a constant.  A constant can be 
  - * used to define a global or locale level constant that can be used to replace 
  - * some values in the <code>Field</code> class.<BR>
  - * &nbsp;&nbsp;&nbsp;ex: &lt;constant name="zip" value="^\d{5}$" /&gt;<BR>
  + * <p>A constant can be used to define a global or 
  + * locale level constant that can be used to replace 
  + * values in certain fields.  The <code>Field</code>'s 
  + * property field, the <code>Var</code>'s value field, 
  + * the <code>Msg</code>'s key field, and the <code>Arg</code>'s 
  + * key field can all contain constants reference for replacement.
  + * <br>
  + * &nbsp;&nbsp;&nbsp;ex: &lt;constant name="zip" value="^\d{5}$" /&gt;<br>
    * &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;mask="${zip}" </p>
    *
  - * <ul><li>See /WEB-INF/validation.xml for validation rules.</li></ul>
  - *
    * @author David Winterfeldt
   */
  -public class Constant implements java.io.Serializable {
  +public class Constant implements Serializable {
  +
       /**
        * The name of the constant.
       */
  @@ -107,7 +112,10 @@
       public void setValue(String value) {
          this.value = value;	
       }
  -       
  +
  +    /**
  +     * Returns a string representation of the object.
  +    */       
       public String toString() {
          StringBuffer results = new StringBuffer();
       	
  
  
  
  1.3       +20 -40    jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java
  
  Index: Field.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Field.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Field.java	15 Jan 2002 06:06:24 -0000	1.2
  +++ Field.java	13 Mar 2002 05:39:32 -0000	1.3
  @@ -67,20 +67,24 @@
   
   
   /**
  - * <p>Used in the Validation framework.</p>
  - *
  - * <ul><li>See /WEB-INF/validation.xml for validation rules.</li></ul>
  + * <p>This contains the list of pluggable validators to 
  + * run on a field and any message information and variables
  + * to perform the validations and generate error messages.</p>
    *
    * @author David Winterfeldt
    * @see org.apache.commons.validator.Form
   */
   public class Field implements Cloneable, Serializable {
  +
       /**
        * This is the value that will be used as a key if the <code>Arg</code> 
        * name field has no value.
       */
       public final static String ARG_DEFAULT = "org.apache.commons.validator.Field.DEFAULT";
       
  +    /**
  +     * This indicates an indexed property is being referenced.
  +    */
       public final static String TOKEN_INDEXED = "[]";
       
       protected final static String TOKEN_START = "${";
  @@ -560,6 +564,9 @@
          return Collections.unmodifiableMap(hDependencies).keySet();
       }
   
  +    /**
  +     * Creates and returns a copy of this object.
  +    */
       public Object clone() {
          try {
              Field field = (Field)super.clone();
  @@ -586,50 +593,23 @@
   
              // page & fieldOrder should be taken care of by clone method
              
  -           field.hDependencies = copyFastHashMap(hDependencies);
  -           field.hVars = copyFastHashMap(hVars);
  -           field.hMsgs = copyFastHashMap(hMsgs);
  -           field.hArg0 = copyFastHashMap(hArg0);
  -           field.hArg1 = copyFastHashMap(hArg1);
  -           field.hArg2 = copyFastHashMap(hArg2);
  -           field.hArg3 = copyFastHashMap(hArg3);
  +           field.hDependencies = ValidatorUtil.copyFastHashMap(hDependencies);
  +           field.hVars = ValidatorUtil.copyFastHashMap(hVars);
  +           field.hMsgs = ValidatorUtil.copyFastHashMap(hMsgs);
  +           field.hArg0 = ValidatorUtil.copyFastHashMap(hArg0);
  +           field.hArg1 = ValidatorUtil.copyFastHashMap(hArg1);
  +           field.hArg2 = ValidatorUtil.copyFastHashMap(hArg2);
  +           field.hArg3 = ValidatorUtil.copyFastHashMap(hArg3);
       
              return field;
          } catch (CloneNotSupportedException e) {
             throw new InternalError(e.toString());
          }
       }    
  -    
  -    /**
  -     * Makes a deep copy of a <code>FastHashMap</code> if the values 
  -     * are <code>String</code>, <code>Msg</code>, <code>Arg</code>, 
  -     * or <code>Var</code>.  Otherwise it is a shallow copy.
  -    */
  -    public FastHashMap copyFastHashMap(FastHashMap map) {
  -       FastHashMap hResults = new FastHashMap();
  -       
  -       for (Iterator i = map.keySet().iterator(); i.hasNext(); ) {
  -          String key = (String)i.next();
  -          Object value = map.get(key);
   
  -       	  if (value instanceof String) {
  -       	     hResults.put(key, new String((String)value));
  -       	  } else if (value instanceof Msg) {
  -       	     hResults.put(key, ((Msg)value).clone());
  -       	  } else if (value instanceof Arg) {
  -       	     hResults.put(key, ((Arg)value).clone());
  -       	  } else if (value instanceof Var) {
  -       	     hResults.put(key, ((Var)value).clone());
  -          } else {
  -             hResults.put(key, value);	
  -          }
  -       }
  -       
  -       hResults.setFast(true);
  -       
  -       return hResults;
  -    }
  -    
  +    /**
  +     * Returns a string representation of the object.
  +    */       
       public String toString() {
          StringBuffer results = new StringBuffer();
          
  
  
  
  1.2       +16 -11    jakarta-commons/validator/src/share/org/apache/commons/validator/Form.java
  
  Index: Form.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Form.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Form.java	6 Jan 2002 05:08:43 -0000	1.1
  +++ Form.java	13 Mar 2002 05:39:32 -0000	1.2
  @@ -67,21 +67,25 @@
   
   
   /**
  - * <p>Used in the Validation framework.</p>
  - *
  - * <ul><li>See /WEB-INF/validation.xml for validation rules.</li></ul>
  + * <p>This contains a set of validation rules for a 
  + * form/JavaBean.  The information is contained in a 
  + * list of <code>Field</code> objects.</p>
    *
    * @author David Winterfeldt
   */
   public class Form implements Serializable {
  +
       /**
  -     * The name of the form should match the form name in the action configuration 
  -     * in the struts-config.xml file.
  +     * The name/key the set of validation rules is 
  +     * stored under.
       */
       protected String name = null;
   
       /**
  -     * List of <code>Field</code>s.  Used to maintain the order they were added in.
  +     * List of <code>Field</code>s.  Used to maintain 
  +     * the order they were added in although individual 
  +     * <code>Field</code>s can be retrieved using 
  +     * <code>Map</code> of <code>Field</code>s.
       */
       protected List lFields = new ArrayList();
       
  @@ -91,16 +95,14 @@
       protected FastHashMap hFields = new FastHashMap();
   
       /**
  -     * Gets the name of the form.  It should match the form name in 
  -     * the action configuration in the struts-config.xml file.
  +     * Gets the name/key of the set of validation rules.
       */
       public String getName() {
          return name;	
       }
   
       /**
  -     * Sets the name of the form.  It should match the form name in 
  -     * the action configuration in the struts-config.xml file.
  +     * Sets the name/key of the set of validation rules.
       */
       public void setName(String name) {
          this.name = name;	
  @@ -144,7 +146,10 @@
          	  f.process(globalConstants, constants);
          }
       }
  -    
  +
  +    /**
  +     * Returns a string representation of the object.
  +    */    
       public String toString() {
          StringBuffer results = new StringBuffer();
          
  
  
  
  1.4       +14 -6     jakarta-commons/validator/src/share/org/apache/commons/validator/FormSet.java
  
  Index: FormSet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/FormSet.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FormSet.java	17 Jan 2002 04:14:22 -0000	1.3
  +++ FormSet.java	13 Mar 2002 05:39:32 -0000	1.4
  @@ -65,14 +65,14 @@
   
   
   /**
  - * <p>Used in the Validation framework.  It holds a set of <code>Form</code>s 
  - * stored associated with a <code>Locale</code>.</p>
  - *
  - * <ul><li>See /WEB-INF/validation.xml for validation rules.</li></ul>
  + * <p>Holds a set of <code>Form</code>s 
  + * stored associated with a <code>Locale</code> based 
  + * on the country, language, and variant specified.</p>
    *
    * @author David Winterfeldt
   */
   public class FormSet implements Serializable {
  +    
       /**
        * Whether or not the this <code>FormSet</code> was processed 
        * for replacing variables in strings with their values.
  @@ -94,10 +94,15 @@
       */
       private String variant = null;
       
  +    /**
  +     * A <code>FastHashMap</code> of <code>Form</code>s 
  +     * using the name field of the <code>Form</code> as the key.
  +    */
       private FastHashMap hForms = new FastHashMap();
   
       /**
  -     * Constants
  +     * A <code>FastHashMap</code> of <code>Constant</code>s 
  +     * using the name field of the <code>Constant</code> as the key.
       */
       private FastHashMap hConstants = new FastHashMap();
   
  @@ -205,7 +210,10 @@
          
          bProcessed = true;
       }
  -    
  +
  +    /**
  +     * Returns a string representation of the object.
  +    */    
       public String toString() {
          StringBuffer results = new StringBuffer();
       
  
  
  
  1.3       +2 -1      jakarta-commons/validator/src/share/org/apache/commons/validator/GenericValidator.java
  
  Index: GenericValidator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/GenericValidator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- GenericValidator.java	17 Jan 2002 04:14:22 -0000	1.2
  +++ GenericValidator.java	13 Mar 2002 05:39:32 -0000	1.3
  @@ -68,7 +68,8 @@
   
   
   /**
  - * <p>This class performs validations.</p>
  + * <p>This class contains basic methods for 
  + * performing validations.</p>
    *
    * @author David Winterfeldt
   */
  
  
  
  1.3       +16 -7     jakarta-commons/validator/src/share/org/apache/commons/validator/Msg.java
  
  Index: Msg.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Msg.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Msg.java	17 Jan 2002 04:14:22 -0000	1.2
  +++ Msg.java	13 Mar 2002 05:39:32 -0000	1.3
  @@ -57,15 +57,18 @@
   
   package org.apache.commons.validator;
   
  +import java.io.Serializable;
  +
   
   /**
  - * <p>This class can be used to supply an alternative message for a pluggable validator.</p>
  - *
  - * <ul><li>See /WEB-INF/validation.xml for validation rules.</li></ul>
  + * <p>An alternative message can be associated with a <code>Field</code> 
  + * and a pluggable validator instead of using the default message 
  + * stored in the <code>ValidatorAction</code> (aka pluggable validator).</p>
    *
    * @author David Winterfeldt
   */
  -public class Msg implements Cloneable, java.io.Serializable {
  +public class Msg implements Cloneable, Serializable {
  +    
       /**
        * The name dependency that this argument goes with (optional).
       */
  @@ -104,16 +107,19 @@
          this.key = key;	
       }
   
  +    /**
  +     * Creates and returns a copy of this object.
  +    */
       public Object clone() {
          try {
              Msg msg = (Msg)super.clone();
              
              if (key != null) {
  -              msg.name = new String(name);
  +              msg.setName(new String(name));
              }
              
              if (key != null) {
  -              msg.key = new String(key);
  +              msg.setKey(new String(key));
              }
   
              return msg;
  @@ -121,7 +127,10 @@
             throw new InternalError(e.toString());
          }
       }  
  -        
  +
  +    /**
  +     * Returns a string representation of the object.
  +    */
       public String toString() {
          StringBuffer results = new StringBuffer();
          
  
  
  
  1.4       +93 -7     jakarta-commons/validator/src/share/org/apache/commons/validator/Validator.java
  
  Index: Validator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Validator.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Validator.java	17 Jan 2002 04:14:22 -0000	1.3
  +++ Validator.java	13 Mar 2002 05:39:32 -0000	1.4
  @@ -76,8 +76,10 @@
   
   
   /**
  - * <p>This class performs validations.  The methods are can be configured to be 
  - * used in the framework in the validation.xml file.  (See example webapp)</p>
  + * <p>Validations are processed by the validate method.  
  + * An instance of <code>ValidatorResources</code> is 
  + * used to define the validators (validation methods) 
  + * and the validation rules for a JavaBean.</p>
    *
    * @author David Winterfeldt
   */
  @@ -101,25 +103,107 @@
      protected String formName = null;
      protected HashMap hResources = new HashMap();
      protected int page = 0;   
  -   
  +
  +   /**
  +    * Construct a <code>Validator</code> that will 
  +    * use the <code>ValidatorResources</code> 
  +    * passed in to retrieve pluggable validators 
  +    * the different sets of validation rules.
  +    *
  +    * @param	resources	<code>ValidatorResources</code> 
  +    *				to use during validation.
  +   */
  +   public Validator(ValidatorResources resources) {
  +      this.resources = resources;
  +   }
  +
  +   /**
  +    * Construct a <code>Validator</code> that will 
  +    * use the <code>ValidatorResources</code> 
  +    * passed in to retrieve pluggable validators 
  +    * the different sets of validation rules.
  +    *
  +    * @param	resources	<code>ValidatorResources</code> 
  +    *				to use during validation.
  +    * @param	formName	Key used for retrieving the set of 
  +    *				validation rules.
  +   */
      public Validator(ValidatorResources resources, String formName) {
         this.resources = resources;
         this.formName = formName;
      }
      
  +   /**
  +    * Add a resource to be used during the processing 
  +    * of validations.
  +    *
  +    * @param	key		The full class name of the parameter 
  +    *				of the validation method that 
  +    *				corresponds to the value/instance 
  +    *				passed in with it.
  +    * @param	value		The instance that will be passed 
  +    *				into the validation method.
  +   */
      public void addResource(String key, Object value) {
         hResources.put(key, value);
      }
  +
  +   /**
  +    * Gets the form name which is the key 
  +    * to a set of validation rules.
  +   */
  +   public String getFormName() {
  +      return formName;	
  +   }
      
  -   public void setPage(int page) {
  -      this.page = page;	
  +   /**
  +    * Sets the form name which is the key 
  +    * to a set of validation rules.
  +   */
  +   public void setFormName(String formName) {
  +      this.formName = formName;	
      }
   
  +   /**
  +    * Gets the 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 int getPage() {
         return page;	
      }
      
      /**
  +    * Sets the 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 void setPage(int page) {
  +      this.page = page;	
  +   }
  +
  +   /**
  +    * Clears the form name, resources that were added, 
  +    * and the page that was set (if any).  This can 
  +    * be called to reinitialize the Validator instance 
  +    * so it can be reused.  The form name (key to 
  +    * set of validation rules) and any resources needed, 
  +    * like the JavaBean being validated, will need to 
  +    * set and/or added to this instance again.  The 
  +    * <code>ValidatorResources</code> will not be removed 
  +    * since it can be used again and is thread safe.
  +   */
  +   public void clear() {
  +      formName = null;
  +      hResources = new HashMap();
  +      page = 0;   
  +   }
  +      
  +   /**
       * Performs validations based on the configured resources.  
       * 
       * @return	The <code>Map</code> returned uses the property 
  @@ -130,11 +214,13 @@
         Map hResults = new HashMap();
         Locale locale = null;
         
  -      if (hResources.containsKey(LOCALE_KEY))
  +      if (hResources.containsKey(LOCALE_KEY)) {
            locale = (Locale)hResources.get(LOCALE_KEY);
  +      }
         
  -      if (locale == null)
  +      if (locale == null) {
            locale = Locale.getDefault();
  +      }
            
         Form form = null;
         if ((form = resources.get(locale, formName)) != null) {	    
  
  
  
  1.3       +302 -239  jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorAction.java
  
  Index: ValidatorAction.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ValidatorAction.java	17 Jan 2002 04:14:22 -0000	1.2
  +++ ValidatorAction.java	13 Mar 2002 05:39:32 -0000	1.3
  @@ -68,250 +68,313 @@
   
   
   /**
  - * <p>Used in the Validation framework.  Reference to the class and method to perform 
  - * a validation.  Used to dynamically instantiate and run a validation method defined 
  - * in the validation.xml file.<BR>
  - * &nbsp;&nbsp;&nbsp; Note: The validation method is assumed to be thread safe.</p>
  - *
  - * <ul><li>See /WEB-INF/validation.xml for validation rules.</li></ul>
  + * <p>Contains the information to dynamically instantiate 
  + * and run a validation method.  This is the class 
  + * representation of a pluggable validator that can be defined 
  + * in an xml file.<br>
  + * &nbsp;&nbsp;&nbsp; Note: The validation method is assumed 
  + * to be thread safe.</p>
    *
    * @author David Winterfeldt
   */
   public class ValidatorAction implements Serializable {
  -    /**
  -     * The name of the validation.
  -    */
  -    private String name = null;
  -
  -    private String classname = null;
  -    private String method = null; 
  -
  -    // Default for Struts
  -    private String methodParams = Validator.BEAN_KEY + "," + 
  -    				  Validator.VALIDATOR_ACTION_KEY + "," + 
  -    				  Validator.FIELD_KEY + "," + 
  -    				  Validator.ACTION_ERRORS_KEY + "," + 
  -    				  Validator.HTTP_SERVLET_REQUEST_KEY + "," + 
  -    				  Validator.SERVLET_CONTEXT_KEY; 
  -    private String depends = null;       
  -    private String msg = null;    
  -    private String jsFunctionName = null;
  -    private String javascript = null;
  -
  -    private Object instance = null;
  -    
  -
  -    private FastHashMap hDependencies = new FastHashMap();   
  -    private List lMethodParams = new ArrayList();   
  -
  -    /**
  -     * Gets the name of the validator action.
  -    */
  -    public String getName() {
  -       return name;	
  -    }
  -
  -    /**
  -     * Sets the name of the validator action.
  -    */
  -    public void setName(String name) {
  -       this.name = name;	
  -    }
  -
  -    /**
  -     * Gets the class of the validator action.
  -    */
  -    public String getClassname() {
  -       return classname;	
  -    }
  -
  -    /**
  -     * Sets the class of the validator action.
  -    */
  -    public void setClassname(String classname) {
  -       this.classname = classname;	
  -    }
  -
  -    /**
  -     * Gets the name of method being called for the validator action.
  -    */
  -    public String getMethod() {
  -       return method;	
  -    }
  -
  -    /**
  -     * Sets the name of method being called for the validator action.
  -    */
  -    public void setMethod(String method) {
  -       this.method = method;	
  -    }
  -    
  -    /**
  -     * Gets the method parameters for the method.
  -    */
  -    public String getMethodParams() {
  -       return methodParams;	
  -    }
  -
  -    /**
  -     * Sets the method parameters for the method.
  -    */
  -    public void setMethodParams(String methodParams) {
  -       this.methodParams = methodParams;	
  -    }
  -
  -    /**
  -     * Gets the method parameters for the method.
  -    */
  -    public List getMethodParamsList() {
  -       return Collections.unmodifiableList(lMethodParams);
  -    }
  -    
  -    /**
  -     * Gets the dependencies of the validator action.
  -    */
  -    public String getDepends() {
  -       return depends;	
  -    }
  -
  -    /**
  -     * Sets the dependencies of the validator action.
  -    */
  -    public void setDepends(String depends) {
  -       this.depends = depends;	
  -    }
  -
  -    /**
  -     * Gets the resource message associated with the validator action.
  -    */
  -    public String getMsg() {
  -       return msg;	
  -    }
  -
  -    /**
  -     * Sets the resource message associated with the validator action.
  -    */
  -    public void setMsg(String msg) {
  -       this.msg = msg;	
  -    }
  -
  -    /**
  -     * Gets the Javascript function name.  This is optional and will 
  -     * be used instead of validator action name for the name of the 
  -     * Javascript function/object.
  -    */
  -    public String getJsFunctionName() {
  -       return jsFunctionName;	
  -    }
  -
  -    /**
  -     * Sets the Javascript function name.  This is optional and will 
  -     * be used instead of validator action name for the name of the 
  -     * Javascript function/object.
  -    */
  -    public void setJsFunctionName(String jsFunctionName) {
  -       this.jsFunctionName = jsFunctionName;	
  -    }
  -    
  -    /**
  -     * Gets the Javascript equivalent of the java class and method 
  -     * associated with this action.
  -    */
  -    public String getJavascript() {
  -       return javascript;	
  -    }
  -
  -    /**
  -     * Sets the Javascript equivalent of the java class and method 
  -     * associated with this action.
  -    */
  -    public void setJavascript(String javascript) {
  -       this.javascript = javascript;	
  -    }
  -
  -    /**
  -     * Gets an instance based on the validator action's classname.
  -    */
  -    public Object getClassnameInstance() {
  -       return instance;	
  -    }
  -
  -    /**
  -     * Sets an instance based on the validator action's classname.
  -    */
  -    public void setClassnameInstance(Object instance) {
  -       this.instance = instance;	
  -    }
  -
  -    /**
  -     * Creates a <code>FastHashMap</code> for the isDependency method 
  -     * based on depends.
  -    */
  -    public synchronized void process(Map globalConstants) {
  -       // Create FastHashMap for isDependency method
  -       if (getDepends() != null) {
  -       	  if (hDependencies == null) {
  -       	     hDependencies = new FastHashMap();
  -       	  }
  -       	     
  -          StringTokenizer st = new StringTokenizer(getDepends(), ",");
  -          String value = "";
  -          while (st.hasMoreTokens()) {
  -             String depend = st.nextToken().trim();
  -             
  -             if (depend != null && depend.length() > 0) {
  -                hDependencies.put(depend, value);
  -             }
  -          
  -          }
  -              
  -          hDependencies.setFast(true);
  -       }
  -       
  -       // Create List for methodParams
  -       if (getMethodParams() != null) {
  -       	  if (lMethodParams == null) {
  -       	     lMethodParams = new ArrayList();
  -       	  }
  -       	     
  -          StringTokenizer st = new StringTokenizer(getMethodParams(), ",");
   
  -          while (st.hasMoreTokens()) {
  -             String value = st.nextToken().trim();
  +   /**
  +    * The name of the validation.
  +   */
  +   private String name = null;
  +
  +   /**
  +    * The full class name of the class containing 
  +    * the validation method associated with 
  +    * this action.
  +   */   
  +   private String classname = null;
  +   
  +   /**
  +    * The full method name of the validation 
  +    * to be performed.  The method must be 
  +    * thread safe.
  +   */
  +   private String method = null; 
  +
  +   // Default for Struts
  +   /**
  +    * <p>The method signature of the validation method.  This 
  +    * should be a comma delimited list of the full 
  +    * class names of each parameter that the method takes.</p>
  +    *
  +    * <p>Note: <code>java.lang.Object</code> is reserved for the 
  +    * JavaBean that is being validated.  The <code>ValidatorAction</code> 
  +    * and <code>Field</code> that are associated with a fields 
  +    * validation will automatically be populated if they are 
  +    * specified in the method signature.</p>
  +   */
  +   private String methodParams = Validator.BEAN_KEY + "," + 
  +   				  Validator.VALIDATOR_ACTION_KEY + "," + 
  +   				  Validator.FIELD_KEY + "," + 
  +   				  Validator.ACTION_ERRORS_KEY + "," + 
  +   				  Validator.HTTP_SERVLET_REQUEST_KEY + "," + 
  +   				  Validator.SERVLET_CONTEXT_KEY; 
  +   
  +   /**
  +    * The other <code>ValidatorAction</code>s that this
  +    * one depends on.  If any errors occur in an action 
  +    * that this one depends on, this action will not 
  +    * be processsed.
  +   */
  +   private String depends = null;       
  +   
  +   /**
  +    * The default error message associated with 
  +    * this action.
  +   */
  +   private String msg = null;    
  +   
  +   /**
  +    * An optional field to contain the name to be 
  +    * used if JavaScript is generated.
  +   */
  +   private String jsFunctionName = null;
  +
  +   /**
  +    * An optional field to containing a 
  +    * JavaScript representation of the 
  +    * java method assocated with this action.
  +   */
  +   private String javascript = null;
  +
  +   /**
  +    * If the java method matching the correct 
  +    * signature isn't static, the instance is 
  +    * stored in the action.  This assumes the 
  +    * method is thread safe.
  +   */
  +   private Object instance = null;
  +   
  +   /**
  +    * A <code>FastHashMap</code> of the other 
  +    * <code>ValiadtorAction</code>s this one depends
  +    * on (if any).
  +   */
  +   private FastHashMap hDependencies = new FastHashMap();   
  +   
  +   /**
  +    * A list of all the validation method's parameters.
  +   */
  +   private List lMethodParams = new ArrayList();   
  +
  +   /**
  +    * Gets the name of the validator action.
  +   */
  +   public String getName() {
  +      return name;	
  +   }
  +
  +   /**
  +    * Sets the name of the validator action.
  +   */
  +   public void setName(String name) {
  +      this.name = name;	
  +   }
  +
  +   /**
  +    * Gets the class of the validator action.
  +   */
  +   public String getClassname() {
  +      return classname;	
  +   }
  +
  +   /**
  +    * Sets the class of the validator action.
  +   */
  +   public void setClassname(String classname) {
  +      this.classname = classname;	
  +   }
  +
  +   /**
  +    * Gets the name of method being called for the validator action.
  +   */
  +   public String getMethod() {
  +      return method;	
  +   }
  +
  +   /**
  +    * Sets the name of method being called for the validator action.
  +   */
  +   public void setMethod(String method) {
  +      this.method = method;	
  +   }
  +   
  +   /**
  +    * Gets the method parameters for the method.
  +   */
  +   public String getMethodParams() {
  +      return methodParams;	
  +   }
  +
  +   /**
  +    * Sets the method parameters for the method.
  +   */
  +   public void setMethodParams(String methodParams) {
  +      this.methodParams = methodParams;	
  +   }
  +
  +   /**
  +    * Gets the method parameters for the method.
  +   */
  +   public List getMethodParamsList() {
  +      return Collections.unmodifiableList(lMethodParams);
  +   }
  +   
  +   /**
  +    * Gets the dependencies of the validator action.
  +   */
  +   public String getDepends() {
  +      return depends;	
  +   }
  +
  +   /**
  +    * Sets the dependencies of the validator action.
  +   */
  +   public void setDepends(String depends) {
  +      this.depends = depends;	
  +   }
  +
  +   /**
  +    * Gets the message associated with the validator action.
  +   */
  +   public String getMsg() {
  +      return msg;	
  +   }
  +
  +   /**
  +    * Sets the message associated with the validator action.
  +   */
  +   public void setMsg(String msg) {
  +      this.msg = msg;	
  +   }
  +
  +   /**
  +    * Gets the Javascript function name.  This is optional and can 
  +    * be used instead of validator action name for the name of the 
  +    * Javascript function/object.
  +   */
  +   public String getJsFunctionName() {
  +      return jsFunctionName;	
  +   }
  +
  +   /**
  +    * Sets the Javascript function name.  This is optional and can 
  +    * be used instead of validator action name for the name of the 
  +    * Javascript function/object.
  +   */
  +   public void setJsFunctionName(String jsFunctionName) {
  +      this.jsFunctionName = jsFunctionName;	
  +   }
  +   
  +   /**
  +    * Gets the Javascript equivalent of the java class and method 
  +    * associated with this action.
  +   */
  +   public String getJavascript() {
  +      return javascript;	
  +   }
  +
  +   /**
  +    * Sets the Javascript equivalent of the java class and method 
  +    * associated with this action.
  +   */
  +   public void setJavascript(String javascript) {
  +      this.javascript = javascript;	
  +   }
  +
  +   /**
  +    * Gets an instance based on the validator action's classname.
  +   */
  +   public Object getClassnameInstance() {
  +      return instance;	
  +   }
  +
  +   /**
  +    * Sets an instance based on the validator action's classname.
  +   */
  +   public void setClassnameInstance(Object instance) {
  +      this.instance = instance;	
  +   }
  +
  +   /**
  +    * Creates a <code>FastHashMap</code> for the isDependency method 
  +    * based on depends.
  +   */
  +   public synchronized void process(Map globalConstants) {
  +      // Create FastHashMap for isDependency method
  +      if (getDepends() != null) {
  +      	  if (hDependencies == null) {
  +      	     hDependencies = new FastHashMap();
  +      	  }
  +      	     
  +         StringTokenizer st = new StringTokenizer(getDepends(), ",");
  +         String value = "";
  +         while (st.hasMoreTokens()) {
  +            String depend = st.nextToken().trim();
  +            
  +            if (depend != null && depend.length() > 0) {
  +               hDependencies.put(depend, value);
  +            }
  +         
  +         }
                
  -             if (value != null && value.length() > 0) {
  -                lMethodParams.add(value);
  -             }
  -          }
  -       }
  -    }
  -
  -    /**
  -     * Checks whether or not the value passed in is in the depends field.
  -    */
  -    public boolean isDependency(String key) {
  -       if (hDependencies != null) {
  -          return hDependencies.containsKey(key);	
  -       } else {
  -          return false;
  -       }
  -    }
  -
  -    /**
  -     * Gets the dependencies as a <code>Collection</code>.
  -    */
  -    public Collection getDependencies() {
  -       return Collections.unmodifiableMap(hDependencies).keySet();
  -    }
  -    
  -    public String toString() {
  -       StringBuffer results = new StringBuffer();
  -       
  -       results.append("ValidatorAction: ");
  -       results.append(name);
  -       results.append("\n");
  -    
  -       return results.toString();
  -    }
  +         hDependencies.setFast(true);
  +      }
  +      
  +      // Create List for methodParams
  +      if (getMethodParams() != null) {
  +      	  if (lMethodParams == null) {
  +      	     lMethodParams = new ArrayList();
  +      	  }
  +      	     
  +         StringTokenizer st = new StringTokenizer(getMethodParams(), ",");
  +
  +         while (st.hasMoreTokens()) {
  +            String value = st.nextToken().trim();
  +            
  +            if (value != null && value.length() > 0) {
  +               lMethodParams.add(value);
  +            }
  +         }
  +      }
  +   }
  +
  +   /**
  +    * Checks whether or not the value passed in is in the depends field.
  +   */
  +   public boolean isDependency(String key) {
  +      if (hDependencies != null) {
  +         return hDependencies.containsKey(key);	
  +      } else {
  +         return false;
  +      }
  +   }
  +
  +   /**
  +    * Gets the dependencies as a <code>Collection</code>.
  +   */
  +   public Collection getDependencies() {
  +      return Collections.unmodifiableMap(hDependencies).keySet();
  +   }
  +
  +   /**
  +    * Returns a string representation of the object.
  +   */
  +   public String toString() {
  +      StringBuffer results = new StringBuffer();
  +      
  +      results.append("ValidatorAction: ");
  +      results.append(name);
  +      results.append("\n");
  +   
  +      return results.toString();
  +   }
   	
   }
  
  
  
  1.2       +13 -1     jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorException.java
  
  Index: ValidatorException.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorException.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ValidatorException.java	6 Jan 2002 05:08:43 -0000	1.1
  +++ ValidatorException.java	13 Mar 2002 05:39:32 -0000	1.2
  @@ -61,14 +61,26 @@
   
   
   /**
  - * <p>Exception for the Validator Framework.</p>
  + * <p>Exception for the Validator Framework.  All other 
  + * <code>Exception</code>s thrown while the 
  + * <code>Validator</code>'s validate method is being 
  + * called will be considered errors.  A 
  + * <code>ValidatorException</code> will be thrown.</p>
    *
    * @author David Winterfeldt
   */
   public class ValidatorException extends Exception implements Serializable{
   
  +   /**
  +    * Constructs an Exception with no specified detail message.
  +   */
      public ValidatorException() {}
      
  +   /**
  +    * Constructs an Exception with the specified detail message.
  +    * 
  +    * @param	message		The error message.
  +   */
      public ValidatorException(String message) {
         super(message);	
      }
  
  
  
  1.4       +9 -10     jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java
  
  Index: ValidatorResources.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorResources.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ValidatorResources.java	17 Jan 2002 04:14:22 -0000	1.3
  +++ ValidatorResources.java	13 Mar 2002 05:39:32 -0000	1.4
  @@ -224,8 +224,6 @@
               ((country != null && country.length() > 0) ? "_" + country : "") + 
               ((variant != null && variant.length() > 0) ? "_" + variant : "");
         
  -      //System.out.println("ValidatorResources::get #1 - locale=" + locale.toString() + "  key=" + key);
  -      
         o = hFormSets.get(key);
         if (o != null) {
            fs = (FormSet)o;
  @@ -237,8 +235,6 @@
            key = ((language != null && language.length() > 0) ? language : "") + 
                  ((country != null && country.length() > 0) ? "_" + country : "");
            
  -         //System.out.println("ValidatorResources::get #2 - locale=" + locale.toString() + "  key=" + key);
  -         
            o = hFormSets.get(key);
            if (o != null) {
               fs = (FormSet)o;
  @@ -251,8 +247,6 @@
         if (f == null) {
            key = ((language != null && language.length() > 0) ? language : "");
            
  -         //System.out.println("ValidatorResources::get #3 - locale=" + locale.toString() + "  key=" + key);
  -         
            o = hFormSets.get(key);
            if (o != null) {
               fs = (FormSet)o;
  @@ -262,9 +256,7 @@
         }
         
         if (f == null) {
  -         key = Locale.getDefault().toString();
  -         
  -         //System.out.println("ValidatorResources::get #4 - locale=" + locale.toString() + "  key=" + key);
  +         key = defaultLocale.toString();
            
            o = hFormSets.get(key);
            if (o != null) {
  @@ -342,12 +334,19 @@
         for (Iterator i = hFormSets.values().iterator(); i.hasNext(); ) {
         	  FormSet fs = (FormSet)i.next();
    
  -         if (!fs.isProcessed())
  +         if (!fs.isProcessed()) {
               fs.process(hConstants);
  +         }
         }
    
      }
   
  +   /**
  +    * Retrieves the closest matching <code>Field</code> based 
  +    * on <code>FormSet</code>'s locale.  This is used when 
  +    * constructing a clone, field by field, of partial 
  +    * <code>FormSet</code>.
  +   */
      protected Field getClosestLocaleField(FormSet fs, String formKey, String fieldKey) {
         Field field = null;
         String language = fs.getLanguage();
  
  
  
  1.3       +38 -2     jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorUtil.java
  
  Index: ValidatorUtil.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/ValidatorUtil.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ValidatorUtil.java	17 Jan 2002 04:14:22 -0000	1.2
  +++ ValidatorUtil.java	13 Mar 2002 05:39:32 -0000	1.3
  @@ -57,14 +57,16 @@
   
   package org.apache.commons.validator;
   
  +import java.util.Iterator;
  +import java.util.Map;
   import org.apache.commons.beanutils.PropertyUtils;
  +import org.apache.commons.collections.FastHashMap; 
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogSource;
   
   
   /**
  - * <p>This class helps provides some useful methods for retrieving objects 
  - * from different scopes of the application.</p>
  + * <p>Basic utility methods.</p>
    *
    * @author David Winterfeldt
   */
  @@ -116,6 +118,40 @@
         }
      	
         return (value != null ? value.toString() : null);    	
  +   }
  +
  +   /**
  +    * Makes a deep copy of a <code>FastHashMap</code> if the values 
  +    * are <code>String</code>, <code>Msg</code>, <code>Arg</code>, 
  +    * or <code>Var</code>.  Otherwise it is a shallow copy.
  +    * 
  +    * @param	map		<code>FastHashMap</code> to copy.
  +    * @return 	FastHashMap	A copy of the <code>FastHashMap</code> 
  +    *				that was passed in.
  +   */
  +   public static FastHashMap copyFastHashMap(FastHashMap map) {
  +      FastHashMap hResults = new FastHashMap();
  +      
  +      for (Iterator i = map.keySet().iterator(); i.hasNext(); ) {
  +         String key = (String)i.next();
  +         Object value = map.get(key);
  +
  +      	  if (value instanceof String) {
  +      	     hResults.put(key, new String((String)value));
  +      	  } else if (value instanceof Msg) {
  +      	     hResults.put(key, ((Msg)value).clone());
  +      	  } else if (value instanceof Arg) {
  +      	     hResults.put(key, ((Arg)value).clone());
  +      	  } else if (value instanceof Var) {
  +      	     hResults.put(key, ((Var)value).clone());
  +         } else {
  +            hResults.put(key, value);	
  +         }
  +      }
  +      
  +      hResults.setFast(true);
  +      
  +      return hResults;
      }
      
   }
  
  
  
  1.3       +22 -16    jakarta-commons/validator/src/share/org/apache/commons/validator/Var.java
  
  Index: Var.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/share/org/apache/commons/validator/Var.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Var.java	15 Jan 2002 06:06:24 -0000	1.2
  +++ Var.java	13 Mar 2002 05:39:32 -0000	1.3
  @@ -57,32 +57,32 @@
   
   package org.apache.commons.validator;
   
  +import java.io.Serializable;
  +
   
   /**
  - * <p>Used in the Validation framework for creating a variable.  A variable 
  - * can be used to pass in values on a field level for a validation method.</p>
  - *
  - * <ul><li>See /WEB-INF/validation.xml for validation rules.</li></ul>
  + * <p>A variable can be associate with a <code>Field</code> for 
  + * passing in information to a pluggable validator.</p>
    *
    * @author David Winterfeldt
   */
  -public class Var implements Cloneable, java.io.Serializable {
  +public class Var implements Cloneable, Serializable {
   
       /**
  -     * Int Constant for JavaScript type.  This is used when generating the JavaScript objects 
  -     * for use in client side validation.
  +     * Int Constant for JavaScript type.  This can be used 
  +     * when auto-generating JavaScript.
       */
       public final static String JSTYPE_INT = "int";
   
       /**
  -     * String Constant for JavaScript type.  This is used when generating the JavaScript objects 
  -     * for use in client side validation.
  +     * String Constant for JavaScript type.  This can be used 
  +     * when auto-generating JavaScript.
       */
       public final static String JSTYPE_STRING = "string";
   
       /**
  -     * Regular Expression Constant for JavaScript type.  This is used when generating the JavaScript objects 
  -     * for use in client side validation.
  +     * Regular Expression Constant for JavaScript type.  This can be used 
  +     * when auto-generating JavaScript.
       */
       public final static String JSTYPE_REGEXP = "regexp";
       
  @@ -97,7 +97,7 @@
       private String value = null;
   
       /**
  -     * The JavaScript type of the variable.
  +     * The optional JavaScript type of the variable.
       */
       private String jsType = null;
       
  @@ -151,20 +151,23 @@
          this.jsType = jsType;	
       }
   
  +    /**
  +     * Creates and returns a copy of this object.
  +    */
       public Object clone() {
          try {
              Var var = (Var)super.clone();
              
              if (name != null) {
  -              var.name = new String(name);
  +              var.setName(new String(name));
              }
              
              if (value != null) {
  -              var.value = new String(value);
  +              var.setValue(new String(value));
              }
              
              if (jsType != null) {
  -              var.jsType = new String(jsType);
  +              var.setJsType(new String(jsType));
              }
              
              return var;
  @@ -172,7 +175,10 @@
             throw new InternalError(e.toString());
          }
       }  
  -           
  +
  +    /**
  +     * Returns a string representation of the object.
  +    */
       public String toString() {
          StringBuffer results = new StringBuffer();
          
  
  
  
  1.1                  jakarta-commons/validator/src/share/org/apache/commons/validator/package.html
  
  Index: package.html
  ===================================================================
  <html>
  <head>
     <title>Package Documentation for org.apache.commons.validator</title>
  </head>
  <body bgcolor="white">
  The Validator package provides validation for JavaBeans based on an xml file.
  <br><br>
  <a name="doc.Description"></a>
  <div align="center">
  <a href="#doc.Depend">[Dependencies]</a>
  <a href="#doc.Intro">[Introduction]</a>
  <a href="#doc.Overview">[Overview]</a>
  <a href="#doc.Resources">[Resources]</a>
  <a href="#doc.Usage">[Usage Example]</a>
  </div>
  
  <a name="doc.Depend"></a>
  <h3>External Dependencies</h3>
  
  <ul>
    <li>
      <a href="http://jakarta.apache.org/builds/jakarta-commons/release/commons-beanutils">
      Beanutils Package (Jakarta Commons)</a>, version 1.0 or later
    </li>
    <li>
      <a href="http://jakarta.apache.org/builds/jakarta-commons/release/commons-collections">
      Collections Package (Jakarta Commons)</a>, version 1.0 or later
    </li>
    <li>
      <a href="http://jakarta.apache.org/builds/jakarta-commons/release/commons-digester">
      Digester Package (Jakarta Commons)</a>, version 1.0 or later
    </li>
    <li>
      <a href="http://jakarta.apache.org/builds/jakarta-commons/release/commons-logging">
      Logging Package (Jakarta Commons)</a>, version 1.0 or later
    </li>
    <li>An xml parser conforming to
      <a href="http://www.megginson.com/SAX/">SAX 2.0</a> for the Commons Digester
    </li>
    <li>Optionally, an XML parser conforming to
      <a href="http://java.sun.com/products/xml">JAXP
      </a>, version 1.1 or later (the first one to support SAX 2.0) 
       for the Commons Digester
    </li>
  
  </ul>
  
  <a name="doc.Intro"></a>
  <h3>Introduction</h3>
  
  <p>A common issue when receiving data either electronically or from 
  user input is verifying the integrity of the data.  This work is 
  repetitive and becomes even more complicated when different sets 
  of validation rules need to be applied to the same set of data based 
  on locale for example.  Error messages may also vary by locale.  
  This package attempts to address some of these issues and 
  speed development and maintenance of validation rules.
  </p>
  
  <p>In order to use the Validator, the following basic steps are required:</p>
  <ul>
     <li>Create a new instance of the
         <code>org.apache.commons.validator.Validator</code> class.  Currently 
         Validator instances may be safely reused if the current ValidatorResources 
         are the same, as long as 
         you have completed any previous validation, and you do not try to utilize
         a particular Validator instance from more than one thread at a time.</li>
     <li>Add any <a href="#doc.Resources">resources</a>
         needed to perform the validations.  Such as the JavaBean to validate.</li>
     <li>Call the validate method on <code>org.apache.commons.validator.Validator</code>.</li>
  </ul>
  
  <a name="doc.Overview"></a>
  <h3>Overview</h3>
  <p>
     The Commons Validator is a basic validation framework that 
     lets you define validation rules for a JavaBean in an xml file.  
     Validators, the validation definition, can also be defined in 
     the xml file.  An example of a validator would be defining 
     what method and class will be called to perform the validation 
     for a required field.  Validation rules can be grouped together 
     based on locale and a JavaBean/Form that the rules are associated 
     with.  The framework has basic support for user defined constants 
     which can be used in some field attributes. 
  </p>
  <p>
     Validation rules can be defined in an xml file which keeps 
     them abstracted from JavaBean you are validating.  The 
     property reference to a field supports nested properties 
     using the Jakarta Commons BeanUtils 
     (http://jakarta.apache.org/commons/beanutils.html) package.  
     Error messages and the arguments for error messages can be 
     associated with a fields validation.
  </p>
  
  <a name="doc.Resources"></a>
  <h3>Resources</h3>
  <p>
     After a Validator instance is created, instances of 
     classes can be added to it to be passed into 
     validation methods by calling the addResource 
     method.  Below is a list of reserved keys (class names).
  </p>
  
  <table width="100%" border="1" cellspacing="5">
     <tr>
        <th>Class Name</th>
        <th>Validator Contant</th>
        <th>Description</th>
     </tr>
     <tr>
        <td>java.lang.Object</td>
        <td>Validator.BEAN_KEY</td>
        <td>JavaBean that is being validated</td>
     </tr>
     <tr>
        <td>java.util.Locale</td>
        <td>Validator.LOCALE_KEY</td>
        <td>
           Locale to use when retrieving a FormSet.  
           The default locale will be used if one 
           isn't specified.
        </td>
     </tr>
     <tr>
        <td>org.apache.commons.validator.ValidatorAction</td>
        <td>Validator.VALIDATOR_ACTION_KEY</td>
        <td>
           This is automatically added to a Validator's  
           resources as a validation is being processed. 
           If this class name is used when defining 
           a method signature for a pluggable validator, 
           the current ValidatorAction will be passed into 
           the validation method.
        </td>
     </tr>
     <tr>
        <td>org.apache.commons.validator.Field</td>
        <td>Validator.FIELD_KEY</td>
        <td>
           This is automatically added to a Validator's  
           resources as a validation is being processed. 
           If this class name is used when defining 
           a method signature for a pluggable validator, 
           the current Field will be passed into 
           the validation method.
        </td>
     </tr>
  </table>
  
  
  <a name="doc.Usage"></a>
  <h3>Usage Example</h3>
  <p>
     This is a basic example setting up a required validator for 
     a name bean.  This example is a working unit test (reference 
     <code>org.apache.commons.validator.RequiredNameTest</code> and 
     validator-name-required.xml located under validator/src/test).
  </p>
  <p>
     Create an xml file with your validator and validation rules. 
     Setup your required validator in your xml file.<br>
     <br>
     <a href="#doc.Usage.xml">XML Example</a><br>
     <a href="#doc.Usage.validator">Validator Example</a><br>
     <a href="#doc.Usage.pluggableValidator">Pluggable Validator Example</a>
  </p>
  
  <a name="doc.Usage.xml"></a>
  <h4>XML Example</h4>
  <p>
     Definition of a 'required' pluggable validator.<br>
     <br>
     &lt;form-validation&gt; <br>
     &nbsp;&nbsp;&nbsp;&lt;global&gt; <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;validator name="required" <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; classname="org.apache.commons.validator.TestValidator" <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; method="validateRequired" <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; methodParams="java.lang.Object,
                                      org.apache.commons.validator.Field"/&gt; <br>
  
     &nbsp;&nbsp;&nbsp; &lt;/global&gt; <br>
     &nbsp;&nbsp;&nbsp; &lt;formset&gt; <br>
     &nbsp;&nbsp;&nbsp; &lt;/formset&gt; <br>
     &lt;/form-validation&gt; <br>
  
  </p>
  <p>
     Add validation rules to require a first name and a last name.<br>
     <br>
     &lt;form-validation&gt; <br>
     &nbsp;&nbsp;&nbsp;&lt;global&gt; <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;validator name="required" <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; classname="org.apache.commons.validator.TestValidator" <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; method="validateRequired" <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; methodParams="java.lang.Object,
                                      org.apache.commons.validator.Field"/&gt; <br>
  
     &nbsp;&nbsp;&nbsp; &lt;/global&gt; <br>
  <b>
     &nbsp;&nbsp;&nbsp; &lt;formset&gt; <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;form    name="nameForm"&gt; <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    &lt;field    property="firstName" 
                                                          depends="required"&gt; <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    	     &lt;arg0 key="nameForm.firstname.displayname"/&gt; <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    &lt;/field&gt; <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    &lt;field    property="lastName" 
                                                               depends="required"&gt; <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    	     &lt;arg0 key="nameForm.lastname.displayname"/&gt; <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;    &lt;/field&gt; <br>
     &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/form&gt; <br>
     &nbsp;&nbsp;&nbsp; &lt;/formset&gt; <br>
  </b>
     &lt;/form-validation&gt; <br>
  </p>
  
  <a name="doc.Usage.validator"></a>
  <h4>Validator Example</h4>
  <p>
  Excerpts from org.apache.commons.validator.RequiredNameTest
  </p>
  <p>
  InputStream in = this.getClass().getResourceAsStream("validator-name-required.xml");<br>
  <br>
  // Create an instance of ValidatorResources to <br>
  // initialize from an xml file. <br>
  ValidatorResources resources = new ValidatorResources();<br>
  <br>
  // Load resources into ValidatorResources passed in <br>
  ValidatorResourcesInitializer.initialize(resources, in);<br>
  </p>
  <p>
  // Create bean to run test on.<br>
  Name name = new Name();<br>
  <br>
        // Construct validator based on the loaded resources <br>
        // and the form key<br>
        Validator validator = new Validator(resources, "nameForm");<br>
        // add the name bean to the validator as a resource <br>
        // for the validations to be performed on.<br>
        validator.addResource(Validator.BEAN_KEY, name);<br>
  <br>
        // Get results of the validation.<br>
        Map hResults = null;<br>
        <br>
        // throws ValidatorException, <br>
        // but aren't catching for example <br>
        hResults = validator.validate();<br>
        <br>
        if (hResults.get("firstName") == null) { <br>
  &nbsp;&nbsp;&nbsp; // no error <br>
        } else {<br>
  &nbsp;&nbsp;&nbsp; // number of errors for first name
  &nbsp;&nbsp;&nbsp; int errors = ((Integer)hResults.get("firstName")).intValue();<br>
        } <br>
  </p>
  
  <a name="doc.Usage.pluggableValidator"></a>
  <h4>Pluggable Validator Example</h4>
  <p>
  Validation method defined in the 'required' pluggable validator 
  (excerpt from org.apache.commons.validator.TestValidator).
  </p>
  
  <p>
                     public static boolean validateRequired(Object bean, Field field) {<br>
  &nbsp;&nbsp;&nbsp;    String value = ValidatorUtil.getValueAsString(bean, field.getProperty());<br>
  &nbsp;&nbsp;&nbsp;    return GenericValidator.isBlankOrNull(value);<br>
                     }<br>
  </p>
  </body>
  </html>
  
  
  
  1.2       +2 -2      jakarta-commons/validator/src/test/org/apache/commons/validator/validator-name-required.xml
  
  Index: validator-name-required.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/test/org/apache/commons/validator/validator-name-required.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- validator-name-required.xml	11 Mar 2002 05:12:02 -0000	1.1
  +++ validator-name-required.xml	13 Mar 2002 05:39:32 -0000	1.2
  @@ -9,11 +9,11 @@
         <form    name="nameForm">
            <field    property="firstName"
            	   depends="required">
  -         	     <arg0 key="registrationForm.firstname.displayname"/>
  +         	     <arg0 key="nameForm.firstname.displayname"/>
            </field>    
            <field    property="lastName"
            	   depends="required">
  -         	     <arg0 key="registrationForm.lastname.displayname"/>
  +         	     <arg0 key="nameForm.lastname.displayname"/>
            </field>
         </form>
      </formset>   
  
  
  

--
To unsubscribe, e-mail:   <mailto:commons-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@jakarta.apache.org>


Mime
View raw message