cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From h...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/acting FormValidatorAction.java AbstractValidatorAction.java ValidatorActionHelper.java ValidatorActionResult.java
Date Sun, 11 Aug 2002 17:44:17 GMT
haul        2002/08/11 10:44:17

  Modified:    src/java/org/apache/cocoon/acting Tag: cocoon_2_0_3_branch
                        FormValidatorAction.java
                        AbstractValidatorAction.java
                        ValidatorActionHelper.java
                        ValidatorActionResult.java
  Log:
    <action dev="CH" type="add">
     Simple Formvalidation: FormValidatorAction sets attribute "*" to indicate
     overall validation status. Added SimpleFormTransformer that fills XHTML form
     fields with values from request parameters and allows conditional error tags
     depending on validation result. This removes the requirement for
     XSP. Changed ordering of error levels: "notpresent" (indicates that no
     validation result is present for this parameter) moves between "ok" and
     "error". New error level "maxerror" used in conjunction with the
     transformer, is never set, used as upper bound.
    </action>
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.8.2.2   +9 -4      xml-cocoon2/src/java/org/apache/cocoon/acting/FormValidatorAction.java
  
  Index: FormValidatorAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/FormValidatorAction.java,v
  retrieving revision 1.8.2.1
  retrieving revision 1.8.2.2
  diff -u -r1.8.2.1 -r1.8.2.2
  --- FormValidatorAction.java	28 Apr 2002 19:48:28 -0000	1.8.2.1
  +++ FormValidatorAction.java	11 Aug 2002 17:44:17 -0000	1.8.2.2
  @@ -98,10 +98,13 @@
    * This action returns null when validation fails, otherwise it provides
    * all validated parameters to the sitemap via {name} expression.
    *
  - * In addition a request attribute <code>org.apache.cocoon.acting.FormValidatorAction.results</code>
  + * In addition a request attribute
  + * <code>org.apache.cocoon.acting.FormValidatorAction.results</code>
    * contains the validation results in both cases and make it available
  - * to XSPs. Mind you that redirections create new request objects and thus
  - * the result is not available for the target page.
  + * to XSPs. The special parameter "*" contains either the validation
  + * result "OK", if all parameters were validated successfully, or
  + * "ERROR" otherwise. Mind you that redirections create new request
  + * objects and thus the result is not available for the target page.
    *
    * All values for a parameter are read through the
    * getParameterValues() method and validated seperately.
  @@ -257,9 +260,11 @@
               if (!allOK) {
                   // if any validation failed return an empty map
                   actionMap = null;
  +                resultMap.put("*", ValidatorActionResult.ERROR);
                   if (getLogger().isDebugEnabled())
                       getLogger().debug ("All form params validated. An error occurred.");
               } else {
  +                resultMap.put("*", ValidatorActionResult.OK);
                   if (getLogger().isDebugEnabled())
                       getLogger().debug ("All form params successfully validated");
               }
  
  
  
  1.8.2.2   +49 -56    xml-cocoon2/src/java/org/apache/cocoon/acting/AbstractValidatorAction.java
  
  Index: AbstractValidatorAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/AbstractValidatorAction.java,v
  retrieving revision 1.8.2.1
  retrieving revision 1.8.2.2
  diff -u -r1.8.2.1 -r1.8.2.2
  --- AbstractValidatorAction.java	28 Apr 2002 19:48:28 -0000	1.8.2.1
  +++ AbstractValidatorAction.java	11 Aug 2002 17:44:17 -0000	1.8.2.2
  @@ -69,44 +69,44 @@
    *
    * <pre>
    * &lt;root&gt;
  -*         &lt;parameter name="username" type="string" nullable="no"/&gt;
  -*         &lt;parameter name="role" type="string" nullable="no"/&gt;
  -*         &lt;parameter name="oldpassword" type="string" nullable="no"/&gt;
  -*         &lt;parameter name="newpassword" type="string" nullable="no"/&gt;
  -*         &lt;parameter name="renewpassword" type="string" nullable="no"/&gt;
  -*         &lt;parameter name="id" type="long" nullable="no"/&gt;
  -*         &lt;parameter name="sallary" type="double" nullable="no"/&gt;
  -*         &lt;parameter name="theme" type="string" nullable="yes" default="dflt"/&gt;
  -*         &lt;constraint-set name="is-logged-in"&gt;
  -*                 &lt;validate name="username"/&gt;
  -*                 &lt;validate name="role"/&gt;
  -*         &lt;/constraint-set&gt;
  + *         &lt;parameter name="username" type="string" nullable="no"/&gt;
  + *         &lt;parameter name="role" type="string" nullable="no"/&gt;
  + *         &lt;parameter name="oldpassword" type="string" nullable="no"/&gt;
  + *         &lt;parameter name="newpassword" type="string" nullable="no"/&gt;
  + *         &lt;parameter name="renewpassword" type="string" nullable="no"/&gt;
  + *         &lt;parameter name="id" type="long" nullable="no"/&gt;
  + *         &lt;parameter name="sallary" type="double" nullable="no"/&gt;
  + *         &lt;parameter name="theme" type="string" nullable="yes" default="dflt"/&gt;
  + *         &lt;constraint-set name="is-logged-in"&gt;
  + *                 &lt;validate name="username"/&gt;
  + *                 &lt;validate name="role"/&gt;
  + *         &lt;/constraint-set&gt;
    *
  -*         &lt;constraint-set name="is-in-admin-role"&gt;
  -*                 &lt;validate name="username"/&gt;
  -*                 &lt;validate name="role" equals-to="admin"/&gt;
  -*         &lt;/constraint-set&gt;
  + *         &lt;constraint-set name="is-in-admin-role"&gt;
  + *                 &lt;validate name="username"/&gt;
  + *                 &lt;validate name="role" equals-to="admin"/&gt;
  + *         &lt;/constraint-set&gt;
    *
  -*         &lt;constraint-set name="new-passwords-match"&gt;
  -*                 &lt;validate name="oldpassword"/&gt;
  -*                 &lt;validate name="newpassword"/&gt;
  -*                 &lt;validate name="renewpassword"
  -*                         equals-to-param="newpass"/&gt;
  -*         &lt;/constraint-set&gt;
  + *         &lt;constraint-set name="new-passwords-match"&gt;
  + *                 &lt;validate name="oldpassword"/&gt;
  + *                 &lt;validate name="newpassword"/&gt;
  + *                 &lt;validate name="renewpassword"
  + *                         equals-to-param="newpass"/&gt;
  + *         &lt;/constraint-set&gt;
    * &lt;/root&gt;
    * </pre>
    *
    * <h3>The types recognized by validator and their attributes</h3>
    * <table border="1">
  -*         <tr>
  -*                 <td><b>string</b></td><td>nullable="yes|no"
default="str"</td>
  -*         </tr>
  -*         <tr>
  -*                 <td><b>long</b></td><td>nullable="yes|no"
default="123123"</td>
  -*         </tr>
  -*         <tr>
  -*                 <td><b>double</b></td><td>nullable="yes|no"
default="0.5"</td>
  -*         </tr>
  + *         <tr>
  + *                 <td><b>string</b></td><td>nullable="yes|no"
default="str"</td>
  + *         </tr>
  + *         <tr>
  + *                 <td><b>long</b></td><td>nullable="yes|no"
default="123123"</td>
  + *         </tr>
  + *         <tr>
  + *                 <td><b>double</b></td><td>nullable="yes|no"
default="0.5"</td>
  + *         </tr>
    * </table>
    * Default value takes place only when specified parameter is nullable and
    * really is null or empty. Long numbers may be specified in decimal, hex or
  @@ -115,41 +115,34 @@
    * <h3>Constraints</h3>
    * <table border="1">
    * <tr>
  -*     <td>matches-regex</td><td>POSIX regular expression</td>
  + *     <td>matches-regex</td><td>POSIX regular expression</td>
    * </tr>
    * <tr>
  -*     <td>min-len</td><td>positive integer</td>
  + *    <td>one-of</td><td>List of strings, enclosed and separated by <code>|</code></td>
    * </tr>
    * <tr>
  -*     <td>max-len</td><td>positive integer</td>
  + *     <td>min-len</td><td>positive integer</td>
    * </tr>
    * <tr>
  -*     <td>min</td><td>Double / Long</td>
  + *     <td>max-len</td><td>positive integer</td>
    * </tr>
    * <tr>
  -*     <td>max</td><td>Double / Long</td>
  + *     <td>min</td><td>Double / Long</td>
  + * </tr>
  + * <tr>
  + *     <td>max</td><td>Double / Long</td>
    * </tr>
    * </table>
  -* Constraints can be defined globally for a parameter and can be overridden
  -* by redefinition in a constraint-set. Thus if e.g. a database field can take
  -* at maximum 200 character, this property can be set globally.
  -*
  -* Values in parameter arrays are validated individually and the worst
  -* error is reported back.
  -*
  -* <h3>The attributes recognized in "constraint-set"</h3>
  -* <table>
  -* <tr>
  -*     <td>equals-to-param</td><td>parameter name</td>
  -* </tr>
  -* <tr>
  -*     <td>equals-to</td><td>string constant</td>
  -* </tr>
  -* </table>
  -* @author <a href="mailto:Martin.Man@seznam.cz">Martin Man</a>
  -* @author <a href="mailto:haul@informatik.tu-darmstadt.de">Christian Haul</a>
  -* @version CVS $Id$
  -*/
  + * Constraints can be defined globally for a parameter and can be overridden
  + * by redefinition in a constraint-set. Thus if e.g. a database field can take
  + * at maximum 200 character, this property can be set globally.
  + *
  + * Values in parameter arrays are validated individually and the worst
  + * error is reported back.
  + * @author <a href="mailto:Martin.Man@seznam.cz">Martin Man</a>
  + * @author <a href="mailto:haul@informatik.tu-darmstadt.de">Christian Haul</a>
  + * @version CVS $Id$
  + */
   public abstract class AbstractValidatorAction
   extends AbstractComplementaryConfigurableAction
   implements Configurable
  
  
  
  1.5.2.1   +10 -1     xml-cocoon2/src/java/org/apache/cocoon/acting/ValidatorActionHelper.java
  
  Index: ValidatorActionHelper.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/ValidatorActionHelper.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- ValidatorActionHelper.java	22 Feb 2002 06:59:26 -0000	1.5
  +++ ValidatorActionHelper.java	11 Aug 2002 17:44:17 -0000	1.5.2.1
  @@ -98,6 +98,15 @@
       }
   
       /**
  +     * Tests if the validation result is <code>NOTPRESENT</code>,
  +     * e.g. when the value is null and is allowed to be null.
  +     *
  +     */
  +    public boolean isNotPresent() {
  +    return (result.equals(ValidatorActionResult.NOTPRESENT));
  +    }
  +
  +    /**
        * Tests if the validation result is <code>ISNULL</code>,
        * e.g. when the value is null but is not supposed to be null.
        *
  
  
  
  1.5.2.1   +16 -10    xml-cocoon2/src/java/org/apache/cocoon/acting/ValidatorActionResult.java
  
  Index: ValidatorActionResult.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/ValidatorActionResult.java,v
  retrieving revision 1.5
  retrieving revision 1.5.2.1
  diff -u -r1.5 -r1.5.2.1
  --- ValidatorActionResult.java	22 Feb 2002 06:59:26 -0000	1.5
  +++ ValidatorActionResult.java	11 Aug 2002 17:44:17 -0000	1.5.2.1
  @@ -68,46 +68,52 @@
       OK         = new ValidatorActionResult ("OK");          // 0
   
       /**
  +     * this is returned when the result of a validation is
  +     * requested but no such result is found in the request
  +     * attribute.
  +     */
  +    public static final ValidatorActionResult
  +    NOTPRESENT = new ValidatorActionResult ("NOTPRESENT");  // 1
  +
  +    /**
        * some error occurred, this is a result that is never set but
        * serves as a comparison target.
        */
       public static final ValidatorActionResult
  -    ERROR      = new ValidatorActionResult ("ERROR");       // 1
  +    ERROR      = new ValidatorActionResult ("ERROR");       // 2
   
       /**
        * the parameter is null but isn't allowed to.
        */
       public static final ValidatorActionResult
  -    ISNULL     = new ValidatorActionResult ("ISNULL");      // 2
  +    ISNULL     = new ValidatorActionResult ("ISNULL");      // 3
   
       /**
        * either value or length in case of a string is less than the
        * specified minimum.
        */
       public static final ValidatorActionResult
  -    TOOSMALL   = new ValidatorActionResult ("TOOSMALL");    // 3
  +    TOOSMALL   = new ValidatorActionResult ("TOOSMALL");    // 4
   
       /**
        * either value or length in case of a string is greater than
        * the specified maximum.
        */
       public static final ValidatorActionResult
  -    TOOLARGE   = new ValidatorActionResult ("TOOLARGE");    // 4
  +    TOOLARGE   = new ValidatorActionResult ("TOOLARGE");    // 5
   
       /**
        * a string parameter's value is not matched by the specified
        * regular expression.
        */
       public static final ValidatorActionResult
  -    NOMATCH    = new ValidatorActionResult ("NOMATCH");     // 5
  +    NOMATCH    = new ValidatorActionResult ("NOMATCH");     // 6
   
       /**
  -     * this is returned when the result of a validation is
  -     * requested but no such result is found in the request
  -     * attribute.
  +     * maximum error, only used for comparisons.
        */
       public static final ValidatorActionResult
  -    NOTPRESENT = new ValidatorActionResult ("NOTPRESENT");  // 6
  +    MAXERROR   = new ValidatorActionResult ("MAXERROR");    // 7
   
       /**
        * Make constructor private to inhibit creation outside.
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message