project35.soa.validation
Class DateValidator

java.lang.Object
  extended by project35.soa.validation.AbstractEditFieldValidationService
      extended by project35.soa.validation.DateValidator
All Implemented Interfaces:
java.io.Serializable, ServiceClass, EditFieldValidationService, FieldValidationService

public class DateValidator
extends AbstractEditFieldValidationService

In Project35, the user can establish which format they want to use to express date values. These formats are supported:

The date values that appear in files always appear in a canonical date format.

Much of the validation behaviour depended on the SimpleDateFormat class features. However, the date format class had some shortcomings and didn't seem to do boundary checking on values for year, month or day. For example, you can accidentally enter "45" for a day number and it won't complain. This class does a lot of things the SimpleDateFormat class SHOULD have been doing but didn't.


Copyright (c) 2008 Kevin Garwood for Project35. The original code was developed by Kevin Garwood for the University of Manchester. Revisions have been made for Project35, a project that is independent of that institution. This code is licensed under the Academic Free License version 3.0. The code attribution for the original code is included here:

Copyright (c) Kevin Garwood and University of Manchester 2007. All rights reserved. Licensed under the Academic Free License version 3.0. For more information on the terms and conditions, please see the file "LICENSE" that is included in this distribution.


Version:
1.0
Author:
Kevin Garwood (kgarwood@users.sourceforge.net)
See Also:
Serialized Form

Field Summary
static java.text.SimpleDateFormat canonicalFormat
          format used to read/write date values from file
static java.text.SimpleDateFormat ddmmyyyyFormat
          indicates DD/MM/YYYY format
static java.text.SimpleDateFormat mmddyyyyFormat
          indicates MM/DD/YYYY format
static java.text.SimpleDateFormat yyyymmddFormat
          indicates YYYY/MM/DD format
 
Fields inherited from class project35.soa.validation.AbstractEditFieldValidationService
collator
 
Constructor Summary
DateValidator()
           
 
Method Summary
static java.util.Date getCanonicalDate(java.lang.String date)
          string date
static java.text.SimpleDateFormat getCanonicalFormat()
           
static java.lang.String getCanonicalValue(java.util.Date date)
           
static java.util.Date getDate(java.lang.String date)
           
static java.text.SimpleDateFormat getDateFormat()
          gets the current date format
static java.lang.String getDateFormatString(java.text.SimpleDateFormat format)
           
static java.lang.String getDateValue(java.util.Date date)
          a date
static void setDateFormat(java.text.SimpleDateFormat format)
          sets the date format used to do validation
static void setDefaultDateFormat()
          sets date format to ddmmyyyy format
 java.util.ArrayList validate(Project35FormContext project35FormContext, java.lang.String value)
          assumes that the string value passed to it will always be written in a canonical form.
 
Methods inherited from class project35.soa.validation.AbstractEditFieldValidationService
getFieldName, getInitialisationParameters, initialiseService, isEmpty, isFieldRequired, setFieldName, setRequiredField, validateRequiredField
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

canonicalFormat

public static final java.text.SimpleDateFormat canonicalFormat
format used to read/write date values from file


ddmmyyyyFormat

public static final java.text.SimpleDateFormat ddmmyyyyFormat
indicates DD/MM/YYYY format


mmddyyyyFormat

public static final java.text.SimpleDateFormat mmddyyyyFormat
indicates MM/DD/YYYY format


yyyymmddFormat

public static final java.text.SimpleDateFormat yyyymmddFormat
indicates YYYY/MM/DD format

Constructor Detail

DateValidator

public DateValidator()
Method Detail

getCanonicalDate

public static java.util.Date getCanonicalDate(java.lang.String date)
string date

Returns:
Date object

getCanonicalFormat

public static java.text.SimpleDateFormat getCanonicalFormat()
Returns:
the canonical date format used for validation

getDateFormat

public static java.text.SimpleDateFormat getDateFormat()
gets the current date format

Returns:
the current date format

getDateFormatString

public static java.lang.String getDateFormatString(java.text.SimpleDateFormat format)
Parameters:
format - returns the pattern corresponding to the date format
Returns:
the string representation of the date format pattern

getCanonicalValue

public static java.lang.String getCanonicalValue(java.util.Date date)
Parameters:
date - a date object
Returns:
the formatted date value based on the canonical date format.

getDate

public static java.util.Date getDate(java.lang.String date)
Parameters:
date - string representation of a date
Returns:
a date object

getDateValue

public static java.lang.String getDateValue(java.util.Date date)
a date

Returns:
a formatted date value based on the current date format

setDateFormat

public static void setDateFormat(java.text.SimpleDateFormat format)
sets the date format used to do validation

Parameters:
format - the new date format used for validation

setDefaultDateFormat

public static void setDefaultDateFormat()
sets date format to ddmmyyyy format


validate

public java.util.ArrayList validate(Project35FormContext project35FormContext,
                                    java.lang.String value)
assumes that the string value passed to it will always be written in a canonical form.

Specified by:
validate in interface EditFieldValidationService
Specified by:
validate in class AbstractEditFieldValidationService
value - the value of the field
Returns:
a collection of Alert instances that represent errors,warnings,points of information or requests for more information if no errors were found