| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.student.common.validator; | 
  | 17 |  |   | 
  | 18 |  |  import java.text.SimpleDateFormat; | 
  | 19 |  |  import java.util.Date; | 
  | 20 |  |   | 
  | 21 | 31 |  public class ServerDateParser implements DateParser { | 
  | 22 |  |      | 
  | 23 | 2 |          private static ThreadLocal<SimpleDateFormat[]> formats = new ThreadLocal<SimpleDateFormat[]>() { | 
  | 24 |  |   | 
  | 25 |  |                  protected SimpleDateFormat[] initialValue() { | 
  | 26 | 1 |                          return new SimpleDateFormat[] { | 
  | 27 |  |                                      new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"),  | 
  | 28 |  |                                      new SimpleDateFormat("yyyy-MM-dd"),  | 
  | 29 |  |                                      new SimpleDateFormat("yyyy-MMM-dd"), | 
  | 30 |  |                                      new SimpleDateFormat("dd-MM-yyyy"), | 
  | 31 |  |                                      new SimpleDateFormat("dd-MMM-yyyy") | 
  | 32 |  |                      }; | 
  | 33 |  |                  } | 
  | 34 |  |   | 
  | 35 |  |          }; | 
  | 36 |  |           | 
  | 37 |  |       | 
  | 38 |  |      public Date parseDate(String input) { | 
  | 39 | 11 |          Date result = null; | 
  | 40 |  |           | 
  | 41 | 22 |          for (SimpleDateFormat format : formats.get()) { | 
  | 42 |  |                  try { | 
  | 43 | 22 |                      result = format.parse(input); | 
  | 44 | 11 |                  } catch (Exception e) { | 
  | 45 |  |                       | 
  | 46 | 11 |                  } | 
  | 47 | 22 |                  if (result != null) { | 
  | 48 | 11 |                      break; | 
  | 49 |  |                  } | 
  | 50 |  |               | 
  | 51 |  |          } | 
  | 52 |  |           | 
  | 53 | 11 |          if (result == null) { | 
  | 54 | 0 |              throw new DateParseException("Invalid date value: " + input); | 
  | 55 |  |          } | 
  | 56 |  |           | 
  | 57 | 11 |          return result; | 
  | 58 |  |      } | 
  | 59 |  |   | 
  | 60 |  |       | 
  | 61 |  |   | 
  | 62 |  |   | 
  | 63 |  |      @Override | 
  | 64 |  |      public String toString(Date date) { | 
  | 65 | 0 |          String result = null; | 
  | 66 | 0 |          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss,SSS"); | 
  | 67 | 0 |          result = format.format(date); | 
  | 68 |  |   | 
  | 69 | 0 |          return result;         | 
  | 70 |  |      } | 
  | 71 |  |  } |