01: // /////////////////////////////
02: // Makumba, Makumba tag library
03: // Copyright (C) 2000-2003 http://www.makumba.org
04: //
05: // This library is free software; you can redistribute it and/or
06: // modify it under the terms of the GNU Lesser General Public
07: // License as published by the Free Software Foundation; either
08: // version 2.1 of the License, or (at your option) any later version.
09: //
10: // This library is distributed in the hope that it will be useful,
11: // but WITHOUT ANY WARRANTY; without even the implied warranty of
12: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: // Lesser General Public License for more details.
14: //
15: // You should have received a copy of the GNU Lesser General Public
16: // License along with this library; if not, write to the Free Software
17: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: //
19: // -------------
20: // $Id: dateFormatter.java 1688 2007-09-25 12:54:46Z manuel_gay $
21: // $Name$
22: /////////////////////////////////////
23:
24: package org.makumba.commons.formatters;
25:
26: import java.text.DateFormat;
27: import java.text.SimpleDateFormat;
28: import java.util.Calendar;
29: import java.util.Dictionary;
30: import java.util.GregorianCalendar;
31:
32: public class dateFormatter extends FieldFormatter {
33: static String[] _params = { "default", "empty", "format" };
34:
35: static String[][] _paramValues = { null, null, null };
36:
37: public String[] getAcceptedParams() {
38: return _params;
39: }
40:
41: public String[][] getAcceptedValue() {
42: return _paramValues;
43: }
44:
45: private static final class SingletonHolder {
46: static final FieldFormatter singleton = new dateFormatter();
47: }
48:
49: /** Don't use this, use getInstance() */
50: protected dateFormatter() {
51: }
52:
53: public static FieldFormatter getInstance() {
54: return SingletonHolder.singleton;
55: }
56:
57: public String formatNotNull(RecordFormatter rf, int fieldIndex,
58: Object o, Dictionary formatParams) {
59: DateFormat formatter = yearDate;
60: String s = (String) formatParams.get("format");
61: if (s != null) {
62: formatter = new SimpleDateFormat(s,
63: org.makumba.MakumbaSystem.getLocale());
64: formatter.setCalendar(calendar);
65: }
66:
67: return formatter.format((java.util.Date) o);
68: }
69:
70: public static final Calendar calendar;
71:
72: public static final DateFormat yearDate;
73:
74: public static final DateFormat debugTime;
75:
76: static {
77: calendar = new GregorianCalendar(org.makumba.MakumbaSystem
78: .getTimeZone());
79: yearDate = new SimpleDateFormat("dd MMMM yyyy",
80: org.makumba.MakumbaSystem.getLocale());
81: debugTime = new SimpleDateFormat("d MMMM yyyy HH:mm:ss zzz",
82: org.makumba.MakumbaSystem.getLocale());
83: yearDate.setCalendar(calendar);
84: debugTime.setCalendar(calendar);
85: }
86: }
|