org.apache.cocoon.acting
Class AbstractValidatorAction

java.lang.Object
  |
  +--org.apache.avalon.framework.logger.AbstractLoggable
        |
        +--org.apache.cocoon.acting.AbstractAction
              |
              +--org.apache.cocoon.acting.AbstractConfigurableAction
                    |
                    +--org.apache.cocoon.acting.ConfigurableComposerAction
                          |
                          +--org.apache.cocoon.acting.AbstractComplementaryConfigurableAction
                                |
                                +--org.apache.cocoon.acting.AbstractValidatorAction
All Implemented Interfaces:
Action, org.apache.avalon.framework.component.Component, org.apache.avalon.framework.component.Composable, org.apache.avalon.framework.configuration.Configurable, org.apache.avalon.framework.logger.Loggable
Direct Known Subclasses:
FormValidatorAction, SessionValidatorAction

public abstract class AbstractValidatorAction
extends AbstractComplementaryConfigurableAction
implements org.apache.avalon.framework.configuration.Configurable

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.

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

The types recognized by validator and their attributes

stringnullable="yes|no" default="str"
longnullable="yes|no" default="123123"
doublenullable="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-regexPOSIX regular expression
min-lenpositive integer
max-lenpositive integer
minDouble / Long
maxDouble / 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-paramparameter name
equals-tostring constant

Version:
CVS $Id: AbstractValidatorAction.java,v 1.8.2.3 2002/08/25 09:12:09 haul Exp $
Author:
Martin Man, Christian Haul

Fields inherited from class org.apache.cocoon.acting.ConfigurableComposerAction
manager
 
Fields inherited from class org.apache.cocoon.acting.AbstractConfigurableAction
settings
 
Fields inherited from class org.apache.cocoon.acting.AbstractAction
EMPTY_MAP
 
Fields inherited from interface org.apache.cocoon.acting.Action
ROLE
 
Constructor Summary
AbstractValidatorAction()
           
 
Method Summary
 ValidatorActionHelper validateParameter(java.lang.String name, org.apache.avalon.framework.configuration.Configuration constraints, org.apache.avalon.framework.configuration.Configuration[] conf, java.util.Map params, boolean isString)
          Try to validate given parameter.
 ValidatorActionHelper validateParameter(java.lang.String name, java.lang.String rule, org.apache.avalon.framework.configuration.Configuration constraints, org.apache.avalon.framework.configuration.Configuration[] conf, java.util.Map params, boolean isString)
          Try to validate given parameter.
 
Methods inherited from class org.apache.cocoon.acting.AbstractComplementaryConfigurableAction
getConfiguration, getConfiguration, getConfiguration
 
Methods inherited from class org.apache.cocoon.acting.ConfigurableComposerAction
compose
 
Methods inherited from class org.apache.cocoon.acting.AbstractConfigurableAction
configure
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLoggable
getLogger, setLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.avalon.framework.configuration.Configurable
configure
 
Methods inherited from interface org.apache.cocoon.acting.Action
act
 

Constructor Detail

AbstractValidatorAction

public AbstractValidatorAction()
Method Detail

validateParameter

public ValidatorActionHelper validateParameter(java.lang.String name,
                                               org.apache.avalon.framework.configuration.Configuration constraints,
                                               org.apache.avalon.framework.configuration.Configuration[] conf,
                                               java.util.Map params,
                                               boolean isString)
Try to validate given parameter.
Parameters:
name - The name of the parameter to validate.
constraints - Configuration of all constraints for this parameter as taken from the description XML file.
conf - Configuration of all parameters as taken from the description XML file.
params - The map of parameters.
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.
Returns:
The validated parameter.

validateParameter

public ValidatorActionHelper validateParameter(java.lang.String name,
                                               java.lang.String rule,
                                               org.apache.avalon.framework.configuration.Configuration constraints,
                                               org.apache.avalon.framework.configuration.Configuration[] conf,
                                               java.util.Map params,
                                               boolean isString)
Try to validate given parameter.
Parameters:
name - The actual name of the parameter to validate.
rule - The name of the parameter element that contains the rule that should be used for validation.
constraints - Configuration of all constraints for this parameter as taken from the description XML file.
conf - Configuration of all parameters as taken from the description XML file.
params - The map of parameters.
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.
Returns:
The validated parameter.


Copyright © 1999-2002 Apache Software Foundation. All Rights Reserved.