Class DateStringValidator

java.lang.Object
org.apache.fulcrum.intake.validator.DefaultValidator<Date>
org.apache.fulcrum.intake.validator.DateStringValidator
All Implemented Interfaces:
org.apache.avalon.framework.logger.LogEnabled, InitableByConstraintMap, Validator<Date>
Direct Known Subclasses:
DateRangeValidator

public class DateStringValidator extends DefaultValidator<Date>
Validates numbers with the following constraints in addition to those listed in DefaultValidator.
Validation rules
NameValid ValuesDefault Value
formatsee SimpleDateFormat javadoc  
formatxsee SimpleDateFormat javadoc  
where x is >= 1 to specify multiple date formats. Only one format rule should have a message
flexibletrue, as long as DateFormat can parse the date, allow it, and false false
Version:
$Id$
Author:
John McNally, Quinton McCombs, Colin Chalmers, Jürgen Hoffmann, Scott Eade
  • Constructor Details

    • DateStringValidator

      public DateStringValidator()
      Default Constructor
  • Method Details

    • init

      public void init(Map<String,? extends Constraint> paramMap) throws InvalidMaskException
      Constructor to use when initializing Object
      Specified by:
      init in interface InitableByConstraintMap
      Overrides:
      init in class DefaultValidator<Date>
      Parameters:
      paramMap - a map of parameters
      Throws:
      InvalidMaskException - one of the mask rules is invalid
    • assertValidity

      public void assertValidity(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<Date>
      Overrides:
      assertValidity in class DefaultValidator<Date>
      Parameters:
      testValue - a String to be tested
      Throws:
      ValidationException - containing an error message if the testValue did not pass the validation tests.
    • parse

      public Date parse(String s) throws ParseException
      Parses the String s according to the rules/formats for this validator. The formats provided by the "formatx" rules (where x is >= 1) are used before the "format" rules to allow for a display format that includes a 4 digit year, but that will parse the date using a format that accepts 2 digit years.
      Parameters:
      s - possibly a date string
      Returns:
      the date parsed
      Throws:
      ParseException - indicates that the string could not be parsed into a date.
    • format

      public String format(Date date)
      Formats a date into a String. The format used is from the first format rule found for the field.
      Parameters:
      date - the Date object to convert into a string.
      Returns:
      formatted date
    • getDateFormatMessage

      public String getDateFormatMessage()
      Get the value of minLengthMessage.
      Returns:
      value of minLengthMessage.
    • setDateFormatMessage

      public void setDateFormatMessage(String message)
      Only sets the message if the new message has some information. So the last setMessage call with valid data wins. But later calls with null or empty string will not affect a previous valid setting.
      Parameters:
      message - Value to assign to minLengthMessage.
    • getDateFormats

      public List<String> getDateFormats()
      Get the value of dateFormats.
      Returns:
      value of dateFormats.
    • setDateFormats

      public void setDateFormats(List<String> formats)
      Set the value of dateFormats.
      Parameters:
      formats - Value to assign to dateFormats.
    • isFlexible

      public boolean isFlexible()
      Get the value of flexible.
      Returns:
      value of flexible.
    • setFlexible

      public void setFlexible(boolean flexible)
      Set the value of flexible.
      Parameters:
      flexible - Value to assign to flexible.