velosurf.validation
Class DateRange

java.lang.Object
  extended by velosurf.validation.FieldConstraint
      extended by velosurf.validation.DateRange

public class DateRange
extends FieldConstraint

A type and range constraint on dates. Syntax is:


    <column [type="date"] [after="date-after"] [before="date-before"] />
  

The type="date" parameter is implied when after or before is found.

Or:

     <column>
       <date [after="afer-date"] [before="before-date"] [format="SimpleDateFormat format"] [message="error-message"] />
     </column>
   

The format used to specify after and before dates is always yyyyMMdd. The format used to parse the input is by default the short local date format (which depends upon the user locale) but can be configured using the format attribute.

Author:
Claude Brisson

Field Summary
private  java.util.Date after
          afer date
private  java.util.Date before
          before date
private  java.text.SimpleDateFormat dateFormat
          date format
private static java.util.regex.Pattern y4
          'YYYY' date format.
private static java.text.DateFormat ymd
          yyyyMMdd date format.
 
Constructor Summary
DateRange()
          Constructor.
 
Method Summary
private static java.lang.String reformat(java.lang.String pattern, java.lang.String date)
          tries to reformat the date to match pattern conventions
 void setAfterDate(java.util.Date after)
          After date constraint setter.
 void setBeforeDate(java.util.Date before)
          Before date constraint setter.
 void setDateFormat(java.text.SimpleDateFormat dateFormat)
          date format setter.
 java.lang.String toString()
          return a string representation for this constraint.
 boolean validate(java.lang.Object data, java.util.Locale locale)
          Validate data against this constraint.
 
Methods inherited from class velosurf.validation.FieldConstraint
getMessage, setMessage, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

before

private java.util.Date before
before date


after

private java.util.Date after
afer date


dateFormat

private java.text.SimpleDateFormat dateFormat
date format


y4

private static final java.util.regex.Pattern y4
'YYYY' date format.


ymd

private static java.text.DateFormat ymd
yyyyMMdd date format.

Constructor Detail

DateRange

public DateRange()
Constructor.

Method Detail

setBeforeDate

public void setBeforeDate(java.util.Date before)
Before date constraint setter.

Parameters:
before - before date

setAfterDate

public void setAfterDate(java.util.Date after)
After date constraint setter.

Parameters:
after - afet date

validate

public boolean validate(java.lang.Object data,
                        java.util.Locale locale)
Validate data against this constraint.

Overrides:
validate in class FieldConstraint
Parameters:
data - data to validate
locale - locale to use
Returns:
whether data is valid

reformat

private static java.lang.String reformat(java.lang.String pattern,
                                         java.lang.String date)
tries to reformat the date to match pattern conventions

Parameters:
pattern - date pattern
date - date
Returns:
reformatted date

toString

public java.lang.String toString()
return a string representation for this constraint.

Overrides:
toString in class java.lang.Object
Returns:
string

setDateFormat

public void setDateFormat(java.text.SimpleDateFormat dateFormat)
date format setter.

Parameters:
dateFormat - date format


~ooOoo~