View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.r1.common.validator;
17  
18  import java.text.SimpleDateFormat;
19  import java.util.Date;
20  
21  @Deprecated
22  public class ServerDateParser implements DateParser {
23     
24  	private static ThreadLocal<SimpleDateFormat[]> formats = new ThreadLocal<SimpleDateFormat[]>() {
25  
26  		protected SimpleDateFormat[] initialValue() {
27  			return new SimpleDateFormat[] {
28  		    		new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ"), 
29  		    		new SimpleDateFormat("yyyy-MM-dd"), 
30  		    		new SimpleDateFormat("yyyy-MMM-dd"),
31  		    		new SimpleDateFormat("dd-MM-yyyy"),
32  		    		new SimpleDateFormat("dd-MMM-yyyy")
33  		    };
34  		}
35  
36  	};
37  	
38      
39      public Date parseDate(String input) {
40          Date result = null;
41          
42          for (SimpleDateFormat format : formats.get()) {
43                  try {
44                      result = format.parse(input);
45                  } catch (Exception e) {
46                      // just eat it
47                  }
48                  if (result != null) {
49                      break;
50                  }
51              
52          }
53          
54          if (result == null) {
55              throw new DateParseException("Invalid date value: " + input);
56          }
57          
58          return result;
59      }
60  
61      /**
62       * @see org.kuali.student.r1.common.validator.old.DateParser#toString(java.util.Date)
63       */
64      @Override
65      public String toString(Date date) {
66          String result = null;
67          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-ddTHH:mm:ss,SSS");
68          result = format.format(date);
69  
70          return result;        
71      }
72  }