[DS-401] Validate and reject invalid dates during submission.

git-svn-id: http://scm.dspace.org/svn/repo/dspace/trunk@5719 9c30dcfa-912a-0410-8fc2-9e0234be79fd
This commit is contained in:
Robin Taylor
2010-11-03 09:30:26 +00:00
parent 2f8d4170b7
commit ab0c2743da
6 changed files with 81 additions and 18 deletions

View File

@@ -150,7 +150,7 @@ public class DCDate
* @param ss
* the seconds
*/
public DCDate(int yyyy, int mm, int dd, int hh, int mn, int ss)
public DCDate(int yyyy, int mm, int dd, int hh, int mn, int ss) throws DCDateIllegalArgumentException
{
setUTCForFormatting();
@@ -194,8 +194,20 @@ public class DCDate
}
// Set the local calendar.
localCalendar = new GregorianCalendar(lyear, lmonth - 1, lday,
lhours, lminutes, lseconds);
localCalendar = new GregorianCalendar();
localCalendar.setLenient(false);
localCalendar.set(lyear, lmonth - 1, lday, lhours, lminutes, lseconds);
try
{
// Unfortunately GregorianCalendar doesn't throw an exception when you 'set' an invalid value so
// we have to call a method that causes all the values to be inspected in order to check that they are valid.
localCalendar.get(Calendar.YEAR);
}
catch (IllegalArgumentException e)
{
// Re-throw exception as a checked exception so that the calling classes have to deal with it.
throw new DCDateIllegalArgumentException("Invalid parameter", e);
}
if (granularity == DateGran.TIME)
{