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

java.lang.Object
  extended byorg.apache.turbine.services.intake.validator.DefaultValidator
      extended byorg.apache.turbine.services.intake.validator.StringValidator
All Implemented Interfaces:
InitableByConstraintMap, Validator

public class StringValidator
extends DefaultValidator

A validator 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: StringValidator.java 534527 2007-05-02 16:10:59Z tv $
Author:
John McNally, Quinton McCombs, Colin Chalmers

Field Summary
protected  java.lang.String maskMessage
          The message to report if the mask constraint is not satisfied
protected  org.apache.oro.text.regex.Pattern maskPattern
          The compiled perl5 Regular expression from the ORO Perl5Compiler
protected  java.lang.String maskString
          The matching mask String as supplied by the XML input
 
Fields inherited from class org.apache.turbine.services.intake.validator.DefaultValidator
errorMessage, log, maxLength, maxLengthMessage, minLength, minLengthMessage, required, requiredMessage
 
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
StringValidator()
          Default constructor
StringValidator(java.util.Map paramMap)
          Constructor
 
Method Summary
 void assertValidity(java.lang.String testValue)
          Determine whether a testValue meets the criteria specified in the constraints defined for this validator
 java.lang.String getMask()
          Get the value of mask.
 java.lang.String getMaskMessage()
          Get the value of maskMessage.
 void init(java.util.Map paramMap)
          Extract the relevant parameters from the constraints listed in tags within the intake.xml file.
 boolean isValid(java.lang.String testValue)
          Determine whether a testValue meets the criteria specified in the constraints defined for this validator
 void setMask(java.lang.String mask)
          Set the value of mask.
 void setMaskMessage(java.lang.String message)
          Set the value of maskMessage.
 
Methods inherited from class org.apache.turbine.services.intake.validator.DefaultValidator
assertValidity, getMaxLength, getMaxLengthMessage, getMessage, getMinLength, getMinLengthMessage, getRequiredMessage, isRequired, isValid, setMaxLength, setMaxLengthMessage, setMinLength, setMinLengthMessage, setRequired, setRequiredMessage
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maskString

protected java.lang.String maskString
The matching mask String as supplied by the XML input


maskPattern

protected org.apache.oro.text.regex.Pattern maskPattern
The compiled perl5 Regular expression from the ORO Perl5Compiler


maskMessage

protected java.lang.String maskMessage
The message to report if the mask constraint is not satisfied

Constructor Detail

StringValidator

public StringValidator(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

StringValidator

public StringValidator()
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
Overrides:
init in class DefaultValidator
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(java.lang.String testValue)
Determine whether a testValue meets the criteria specified in the constraints defined for this validator

Specified by:
isValid in interface Validator
Overrides:
isValid in class DefaultValidator
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
Overrides:
assertValidity in class DefaultValidator
Parameters:
testValue - a String to be tested
Throws:
ValidationException - containing an error message if the testValue did not pass the validation tests.

getMask

public java.lang.String getMask()
Get the value of mask.

Returns:
value of mask.

setMask

public void setMask(java.lang.String mask)
             throws InvalidMaskException
Set the value of mask.

Parameters:
mask - Value to assign to mask.
Throws:
InvalidMaskException - the mask could not be compiled.

getMaskMessage

public java.lang.String getMaskMessage()
Get the value of maskMessage.

Returns:
value of maskMessage.

setMaskMessage

public void setMaskMessage(java.lang.String message)
Set the value of maskMessage.

Parameters:
message - Value to assign to maskMessage.


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