org.apache.turbine.services.intake.validator
Class DefaultValidator

java.lang.Object
  extended byorg.apache.turbine.services.intake.validator.DefaultValidator
All Implemented Interfaces:
InitableByConstraintMap, Validator
Direct Known Subclasses:
BooleanValidator, DateStringValidator, FileValidator, org.apache.turbine.services.intake.validator.NumberValidator, StringValidator

public abstract class DefaultValidator
extends java.lang.Object
implements Validator, InitableByConstraintMap

DefaultValidator that will compare a testValue against the following constraints:

NameValid ValuesDefault Value
requiredtrue|falsefalse
maskregexp 
minLengthinteger0
maxLengthinteger 
This validator can serve as the base class for more specific validators

Version:
$Id: DefaultValidator.java 538796 2007-05-17 03:19:16Z seade $
Author:
John McNally, Quinton McCombs, Colin Chalmers, Thomas Vandahl

Field Summary
protected  java.lang.String errorMessage
          Error message pertaining to Rule that was broken
protected  org.apache.commons.logging.Log log
          Logging
protected  int maxLength
          The maximum length of the field
protected  java.lang.String maxLengthMessage
          The message to show if field fails max-length test
protected  int minLength
          The minimum length of the field
protected  java.lang.String minLengthMessage
          The message to show if field fails min-length test
protected  boolean required
          A boolean value to signify if the field is definately required or not
protected  java.lang.String requiredMessage
          The message to show if field fails required test
 
Fields inherited from interface org.apache.turbine.services.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
DefaultValidator()
          Default constructor
DefaultValidator(java.util.Map paramMap)
          Constructor
 
Method Summary
 void assertValidity(Field field)
          Determine whether a field meets the criteria specified in the constraints defined for this validator
 void assertValidity(java.lang.String testValue)
          Determine whether a testValue meets the criteria specified in the constraints defined for this validator
 int getMaxLength()
          Get the value of maxLength.
 java.lang.String getMaxLengthMessage()
          Get the value of maxLengthMessage.
 java.lang.String getMessage()
          Get the error message resulting from invalid input.
 int getMinLength()
          Get the value of minLength.
 java.lang.String getMinLengthMessage()
          Get the value of minLengthMessage.
 java.lang.String getRequiredMessage()
          Get the value of requiredMessage.
 void init(java.util.Map paramMap)
          Extract the relevant parameters from the constraints listed in tags within the intake.xml file.
 boolean isRequired()
          Get the value of required.
 boolean isValid(Field field)
          Determine whether a field meets the criteria specified in the constraints defined for this validator
 boolean isValid(java.lang.String testValue)
          Deprecated. use isValid(Field) instead
 void setMaxLength(int maxLength)
          Set the value of maxLength.
 void setMaxLengthMessage(java.lang.String maxLengthMessage)
          Set the value of maxLengthMessage.
 void setMinLength(int minLength)
          Set the value of minLength.
 void setMinLengthMessage(java.lang.String minLengthMessage)
          Set the value of minLengthMessage.
 void setRequired(boolean required)
          Set the value of required.
 void setRequiredMessage(java.lang.String requiredMessage)
          Set the value of requiredMessage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

required

protected boolean required
A boolean value to signify if the field is definately required or not


requiredMessage

protected java.lang.String requiredMessage
The message to show if field fails required test


minLength

protected int minLength
The minimum length of the field


minLengthMessage

protected java.lang.String minLengthMessage
The message to show if field fails min-length test


maxLength

protected int maxLength
The maximum length of the field


maxLengthMessage

protected java.lang.String maxLengthMessage
The message to show if field fails max-length test


errorMessage

protected java.lang.String errorMessage
Error message pertaining to Rule that was broken


log

protected org.apache.commons.logging.Log log
Logging

Constructor Detail

DefaultValidator

public DefaultValidator(java.util.Map paramMap)
                 throws InvalidMaskException
Constructor

Parameters:
paramMap - a Map of Rule's containing constraints on the input.
Throws:
InvalidMaskException - An invalid mask was specified for one of the rules

DefaultValidator

public DefaultValidator()
Default constructor

Method Detail

init

public void init(java.util.Map paramMap)
          throws InvalidMaskException
Extract the relevant parameters from the constraints listed in tags within the intake.xml file.

Specified by:
init in interface InitableByConstraintMap
Parameters:
paramMap - a Map of Rule's containing constraints on the input.
Throws:
InvalidMaskException - An invalid mask was specified for one of the rules

isValid

public boolean isValid(Field field)
Determine whether a field meets the criteria specified in the constraints defined for this validator

Specified by:
isValid in interface Validator
Parameters:
field - a Field to be tested
Returns:
true if valid, false otherwise

assertValidity

public void assertValidity(Field field)
                    throws ValidationException
Determine whether a field meets the criteria specified in the constraints defined for this validator

Specified by:
assertValidity in interface Validator
Parameters:
field - a Field to be tested
Throws:
ValidationException - containing an error message if the testValue did not pass the validation tests.

isValid

public boolean isValid(java.lang.String testValue)
Deprecated. use isValid(Field) instead

Determine whether a testValue meets the criteria specified in the constraints defined for this validator

Specified by:
isValid in interface Validator
Parameters:
testValue - a String to be tested
Returns:
true if valid, false otherwise

assertValidity

public void assertValidity(java.lang.String testValue)
                    throws ValidationException
Determine whether a testValue meets the criteria specified in the constraints defined for this validator

Specified by:
assertValidity in interface Validator
Parameters:
testValue - a String to be tested
Throws:
ValidationException - containing an error message if the testValue did not pass the validation tests.

getMessage

public java.lang.String getMessage()
Get the error message resulting from invalid input.

Specified by:
getMessage in interface Validator
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

public java.lang.String getRequiredMessage()
Get the value of requiredMessage.

Returns:
value of requiredMessage.

setRequiredMessage

public void setRequiredMessage(java.lang.String requiredMessage)
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

public java.lang.String getMinLengthMessage()
Get the value of minLengthMessage.

Returns:
value of minLengthMessage.

setMinLengthMessage

public void setMinLengthMessage(java.lang.String minLengthMessage)
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

public java.lang.String getMaxLengthMessage()
Get the value of maxLengthMessage.

Returns:
value of maxLengthMessage.

setMaxLengthMessage

public void setMaxLengthMessage(java.lang.String maxLengthMessage)
Set the value of maxLengthMessage.

Parameters:
maxLengthMessage - Value to assign to maxLengthMessage.


Copyright © 2000-2008 Apache Software Foundation. All Rights Reserved.