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 AbstractValidatorAction.java AbstractComplementaryConfigurableAction.java DatabaseAddAction.java DatabaseAuthenticatorAction.java DatabaseDeleteAction.java DatabaseSelectAction.java DatabaseUpdateAction.java FormValidatorAction.java SessionValidatorAction.java
Date Sun, 25 Aug 2002 09:12:09 GMT
haul        2002/08/25 02:12:09

  Modified:    src/java/org/apache/cocoon/acting Tag: cocoon_2_0_3_branch
                        AbstractValidatorAction.java
                        AbstractComplementaryConfigurableAction.java
                        DatabaseAddAction.java
                        DatabaseAuthenticatorAction.java
                        DatabaseDeleteAction.java DatabaseSelectAction.java
                        DatabaseUpdateAction.java FormValidatorAction.java
                        SessionValidatorAction.java
  Log:
  Replace Boolean.getBoolean(s) with Boolean.valueOf(s).booleanValue()
  spotted by Per Kreipke
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.8.2.3   +54 -20    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.2
  retrieving revision 1.8.2.3
  diff -u -r1.8.2.2 -r1.8.2.3
  --- AbstractValidatorAction.java	11 Aug 2002 17:44:17 -0000	1.8.2.2
  +++ AbstractValidatorAction.java	25 Aug 2002 09:12:09 -0000	1.8.2.3
  @@ -108,9 +108,11 @@
    *                 <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
  - * octal values as accepted by java.Lang.decode (String s).
  + *
  + * <p>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 octal values as accepted by java.Lang.decode
  + * (String s).</p>
    *
    * <h3>Constraints</h3>
    * <table border="1">
  @@ -118,9 +120,6 @@
    *     <td>matches-regex</td><td>POSIX regular expression</td>
    * </tr>
    * <tr>
  - *    <td>one-of</td><td>List of strings, enclosed and separated by <code>|</code></td>
  - * </tr>
  - * <tr>
    *     <td>min-len</td><td>positive integer</td>
    * </tr>
    * <tr>
  @@ -133,12 +132,24 @@
    *     <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.
  + * <p>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.</p>
  + *
  + * <p>Values in parameter arrays are validated individually and the
  + * worst error is reported back.</p>
  + *
  + * <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$
  @@ -150,29 +161,52 @@
       /**
        * Try to validate given parameter.
        * @param name The name of the parameter to validate.
  -     * @param constraints Configuration of all constraints for this parameter
  -     * as taken from the description XML file.
  +     * @param constraints Configuration of all constraints for this
  +     * parameter as taken from the description XML file.
        * @param conf Configuration of all parameters as taken from the
        * description XML file.
        * @param params The map of parameters.
  -     * @param isString Indicates wheter given param to validate is string
  -     * (as taken from HTTP request for example) or wheteher it should be
  -     * regular instance of java.lang.Double, java.lang.Long, etc.
  +     * @param isString Indicates wheter given param to validate is
  +     * string (as taken from HTTP request for example) or wheteher it
  +     * should be regular instance of java.lang.Double, java.lang.Long,
  +     * etc.
        * @return The validated parameter.
        */
       public ValidatorActionHelper validateParameter(String name, Configuration constraints,
               Configuration[] conf, Map params, boolean isString) {
  +
  +        return validateParameter(name, name, constraints, conf, params, isString);
  +    }
  +
  +    /**
  +     * Try to validate given parameter.
  +     * @param name The actual name of the parameter to validate.
  +     * @param rule The name of the parameter element that contains the
  +     * rule that should be used for validation.
  +     * @param constraints Configuration of all constraints for this
  +     * parameter as taken from the description XML file.
  +     * @param conf Configuration of all parameters as taken from the
  +     * description XML file.
  +     * @param params The map of parameters.
  +     * @param isString Indicates wheter given param to validate is
  +     * string (as taken from HTTP request for example) or wheteher it
  +     * should be regular instance of java.lang.Double, java.lang.Long,
  +     * etc.
  +     * @return The validated parameter.
  +     */
  +    public ValidatorActionHelper validateParameter(String name, String rule, Configuration
constraints,
  +            Configuration[] conf, Map params, boolean isString) {
           String type = null;
           int i = 0;
   
           if (getLogger().isDebugEnabled())
  -            getLogger().debug ("Validating parameter: " + name);
  +            getLogger().debug ("Validating parameter: " + name + " using rule: "+rule);
   
           /* try to find matching param description in conf tree */
           try {
               boolean found = false;
               for (i = 0; i < conf.length; i ++) {
  -                if (name.equals (conf[i].getAttribute ("name"))) {
  +                if (rule.equals (conf[i].getAttribute ("name"))) {
                       found = true;
                       break;
                   }
  @@ -181,7 +215,7 @@
               if (!found) {
                   if (getLogger().isDebugEnabled())
                       getLogger().debug("Description for parameter "
  -                                      + name + " not found");
  +                                      + name + " / " + rule + " not found");
                   return null;
               }
   
  
  
  
  1.7.2.1   +2 -2      xml-cocoon2/src/java/org/apache/cocoon/acting/AbstractComplementaryConfigurableAction.java
  
  Index: AbstractComplementaryConfigurableAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/AbstractComplementaryConfigurableAction.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- AbstractComplementaryConfigurableAction.java	6 Apr 2002 06:26:10 -0000	1.7
  +++ AbstractComplementaryConfigurableAction.java	25 Aug 2002 09:12:09 -0000	1.7.2.1
  @@ -84,7 +84,7 @@
       protected Configuration getConfiguration(String descriptor) throws ConfigurationException
{
           boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT;
           if (this.settings.containsKey("reloadable"))
  -            reloadable = Boolean.getBoolean((String) this.settings.get("reloadable"));
  +            reloadable = Boolean.valueOf((String) this.settings.get("reloadable")).booleanValue();
           return this.getConfiguration(descriptor, null, reloadable);
       }
   
  
  
  
  1.7.2.1   +2 -2      xml-cocoon2/src/java/org/apache/cocoon/acting/DatabaseAddAction.java
  
  Index: DatabaseAddAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/DatabaseAddAction.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- DatabaseAddAction.java	22 Feb 2002 06:59:26 -0000	1.7
  +++ DatabaseAddAction.java	25 Aug 2002 09:12:09 -0000	1.7.2.1
  @@ -96,7 +96,7 @@
           // read global parameter settings
           boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT;
           if (this.settings.containsKey("reloadable"))
  -            reloadable = Boolean.getBoolean((String) this.settings.get("reloadable"));
  +            reloadable = Boolean.valueOf((String) this.settings.get("reloadable")).booleanValue();
           // read local parameter settings
           try {
               Configuration conf =
  
  
  
  1.7.2.1   +2 -2      xml-cocoon2/src/java/org/apache/cocoon/acting/DatabaseAuthenticatorAction.java
  
  Index: DatabaseAuthenticatorAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/DatabaseAuthenticatorAction.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- DatabaseAuthenticatorAction.java	22 Feb 2002 06:59:26 -0000	1.7
  +++ DatabaseAuthenticatorAction.java	25 Aug 2002 09:12:09 -0000	1.7.2.1
  @@ -122,7 +122,7 @@
           boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT;
   
           if (this.settings.containsKey("reloadable")) {
  -            reloadable = Boolean.getBoolean((String) this.settings.get("reloadable"));
  +            reloadable = Boolean.valueOf((String) this.settings.get("reloadable")).booleanValue();
           }
   
           // read local settings
  
  
  
  1.7.2.1   +2 -2      xml-cocoon2/src/java/org/apache/cocoon/acting/DatabaseDeleteAction.java
  
  Index: DatabaseDeleteAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/DatabaseDeleteAction.java,v
  retrieving revision 1.7
  retrieving revision 1.7.2.1
  diff -u -r1.7 -r1.7.2.1
  --- DatabaseDeleteAction.java	22 Feb 2002 06:59:26 -0000	1.7
  +++ DatabaseDeleteAction.java	25 Aug 2002 09:12:09 -0000	1.7.2.1
  @@ -94,7 +94,7 @@
           // read global parameter settings
           boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT;
           if (this.settings.containsKey("reloadable"))
  -            reloadable = Boolean.getBoolean((String) this.settings.get("reloadable"));
  +            reloadable = Boolean.valueOf((String) this.settings.get("reloadable")).booleanValue();
           // read local parameter settings
           try {
               Configuration conf =
  
  
  
  1.6.2.1   +2 -2      xml-cocoon2/src/java/org/apache/cocoon/acting/DatabaseSelectAction.java
  
  Index: DatabaseSelectAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/DatabaseSelectAction.java,v
  retrieving revision 1.6
  retrieving revision 1.6.2.1
  diff -u -r1.6 -r1.6.2.1
  --- DatabaseSelectAction.java	22 Feb 2002 06:59:26 -0000	1.6
  +++ DatabaseSelectAction.java	25 Aug 2002 09:12:09 -0000	1.6.2.1
  @@ -95,7 +95,7 @@
           // read global parameter settings
           boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT;
           if (this.settings.containsKey("reloadable"))
  -            reloadable = Boolean.getBoolean((String) this.settings.get("reloadable"));
  +            reloadable = Boolean.valueOf((String) this.settings.get("reloadable")).booleanValue();
           // read local parameter settings
           try {
               Configuration conf =
  
  
  
  1.8.2.1   +2 -2      xml-cocoon2/src/java/org/apache/cocoon/acting/DatabaseUpdateAction.java
  
  Index: DatabaseUpdateAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/DatabaseUpdateAction.java,v
  retrieving revision 1.8
  retrieving revision 1.8.2.1
  diff -u -r1.8 -r1.8.2.1
  --- DatabaseUpdateAction.java	22 Feb 2002 06:59:26 -0000	1.8
  +++ DatabaseUpdateAction.java	25 Aug 2002 09:12:09 -0000	1.8.2.1
  @@ -91,7 +91,7 @@
           // read global parameter settings
           boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT;
           if (this.settings.containsKey("reloadable"))
  -            reloadable = Boolean.getBoolean((String) this.settings.get("reloadable"));
  +            reloadable = Boolean.valueOf((String) this.settings.get("reloadable")).booleanValue();
           // read local parameter settings
           try {
               Configuration conf =
  
  
  
  1.8.2.3   +53 -27    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.2
  retrieving revision 1.8.2.3
  diff -u -r1.8.2.2 -r1.8.2.3
  --- FormValidatorAction.java	11 Aug 2002 17:44:17 -0000	1.8.2.2
  +++ FormValidatorAction.java	25 Aug 2002 09:12:09 -0000	1.8.2.3
  @@ -75,39 +75,48 @@
    *         &lt;parameter name="validate" value="username,password"&gt;
    * &lt;/map:act&gt;
    * </pre>
  - * The list of parameters to be validated is specified as a comma separated
  - * list of their names. descriptor.xml can therefore be used among many
  - * various actions.
  + *
  + * <p>The list of parameters to be validated is specified as a comma
  + * separated list of their names. descriptor.xml can therefore be used
  + * among many various actions. If the list contains only of <code>*</code>,
  + * all parameters in the file will be validated.</p>
    *
    * <h3>Variant 2</h3>
    * <pre>
  - * <pre>
    * &lt;map:act type="form-validator"&gt;
    *         &lt;parameter name="descriptor" value="context://descriptor.xml"&gt;
    *         &lt;parameter name="validate-set" value="is-logged-in"&gt;
    * &lt;/map:act&gt;
    * </pre>
    *
  - * The parameter "validate-set" tells to take a given "constraint-set"
  - * from description
  - * file and test all parameters against given criteria. This variant is more
  - * powerful, more aspect oriented and more flexibile than the previous one,
  - * becuase it allows the comparsion constructs, etc. See
  - * AbstractValidatorAction documentation.
  - *
  - * This action returns null when validation fails, otherwise it provides
  - * all validated parameters to the sitemap via {name} expression.
  + * <p>The parameter "validate-set" tells to take a given
  + * "constraint-set" from description file and test all parameters
  + * against given criteria. This variant is more powerful, more aspect
  + * oriented and more flexibile than the previous one, becuase it
  + * allows the comparsion constructs, etc. See AbstractValidatorAction
  + * documentation.</p>
  + *
  + * <p>For even more powerfull validation, constraints can be grouped
  + * and used independently of the parameter name. If a validate element
  + * has a <code>rule</code> attribute, it uses the parameter with that
  + * name as a rule template and validates the parameter from the
  + * <code>name</code> attribute with that rule.</p>
  + *
  + * <p>This action returns null when validation fails, otherwise it
  + * provides all validated parameters to the sitemap via {name}
  + * expression.</p>
    *
  - * In addition a request attribute
  + * <p>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. 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.
  + * objects and thus the result is not available for the target
  + * page.</p>
    *
  - * All values for a parameter are read through the
  - * getParameterValues() method and validated seperately.
  + * <p>All values for a parameter are read through the
  + * getParameterValues() method and validated seperately.</p>
    *
    * @author <a href="mailto:Martin.Man@seznam.cz">Martin Man</a>
    * @author <a href="mailto:haul@informatik.tu-darmstadt.de">Christian Haul</a>
  @@ -132,7 +141,7 @@
           // read global parameter settings
           boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT;
           if (this.settings.containsKey("reloadable")) {
  -            reloadable = Boolean.getBoolean((String) this.settings.get("reloadable"));
  +            reloadable = Boolean.valueOf((String) this.settings.get("reloadable")).booleanValue();
           }
   
           // read local settings
  @@ -156,9 +165,22 @@
                       getLogger().debug ("Validating parameters "
                                          + "as specified via 'validate' parameter");
                   /* get list of params to be validated */
  -                String[] rparams = Tokenizer.tokenize (valstr, ",", false);
  -
  -                /* perform actuall validation */
  +                String[] rparams = null;
  +                if (!"*".equals(valstr.trim())) {
  +                    rparams = Tokenizer.tokenize (valstr, ",", false);
  +                } else {
  +                    // validate _all_ parameters
  +                    rparams = new String[desc.length];
  +                    for (int i=0; i<desc.length; i++) {
  +                        rparams[i] = desc[i].getAttribute("name","");
  +                        if ("".equals(rparams[i])) {
  +                            if (getLogger().isDebugEnabled())
  +                                getLogger().debug ("Wrong syntax of the 'validate' parameter");
  +                            return null;
  +                        }
  +                    }
  +                }
  +                /* perform actual validation */
                   ValidatorActionHelper result = null;
                   String name = null;
                   HashMap params = new HashMap (rparams.length);
  @@ -176,7 +198,7 @@
                   for (int i = 0; i < rparams.length; i ++) {
                       name = rparams[i].trim ();
                       result = validateParameter (name, null, desc,
  -                            params, true);
  +                                                params, true);
                       if (!result.isOK()) {
                           if (getLogger().isDebugEnabled())
                               getLogger().debug ("Validation failed for parameter " + name);
  @@ -193,6 +215,9 @@
                   if (getLogger().isDebugEnabled())
                       getLogger().debug ("Validating parameters "
                                          + "from given constraint-set " + valsetstr);
  +                // go over all constraint sets
  +                // untill the requested set is found
  +                // set number will be in j
                   Configuration cset = null;
                   String setname = null;
                   int j = 0;
  @@ -225,14 +250,13 @@
                                          + " contains " + set.length + " rules");
                   /* put required params into hash */
                   for (int i = 0; i < set.length; i ++) {
  -                    name = set[i].getAttribute ("name", "");
  -                    if ("".equals (name.trim ())) {
  +                    name = set[i].getAttribute ("name", "").trim();
  +                    if ("".equals(name)) {
                           if (getLogger().isDebugEnabled())
                               getLogger().debug ("Wrong syntax "
                                                  + " of 'validate' children nr. " + i);
                           return null;
                       }
  -                    name = name.trim ();
                       Object[] values = req.getParameterValues(name);
                       if (values != null) {
                           switch (values.length) {
  @@ -244,9 +268,11 @@
                           params.put(name,values);
                       }
                   }
  +                String rule = null;
                   for (int i = 0; i < set.length; i ++) {
                       name = set[i].getAttribute ("name", null);
  -                    result = validateParameter (name, set[i],
  +                    rule = set[i].getAttribute("rule",name);
  +                    result = validateParameter (name, rule, set[i],
                               desc, params, true);
                       if (!result.isOK()) {
                           if (getLogger().isDebugEnabled())
  
  
  
  1.8.2.1   +2 -2      xml-cocoon2/src/java/org/apache/cocoon/acting/SessionValidatorAction.java
  
  Index: SessionValidatorAction.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/acting/SessionValidatorAction.java,v
  retrieving revision 1.8
  retrieving revision 1.8.2.1
  diff -u -r1.8 -r1.8.2.1
  --- SessionValidatorAction.java	21 Mar 2002 04:09:19 -0000	1.8
  +++ SessionValidatorAction.java	25 Aug 2002 09:12:09 -0000	1.8.2.1
  @@ -127,7 +127,7 @@
           // read global parameter settings
           boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT;
           if (this.settings.containsKey("reloadable")) {
  -            reloadable = Boolean.getBoolean((String) this.settings.get("reloadable"));
  +            reloadable = Boolean.valueOf((String) this.settings.get("reloadable")).booleanValue();
           }
   
           try {
  
  
  

----------------------------------------------------------------------
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