haul 2002/08/25 01:49:18 Modified: src/java/org/apache/cocoon/acting AbstractComplementaryConfigurableAction.java AbstractValidatorAction.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 Minor additions to FormValidatorAction Revision Changes Path 1.9 +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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- AbstractComplementaryConfigurableAction.java 13 Jun 2002 09:28:14 -0000 1.8 +++ AbstractComplementaryConfigurableAction.java 25 Aug 2002 08:49:17 -0000 1.9 @@ -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.10 +96 -69 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.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- AbstractValidatorAction.java 28 Apr 2002 19:03:10 -0000 1.9 +++ AbstractValidatorAction.java 25 Aug 2002 08:49:17 -0000 1.10 @@ -69,87 +69,91 @@ * * <pre> * <root> -* <parameter name="username" type="string" nullable="no"/> -* <parameter name="role" type="string" nullable="no"/> -* <parameter name="oldpassword" type="string" nullable="no"/> -* <parameter name="newpassword" type="string" nullable="no"/> -* <parameter name="renewpassword" type="string" nullable="no"/> -* <parameter name="id" type="long" nullable="no"/> -* <parameter name="sallary" type="double" nullable="no"/> -* <parameter name="theme" type="string" nullable="yes" default="dflt"/> -* <constraint-set name="is-logged-in"> -* <validate name="username"/> -* <validate name="role"/> -* </constraint-set> - * -* <constraint-set name="is-in-admin-role"> -* <validate name="username"/> -* <validate name="role" equals-to="admin"/> -* </constraint-set> - * -* <constraint-set name="new-passwords-match"> -* <validate name="oldpassword"/> -* <validate name="newpassword"/> -* <validate name="renewpassword" -* equals-to-param="newpass"/> -* </constraint-set> + * <parameter name="username" type="string" nullable="no"/> + * <parameter name="role" type="string" nullable="no"/> + * <parameter name="oldpassword" type="string" nullable="no"/> + * <parameter name="newpassword" type="string" nullable="no"/> + * <parameter name="renewpassword" type="string" nullable="no"/> + * <parameter name="id" type="long" nullable="no"/> + * <parameter name="sallary" type="double" nullable="no"/> + * <parameter name="theme" type="string" nullable="yes" default="dflt"/> + * <constraint-set name="is-logged-in"> + * <validate name="username"/> + * <validate name="role"/> + * </constraint-set> + * + * <constraint-set name="is-in-admin-role"> + * <validate name="username"/> + * <validate name="role" equals-to="admin"/> + * </constraint-set> + * + * <constraint-set name="new-passwords-match"> + * <validate name="oldpassword"/> + * <validate name="newpassword"/> + * <validate name="renewpassword" + * equals-to-param="newpass"/> + * </constraint-set> * </root> * </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 - * 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"> * <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>min-len</td><td>positive integer</td> * </tr> * <tr> -* <td>max-len</td><td>positive integer</td> + * <td>max-len</td><td>positive integer</td> * </tr> * <tr> -* <td>min</td><td>Double / Long</td> + * <td>min</td><td>Double / Long</td> + * </tr> + * <tr> + * <td>max</td><td>Double / Long</td> + * </tr> + * </table> + * + * <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>max</td><td>Double / Long</td> + * <td>equals-to</td><td>string constant</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:[EMAIL PROTECTED]">Martin Man</a> -* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a> -* @version CVS $Id$ -*/ + * @author <a href="mailto:[EMAIL PROTECTED]">Martin Man</a> + * @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a> + * @version CVS $Id$ + */ public abstract class AbstractValidatorAction extends AbstractComplementaryConfigurableAction implements Configurable @@ -157,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; } @@ -188,7 +215,7 @@ if (!found) { if (getLogger().isDebugEnabled()) getLogger().debug("Description for parameter " - + name + " not found"); + + name + " / " + rule + " not found"); return null; } 1.8 +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.8 diff -u -r1.7 -r1.8 --- DatabaseAddAction.java 22 Feb 2002 06:59:26 -0000 1.7 +++ DatabaseAddAction.java 25 Aug 2002 08:49:17 -0000 1.8 @@ -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.9 +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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- DatabaseAuthenticatorAction.java 24 Jun 2002 10:49:17 -0000 1.8 +++ DatabaseAuthenticatorAction.java 25 Aug 2002 08:49:17 -0000 1.9 @@ -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.8 +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.8 diff -u -r1.7 -r1.8 --- DatabaseDeleteAction.java 22 Feb 2002 06:59:26 -0000 1.7 +++ DatabaseDeleteAction.java 25 Aug 2002 08:49:17 -0000 1.8 @@ -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.7 +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.7 diff -u -r1.6 -r1.7 --- DatabaseSelectAction.java 22 Feb 2002 06:59:26 -0000 1.6 +++ DatabaseSelectAction.java 25 Aug 2002 08:49:17 -0000 1.7 @@ -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.9 +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.9 diff -u -r1.8 -r1.9 --- DatabaseUpdateAction.java 22 Feb 2002 06:59:26 -0000 1.8 +++ DatabaseUpdateAction.java 25 Aug 2002 08:49:17 -0000 1.9 @@ -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.12 +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.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- FormValidatorAction.java 11 Aug 2002 18:38:04 -0000 1.11 +++ FormValidatorAction.java 25 Aug 2002 08:49:17 -0000 1.12 @@ -75,39 +75,48 @@ * <parameter name="validate" value="username,password"> * </map:act> * </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> * <map:act type="form-validator"> * <parameter name="descriptor" value="context://descriptor.xml"> * <parameter name="validate-set" value="is-logged-in"> * </map:act> * </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:[EMAIL PROTECTED]">Martin Man</a> * @author <a href="mailto:[EMAIL PROTECTED]">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.9 +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.9 diff -u -r1.8 -r1.9 --- SessionValidatorAction.java 21 Mar 2002 04:09:19 -0000 1.8 +++ SessionValidatorAction.java 25 Aug 2002 08:49:17 -0000 1.9 @@ -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: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]