Class DefaultValidator<T>
java.lang.Object
org.apache.fulcrum.intake.validator.DefaultValidator<T>
- All Implemented Interfaces:
org.apache.avalon.framework.logger.LogEnabled,InitableByConstraintMap,Validator<T>
- Direct Known Subclasses:
BooleanValidator,DateStringValidator,FileValidator,NumberValidator,StringValidator
public abstract class DefaultValidator<T>
extends Object
implements Validator<T>, InitableByConstraintMap, org.apache.avalon.framework.logger.LogEnabled
DefaultValidator that will compare a testValue against the following
constraints:
This validator can serve as the base class for more specific validators
| Name | Valid Values | Default Value |
|---|---|---|
| required | true|false | false |
| mask | regexp | |
| minLength | integer | 0 |
| maxLength | integer |
- Version:
- $Id$
- Author:
- John McNally, Quinton McCombs, Colin Chalmers, Thomas Vandahl
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringError message pertaining to Rule that was brokenprotected org.apache.avalon.framework.logger.LoggerLoggingprotected intThe maximum length of the fieldprotected StringThe message to show if field fails max-length testprotected intThe minimum length of the fieldprotected StringThe message to show if field fails min-length testprotected booleanA boolean value to signify if the field is definitely required or notprotected StringThe message to show if field fails required testFields inherited from interface org.apache.fulcrum.intake.validator.Validator
FLEXIBLE_RULE_NAME, FORMAT_RULE_NAME, INVALID_NUMBER_RULE_NAME, MASK_RULE_NAME, MAX_LENGTH_RULE_NAME, MAX_VALUE_RULE_NAME, MIN_LENGTH_RULE_NAME, MIN_VALUE_RULE_NAME, REQUIRED_RULE_NAME -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidassertValidity(String testValue) Determine whether a testValue meets the criteria specified in the constraints defined for this validatorvoidassertValidity(Field<T> field) Determine whether a field meets the criteria specified in the constraints defined for this validatorvoidenableLogging(org.apache.avalon.framework.logger.Logger logger) Enable Avalon LoggingintGet the value of maxLength.Get the value of maxLengthMessage.Get the error message resulting from invalid input.intGet the value of minLength.Get the value of minLengthMessage.Get the value of requiredMessage.voidinit(Map<String, ? extends Constraint> paramMap) Extract the relevant parameters from the constraints listed in <rule> tags within the intake.xml file.booleanGet the value of required.booleanDeprecated.use isValid(Field) insteadbooleanDetermine whether a field meets the criteria specified in the constraints defined for this validatorvoidsetMaxLength(int maxLength) Set the value of maxLength.voidsetMaxLengthMessage(String maxLengthMessage) Set the value of maxLengthMessage.voidsetMinLength(int minLength) Set the value of minLength.voidsetMinLengthMessage(String minLengthMessage) Set the value of minLengthMessage.voidsetRequired(boolean required) Set the value of required.voidsetRequiredMessage(String requiredMessage) Set the value of requiredMessage.
-
Field Details
-
required
protected boolean requiredA boolean value to signify if the field is definitely required or not -
requiredMessage
The message to show if field fails required test -
minLength
protected int minLengthThe minimum length of the field -
minLengthMessage
The message to show if field fails min-length test -
maxLength
protected int maxLengthThe maximum length of the field -
maxLengthMessage
The message to show if field fails max-length test -
errorMessage
Error message pertaining to Rule that was broken -
log
protected org.apache.avalon.framework.logger.Logger logLogging
-
-
Constructor Details
-
DefaultValidator
public DefaultValidator()Default constructor
-
-
Method Details
-
enableLogging
public void enableLogging(org.apache.avalon.framework.logger.Logger logger) Enable Avalon Logging- Specified by:
enableLoggingin interfaceorg.apache.avalon.framework.logger.LogEnabled
-
init
Extract the relevant parameters from the constraints listed in <rule> tags within the intake.xml file.- Specified by:
initin interfaceInitableByConstraintMap- Parameters:
paramMap- aMapofRule's containing constraints on the input.- Throws:
InvalidMaskException- An invalid mask was specified for one of the rules
-
isValid
Determine whether a field meets the criteria specified in the constraints defined for this validator -
assertValidity
Determine whether a field meets the criteria specified in the constraints defined for this validator- Specified by:
assertValidityin interfaceValidator<T>- Parameters:
field- aFieldto be tested- Throws:
ValidationException- containing an error message if the testValue did not pass the validation tests.
-
isValid
Deprecated.use isValid(Field) insteadDetermine whether a testValue meets the criteria specified in the constraints defined for this validator -
assertValidity
Determine whether a testValue meets the criteria specified in the constraints defined for this validator- Specified by:
assertValidityin interfaceValidator<T>- Parameters:
testValue- aStringto be tested- Throws:
ValidationException- containing an error message if the testValue did not pass the validation tests.
-
getMessage
Get the error message resulting from invalid input.- Specified by:
getMessagein interfaceValidator<T>- Returns:
- a
Stringmessage, or the empty String "".
-
isRequired
public boolean isRequired()Get the value of required.- Returns:
- value of required.
-
setRequired
public void setRequired(boolean required) Set the value of required.- Parameters:
required- Value to assign to required.
-
getRequiredMessage
Get the value of requiredMessage.- Returns:
- value of requiredMessage.
-
setRequiredMessage
Set the value of requiredMessage.- Parameters:
requiredMessage- Value to assign to requiredMessage.
-
getMinLength
public int getMinLength()Get the value of minLength.- Returns:
- value of minLength.
-
setMinLength
public void setMinLength(int minLength) Set the value of minLength.- Parameters:
minLength- Value to assign to minLength.
-
getMinLengthMessage
Get the value of minLengthMessage.- Returns:
- value of minLengthMessage.
-
setMinLengthMessage
Set the value of minLengthMessage.- Parameters:
minLengthMessage- Value to assign to minLengthMessage.
-
getMaxLength
public int getMaxLength()Get the value of maxLength.- Returns:
- value of maxLength.
-
setMaxLength
public void setMaxLength(int maxLength) Set the value of maxLength.- Parameters:
maxLength- Value to assign to maxLength.
-
getMaxLengthMessage
Get the value of maxLengthMessage.- Returns:
- value of maxLengthMessage.
-
setMaxLengthMessage
Set the value of maxLengthMessage.- Parameters:
maxLengthMessage- Value to assign to maxLengthMessage.
-