| org.apache.cocoon.acting.AbstractAction org.apache.cocoon.acting.AbstractConfigurableAction org.apache.cocoon.acting.ConfigurableServiceableAction org.apache.cocoon.acting.AbstractComplementaryConfigurableAction org.apache.cocoon.acting.AbstractValidatorAction
All known Subclasses: org.apache.cocoon.acting.FormValidatorAction, org.apache.cocoon.acting.SessionValidatorAction,
AbstractValidatorAction | abstract public class AbstractValidatorAction extends AbstractComplementaryConfigurableAction (Code) | | Abstract implementation of action that needs to perform validation of
parameters (from session, from request, etc.). All `validator' actions
share the same description xml file. In such file every parameter is
described via its name, type and its constraints. One large description
file can be used among all validator actions, because each action should
explicitely specify which parameters to validate - through a sitemap
parameter.
Variant 1
<map:act type="validator">
<parameter name="descriptor" value="context://descriptor.xml">
<parameter name="validate" value="username,password">
</map:act>
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 * ,
all parameters in the file will be validated.
Variant 2
<map:act type="validator">
<parameter name="descriptor" value="context://descriptor.xml">
<parameter name="constraint-set" value="is-logged-in">
</map:act>
The parameter "constraint-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, because it
allows comparsion constructs, etc. See AbstractValidatorAction
documentation.
For even more powerful validation, constraints can be grouped
and used independently of the parameter name. If a validate element
has a rule attribute, it uses the parameter with that
name as a rule template and validates the parameter from the
name attribute with that rule.
This action returns null when validation fails, otherwise it
provides all validated parameters to the sitemap via {name}
expression.
In addition a request attribute
org.apache.cocoon.acting.FormValidatorAction.results
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.
<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>
<constraint-set name="all">
<include name="is-logged-in"/>
<include name="is-in-admin-role"/>
<include name="new-passwords-match"/>
</constraint-set>
</root>
The types recognized by validator and their attributes
string | nullable="yes|no" default="str" |
long | nullable="yes|no" default="123123" |
double | nullable="yes|no" default="0.5" |
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).
Constraints
matches-regex | POSIX regular expression |
min-len | positive integer |
max-len | positive integer |
min | Double / Long |
max | Double / Long |
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.
The attributes recognized in "constraint-set"
equals-to-param | parameter name |
equals-to | string constant |
author: Martin Man author: Christian Haul version: CVS $Id: AbstractValidatorAction.java 433543 2006-08-22 06:22:54Z crossley $ |
Method Summary | |
public Map | act(Redirector redirector, SourceResolver resolver, Map objectModel, String src, Parameters parameters) | abstract protected HashMap | createMapOfParameters(Map objectModel, Collection set) Reads parameter values for all parameters that are contained in the active
constraint list. | protected Configuration | getDescriptor(SourceResolver resolver, Map objectModel, Parameters parameters) Load the descriptor containing the constraints. | protected Collection | getSetOfParameterNamesFromSitemap(String valstr, Map desc) Get list of params to be validated from sitemap parameter and
isolates the parameter names from the comma separated list. | protected Map | indexConfiguration(Configuration[] descriptor) Create an index map to an array of configurations by their name
attribute. | protected boolean | isDescriptorReloadable() Checks the default setting for reloading the descriptor file. | abstract boolean | isStringEncoded() | protected Collection | resolveConstraints(String valsetstr, Map consets) Recursively resolve constraint sets that may "include" other constraint
sets and return a collection of all parameters to validate. | protected Map | setResult(Map objectModel, Map actionMap, Map resultMap, boolean allOK) Add success indicator to resulting maps and clear actionMap if unsuccessful. | public ValidatorActionHelper | validateParameter(String name, Configuration constraints, Map conf, Map params, boolean isString) Try to validate given parameter.
Parameters: name - The name of the parameter to validate. Parameters: constraints - Configuration of all constraints for thisparameter as taken from the description XML file. Parameters: conf - Configuration of all parameters as taken from thedescription XML file. Parameters: params - The map of parameters. Parameters: isString - Indicates wheter given param to validate isstring (as taken from HTTP request for example) or wheteher itshould be regular instance of java.lang.Double, java.lang.Long,etc. | public ValidatorActionHelper | validateParameter(String name, String rule, Configuration constraints, Map conf, Map params, boolean isString) Try to validate given parameter.
Parameters: name - The actual name of the parameter to validate. Parameters: rule - The name of the parameter element that contains therule that should be used for validation. Parameters: constraints - Configuration of all constraints for thisparameter as taken from the description XML file. Parameters: conf - Configuration of all parameters as taken from thedescription XML file. Parameters: params - The map of parameters. Parameters: isString - Indicates wheter given param to validate isstring (as taken from HTTP request for example) or wheteher itshould be regular instance of java.lang.Double, java.lang.Long,etc. | protected boolean | validateSetOfParameters(Map desc, Map actionMap, Map resultMap, Collection set, Map params, boolean isString) Validate all parameters in the set with the constraints contained in
desc and the values from params. | protected ValidatorActionHelper | validateValue(String name, Configuration constraints, Configuration conf, Map params, boolean isString, String type) Validate a single parameter value. |
createMapOfParameters | abstract protected HashMap createMapOfParameters(Map objectModel, Collection set)(Code) | | Reads parameter values for all parameters that are contained in the active
constraint list. If a parameter has multiple values, all are stored in the
resulting map.
Parameters: objectModel - the object model Parameters: set - a collection of parameter names HashMap |
getDescriptor | protected Configuration getDescriptor(SourceResolver resolver, Map objectModel, Parameters parameters)(Code) | | Load the descriptor containing the constraints.
Parameters: resolver - Parameters: parameters - a Configuration containing the constraints or null if a problem occurred. |
getSetOfParameterNamesFromSitemap | protected Collection getSetOfParameterNamesFromSitemap(String valstr, Map desc)(Code) | | Get list of params to be validated from sitemap parameter and
isolates the parameter names from the comma separated list.
|
indexConfiguration | protected Map indexConfiguration(Configuration[] descriptor)(Code) | | Create an index map to an array of configurations by their name
attribute. An empty array results in an empty map.
Parameters: descriptor - index map or empty map |
isDescriptorReloadable | protected boolean isDescriptorReloadable()(Code) | | Checks the default setting for reloading the descriptor file.
boolean |
isStringEncoded | abstract boolean isStringEncoded()(Code) | | Are parameters encoded as strings?
boolean |
resolveConstraints | protected Collection resolveConstraints(String valsetstr, Map consets)(Code) | | Recursively resolve constraint sets that may "include" other constraint
sets and return a collection of all parameters to validate.
Parameters: valsetstr - Parameters: consets - collection of all parameters to validate |
setResult | protected Map setResult(Map objectModel, Map actionMap, Map resultMap, boolean allOK)(Code) | | Add success indicator to resulting maps and clear actionMap if unsuccessful.
Results are stored as request attributes.
Parameters: objectModel - the object model Parameters: actionMap - a Map containing validated parameters Parameters: resultMap - a Map containing validation results Parameters: allOK - a boolean indicating if all validations were successful actionMap if allOK or null otherwise |
validateParameter | public ValidatorActionHelper validateParameter(String name, Configuration constraints, Map conf, Map params, boolean isString)(Code) | | Try to validate given parameter.
Parameters: name - The name of the parameter to validate. Parameters: constraints - Configuration of all constraints for thisparameter as taken from the description XML file. Parameters: conf - Configuration of all parameters as taken from thedescription XML file. Parameters: params - The map of parameters. Parameters: isString - Indicates wheter given param to validate isstring (as taken from HTTP request for example) or wheteher itshould be regular instance of java.lang.Double, java.lang.Long,etc. The validated parameter. |
validateParameter | public ValidatorActionHelper validateParameter(String name, String rule, Configuration constraints, Map conf, Map params, boolean isString)(Code) | | Try to validate given parameter.
Parameters: name - The actual name of the parameter to validate. Parameters: rule - The name of the parameter element that contains therule that should be used for validation. Parameters: constraints - Configuration of all constraints for thisparameter as taken from the description XML file. Parameters: conf - Configuration of all parameters as taken from thedescription XML file. Parameters: params - The map of parameters. Parameters: isString - Indicates wheter given param to validate isstring (as taken from HTTP request for example) or wheteher itshould be regular instance of java.lang.Double, java.lang.Long,etc. The validated parameter. |
validateSetOfParameters | protected boolean validateSetOfParameters(Map desc, Map actionMap, Map resultMap, Collection set, Map params, boolean isString)(Code) | | Validate all parameters in the set with the constraints contained in
desc and the values from params. Validation details are in resultMap and
successful validated parameters in resultMap.
Parameters: desc - Parameters: actionMap - Parameters: resultMap - Parameters: set - Parameters: params - Parameters: isString - boolean all parameters ok or not |
validateValue | protected ValidatorActionHelper validateValue(String name, Configuration constraints, Configuration conf, Map params, boolean isString, String type)(Code) | | Validate a single parameter value.
Parameters: name - String holding the name of the parameter Parameters: constraints - Configuration holding the constraint set configuration for the parameter Parameters: conf - Configuration holding the parameter configuration Parameters: params - Map of parameter values to be validated Parameters: isString - boolean indicating if the value is string encoded Parameters: type - string holding the name of the datatype to validate value ValidatorActionHelper |
Methods inherited from org.apache.cocoon.acting.AbstractComplementaryConfigurableAction | protected Configuration getConfiguration(String descriptor) throws ConfigurationException(Code)(Java Doc) protected Configuration getConfiguration(String descriptor, boolean reloadable) throws ConfigurationException(Code)(Java Doc) protected Configuration getConfiguration(String descriptor, SourceResolver resolver, boolean reloadable) throws ConfigurationException(Code)(Java Doc)
|
Fields inherited from org.apache.cocoon.acting.ConfigurableServiceableAction | protected ServiceManager manager(Code)(Java Doc)
|
Methods inherited from org.apache.cocoon.acting.ConfigurableServiceableAction | public void service(ServiceManager manager) throws ServiceException(Code)(Java Doc)
|
Fields inherited from org.apache.cocoon.acting.AbstractConfigurableAction | protected HashMap settings(Code)(Java Doc)
|
Methods inherited from org.apache.cocoon.acting.AbstractConfigurableAction | public void configure(Configuration conf) throws ConfigurationException(Code)(Java Doc)
|
Fields inherited from org.apache.cocoon.acting.AbstractAction | final protected static Map EMPTY_MAP(Code)(Java Doc)
|
|
|