Added methods for getting SQL dates to match the methods for getting util

dates.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@1827 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2006-04-17 01:38:45 +00:00
parent ccebc24367
commit 1e518d06bb
@@ -36,6 +36,11 @@ import com.samskivert.util.StringUtil;
*/
public class ParameterUtil
{
/** A default date that can be placed in fields to communicate the
* appropriate format. Is treated the same as the empty string by {@link
* #getDateParameter}. */
public static final String DATE_TEMPLATE = "YYYY-MM-DD";
/**
* An interface for validating form parameters.
*/
@@ -260,6 +265,17 @@ public class ParameterUtil
invalidDataMessage);
}
/**
* Similar to {@link #requireDateParameter} but returns a SQL date.
*/
public static java.sql.Date requireSQLDateParameter (
HttpServletRequest req, String name, String invalidDataMessage)
throws DataValidationException
{
return new java.sql.Date(
requireDateParameter(req, name, invalidDataMessage).getTime());
}
/**
* Fetches the supplied parameter from the request and converts it to
* a date. The value of the parameter should be a date formatted like
@@ -272,12 +288,24 @@ public class ParameterUtil
throws DataValidationException
{
String value = getParameter(req, name, false);
if (StringUtil.isBlank(value)) {
if (StringUtil.isBlank(value) ||
DATE_TEMPLATE.equalsIgnoreCase(value)) {
return null;
}
return parseDateParameter(value, invalidDataMessage);
}
/**
* Similar to {@link #getDateParameter} but returns a SQL date.
*/
public static java.sql.Date getSQLDateParameter (
HttpServletRequest req, String name, String invalidDataMessage)
throws DataValidationException
{
Date when = getDateParameter(req, name, invalidDataMessage);
return (when == null) ? null : new java.sql.Date(when.getTime());
}
/**
* Returns true if the specified parameter is set in the request.
*