mman 01/09/03 03:25:11
Modified: src/org/apache/cocoon/acting Tag: cocoon_20_branch
AbstractValidatorAction.java
Log:
'nullable' and 'default' attributes specified as follows
<constraint-set>
<validate name="xxx" nullable="yes" default="bbb">
</constraint-set>
now override the globale values specified by global parameter description
<parameter name="xxx" nullable="no" default="aaa"/>
Revision Changes Path
No revision
No revision
1.4.2.6 +35 -16
xml-cocoon2/src/org/apache/cocoon/acting/AbstractValidatorAction.java
Index: AbstractValidatorAction.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/acting/AbstractValidatorAction.java,v
retrieving revision 1.4.2.5
retrieving revision 1.4.2.6
diff -u -r1.4.2.5 -r1.4.2.6
--- AbstractValidatorAction.java 2001/08/28 18:14:59 1.4.2.5
+++ AbstractValidatorAction.java 2001/09/03 10:25:11 1.4.2.6
@@ -1,4 +1,4 @@
-// $Id: AbstractValidatorAction.java,v 1.4.2.5 2001/08/28 18:14:59 mman Exp $
+// $Id: AbstractValidatorAction.java,v 1.4.2.6 2001/09/03 10:25:11 mman Exp $
package org.apache.cocoon.acting;
import org.apache.avalon.framework.configuration.Configurable;
@@ -97,7 +97,7 @@
* </table>
* @author Martin Man <[EMAIL PROTECTED]>
* @author <a href="mailto:[EMAIL PROTECTED]">Christian Haul</a>
-* @version CVS $Revision: 1.4.2.5 $ $Date: 2001/08/28 18:14:59 $
+* @version CVS $Revision: 1.4.2.6 $ $Date: 2001/09/03 10:25:11 $
*/
public abstract class AbstractValidatorAction
extends AbstractComplementaryConfigurableAction
@@ -174,8 +174,8 @@
Configuration conf, Map params, boolean is_string) {
Object param = params.get (name);
String value = null;
- String dflt = getDefault (conf);
- boolean nullable = getNullable (conf);
+ String dflt = getDefault (conf, constraints);
+ boolean nullable = getNullable (conf, constraints);
getLogger().debug ("VALIDATOR: validating string parameter "
+ name + " (encoded in a string: " + is_string + ")");
@@ -277,11 +277,11 @@
private ValidatorActionHelper validateLong (String name, Configuration
constraints,
Configuration conf, Map params, boolean is_string) {
Object param = params.get (name);
- boolean nullable = getNullable(conf);
+ boolean nullable = getNullable(conf, constraints);
Long value = null;
Long dflt = null;
{
- String tmp = getDefault(conf);
+ String tmp = getDefault (conf, constraints);
if ( tmp != null ) dflt = Long.decode(tmp);
}
@@ -371,11 +371,11 @@
private ValidatorActionHelper validateDouble (String name, Configuration
constraints,
Configuration conf, Map params, boolean is_string) {
Object param = params.get (name);
- boolean nullable = getNullable(conf);
+ boolean nullable = getNullable (conf, constraints);
Double value = null;
Double dflt = null;
{
- String tmp = getDefault(conf);
+ String tmp = getDefault (conf, constraints);
if ( tmp!=null ) dflt = Double.valueOf(tmp);
}
@@ -542,36 +542,55 @@
}
/**
- * Returns the value of 'nullable' attribute from given configuration.
+ * Returns the value of 'nullable' attribute from given configuration or
+ * from given constraints, value present in constrints takes precedence,
+ * false when attribute is not present in either of them.
*/
- private boolean getNullable (Configuration conf) {
+ private boolean getNullable (Configuration conf, Configuration cons) {
/* check nullability */
try {
- String tmp = conf.getAttribute ("nullable", "no");
+ String tmp = cons.getAttribute ("nullable", "no");
if ("yes".equals (tmp) || "true".equals (tmp)) {
return true;
}
} catch (Exception e) {
+ try {
+ String tmp = conf.getAttribute ("nullable", "no");
+ if ("yes".equals (tmp) || "true".equals (tmp)) {
+ return true;
+ }
+ } catch (Exception e1) {
+ }
}
return false;
}
/**
- * Returns the default value from given configuration.
+ * Returns the default value from given configuration or constraints.
+ * Value present in constraints takes precedence, null is returned when no
+ * default attribute is present in eiher of them.
*/
- private String getDefault (Configuration conf) {
+ private String getDefault (Configuration conf, Configuration cons) {
String dflt = null;
try {
- dflt = conf.getAttribute ("default", "");
+ dflt = cons.getAttribute ("default", "");
if ("".equals (dflt.trim ())) {
return null;
}
} catch (Exception e) {
- return null;
+ try {
+ dflt = conf.getAttribute ("default", "");
+ if ("".equals (dflt.trim ())) {
+ return null;
+ }
+ } catch (Exception e1) {
+ return null;
+ }
}
return dflt;
}
+
/**
* Replacement for Avalon's Configuration.getAttributeAsLong
* because that one doesn't take <code>Long</code> but long and
@@ -627,5 +646,5 @@
}
-// $Id: AbstractValidatorAction.java,v 1.4.2.5 2001/08/28 18:14:59 mman Exp $
+// $Id: AbstractValidatorAction.java,v 1.4.2.6 2001/09/03 10:25:11 mman Exp $
// vim: set et ts=4 sw=4:
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]