01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19:
20: package de.schlund.pfixcore.generator.casters;
21:
22: import java.text.ParseException;
23: import java.text.SimpleDateFormat;
24: import java.util.ArrayList;
25: import java.util.Date;
26:
27: import de.schlund.pfixcore.generator.IWrapperParamCaster;
28: import de.schlund.pfixcore.generator.SimpleCheck;
29: import de.schlund.pfixxml.RequestParam;
30: import de.schlund.util.statuscodes.StatusCode;
31: import de.schlund.util.statuscodes.StatusCodeLib;
32:
33: /**
34: * ToDate.java
35: *
36: *
37: * Created: Thu Aug 16 15:34:25 2001
38: *
39: * @author <a href="mailto:jtl@schlund.de">Jens Lautenbacher</a>
40: *
41: *
42: */
43:
44: public class ToDate extends SimpleCheck implements IWrapperParamCaster {
45: private Date[] value = null;
46: private SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
47: private StatusCode scode;
48:
49: public ToDate() {
50: scode = StatusCodeLib.PFIXCORE_GENERATOR_CASTER_ERR_TO_DATE;
51: }
52:
53: public void put_scode_casterror(String fqscode) {
54: scode = StatusCodeLib.getStatusCodeByName(fqscode);
55: }
56:
57: public void put_format(String fmtstr) {
58: format = new SimpleDateFormat(fmtstr);
59: }
60:
61: public Object[] getValue() {
62: return value;
63: }
64:
65: public void castValue(RequestParam[] param) {
66: reset();
67: format.setLenient(false);
68: Date val;
69: ArrayList<Date> dates = new ArrayList<Date>();
70: for (int i = 0; i < param.length; i++) {
71: try {
72: val = format.parse(param[i].getValue());
73: dates.add(val);
74: } catch (ParseException e) {
75: val = null;
76: addSCode(scode);
77: break;
78: }
79: }
80: if (!errorHappened()) {
81: value = dates.toArray(new Date[] {});
82: }
83: }
84:
85: }// ToDate
|