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 String
Error message pertaining to Rule that was brokenprotected org.apache.avalon.framework.logger.Logger
Loggingprotected int
The maximum length of the fieldprotected String
The message to show if field fails max-length testprotected int
The minimum length of the fieldprotected String
The message to show if field fails min-length testprotected boolean
A boolean value to signify if the field is definitely required or notprotected String
The 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 TypeMethodDescriptionvoid
assertValidity
(String testValue) Determine whether a testValue meets the criteria specified in the constraints defined for this validatorvoid
assertValidity
(Field<T> field) Determine whether a field meets the criteria specified in the constraints defined for this validatorvoid
enableLogging
(org.apache.avalon.framework.logger.Logger logger) Enable Avalon Loggingint
Get the value of maxLength.Get the value of maxLengthMessage.Get the error message resulting from invalid input.int
Get the value of minLength.Get the value of minLengthMessage.Get the value of requiredMessage.void
init
(Map<String, ? extends Constraint> paramMap) Extract the relevant parameters from the constraints listed in <rule> tags within the intake.xml file.boolean
Get the value of required.boolean
Deprecated.use isValid(Field) insteadboolean
Determine whether a field meets the criteria specified in the constraints defined for this validatorvoid
setMaxLength
(int maxLength) Set the value of maxLength.void
setMaxLengthMessage
(String maxLengthMessage) Set the value of maxLengthMessage.void
setMinLength
(int minLength) Set the value of minLength.void
setMinLengthMessage
(String minLengthMessage) Set the value of minLengthMessage.void
setRequired
(boolean required) Set the value of required.void
setRequiredMessage
(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:
enableLogging
in 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:
init
in interfaceInitableByConstraintMap
- Parameters:
paramMap
- aMap
ofRule
'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:
assertValidity
in interfaceValidator<T>
- Parameters:
field
- aField
to 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:
assertValidity
in interfaceValidator<T>
- Parameters:
testValue
- aString
to 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:
getMessage
in interfaceValidator<T>
- Returns:
- a
String
message, 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.
-