01: /* $Id: DateFormat.java 722 2006-10-30 10:15:22Z hengels $ */
02: package org.conform.format;
03:
04: import java.text.*;
05: import java.util.*;
06:
07: /**
08: * java.sql.Date
09: * @version $Revision: 722 $
10: */
11: public class DateFormat extends AbstractFormat {
12: public DateFormat() {
13: message = "validation.unparsableDate";
14: }
15:
16: public DateFormat(String pattern) {
17: message = "validation.unparsableDate";
18: this .pattern = pattern;
19: }
20:
21: public java.text.DateFormat getFormat() {
22: if (pattern != null)
23: return new SimpleDateFormat(pattern, FormatFactory
24: .getInstance().getLocale());
25: else
26: return java.text.DateFormat.getDateInstance(
27: java.text.DateFormat.SHORT, FormatFactory
28: .getInstance().getLocale());
29: }
30:
31: public String getHelp() {
32: return ((SimpleDateFormat) getFormat()).toPattern();
33: }
34:
35: public String format(Object value) {
36: return getFormat().format(value);
37: }
38:
39: public Object parse(String string) throws ParseException {
40: Date date = (Date) getFormat().parseObject(string);
41: return new java.sql.Date(date.getTime());
42: }
43: }
|