01: /*
02: * Copyright 2004, 2005, 2006 Odysseus Software GmbH
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package de.odysseus.calyxo.forms.convert;
17:
18: import java.text.Format;
19: import java.text.ParseException;
20: import java.text.DateFormat;
21:
22: import java.util.Date;
23: import java.util.Locale;
24:
25: /**
26: * Time converter.
27: *
28: * @author Oliver Stuhr
29: */
30: public class TimeConverter extends FormatBasedConverter implements
31: Cloneable {
32:
33: /**
34: * Default constructor.
35: */
36: public TimeConverter() {
37: super ();
38: }
39:
40: /**
41: * Create date format instance
42: */
43: protected Format createFormat(Locale locale) {
44: DateFormat f = DateFormat.getTimeInstance(DateFormat.SHORT,
45: locale);
46: adapt(f);
47: return f;
48: }
49:
50: /**
51: * Adapt date format instance (sets <code>lenient</code> property to <code>false</code>).
52: */
53: protected void adapt(DateFormat format) {
54: format.setLenient(false);
55: }
56:
57: /**
58: * Format method.
59: */
60: public String format(Object value) {
61: return super .format((Date) value);
62: }
63:
64: /**
65: * Parse method.
66: */
67: public Object parse(String value) throws ParseException {
68: return super.parse(value == null ? null : value.trim());
69: }
70: }
|