01: /*
02: * Copyright 2001-2007 Hippo (www.hippo.nl)
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 nl.hippo.cms.wizard.widgets;
17:
18: import java.text.SimpleDateFormat;
19: import java.util.Date;
20:
21: import nl.hippo.cms.wizard.Constants;
22: import nl.hippo.cms.wizard.components.Configuration;
23:
24: public class DateWidget extends AbstractWidget {
25:
26: public static final String TYPE = "date";
27: private String displayFormat;
28: private String outputFormat;
29: private String pathFormat;
30: private Object value;
31:
32: //@Override
33: public Object getValue() {
34: return value;
35: }
36:
37: public void setValue(Object object) {
38: value = object;
39: }
40:
41: //@Override
42: public void configure(Configuration config) throws Exception {
43: super .configure(config);
44: outputFormat = (config
45: .get(Constants.DATE_OUTPUT_FORMAT_ATTRIBUTE_NAME));
46: displayFormat = (config
47: .get(Constants.DATE_DISPLAY_FORMAT_ATTRIBUTE_NAME));
48: pathFormat = (config
49: .get(Constants.DATE_PATH_FORMAT_ATTRIBUTE_NAME));
50: }
51:
52: //@Override
53: public String getPath() {
54: return getURIValue();
55: }
56:
57: public String getURIValue() {
58:
59: String strOutDt = "";
60: try {
61: String strTmp = value.toString();
62: Date dtTmp = new SimpleDateFormat(outputFormat)
63: .parse(strTmp);
64: strOutDt = new SimpleDateFormat(pathFormat).format(dtTmp);
65: } catch (Exception e) {
66:
67: }
68: return strOutDt;
69: }
70:
71: public String getPathFormat() {
72: return pathFormat;
73: }
74:
75: public String getDisplayFormat() {
76: return displayFormat;
77: }
78:
79: public String getStoreFormat() {
80: return outputFormat;
81: }
82:
83: public String getType() {
84: return TYPE;
85: }
86: }
|