01: package com.technoetic.xplanner.format;
02:
03: import javax.servlet.http.HttpServletRequest;
04: import javax.servlet.jsp.PageContext;
05: import java.text.ParseException;
06: import java.text.SimpleDateFormat;
07: import java.util.Date;
08:
09: public class DateFormat extends AbstractFormat {
10: private java.text.DateFormat format = null;
11:
12: public DateFormat(HttpServletRequest request) {
13: String format = getFormat(request, "format.date");
14: if (format != null) {
15: this .format = new SimpleDateFormat(format);
16: } else {
17: this .format = java.text.DateFormat.getDateInstance(
18: java.text.DateFormat.SHORT, request.getLocale());
19: }
20: }
21:
22: public String format(Date value) {
23: return format.format(value);
24: }
25:
26: public Date parse(String value) throws ParseException {
27: return format.parse(value);
28: }
29:
30: public static String format(PageContext pageContext, Date value) {
31: return new DateFormat((HttpServletRequest) pageContext
32: .getRequest()).format(value);
33: }
34:
35: public static String format(HttpServletRequest request, Date value) {
36: return new DateFormat(request).format(value);
37: }
38:
39: public static Date parse(PageContext pageContext, String dateString)
40: throws ParseException {
41: return new DateFormat((HttpServletRequest) pageContext
42: .getRequest()).parse(dateString);
43: }
44:
45: }
|