KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > l10n > DefaultDateFormatCfMod


1 /* ************************************************************************** *
2  * Copyright (C) 2004 NightLabs GmbH, Marco Schulze *
3  * All rights reserved. *
4  * http://www.NightLabs.de *
5  * *
6  * This program and the accompanying materials are free software; you can re- *
7  * distribute it and/or modify it under the terms of the GNU General Public *
8  * License as published by the Free Software Foundation; either ver 2 of the *
9  * License, or any later version. *
10  * *
11  * This module is distributed in the hope that it will be useful, but WITHOUT *
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FIT- *
13  * NESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more *
14  * details. *
15  * *
16  * You should have received a copy of the GNU General Public License along *
17  * with this module; if not, write to the Free Software Foundation, Inc.: *
18  * 59 Temple Place, Suite 330 *
19  * Boston MA 02111-1307 *
20  * USA *
21  * *
22  * Or get it online: *
23  * http://www.opensource.org/licenses/gpl-license.php *
24  * *
25  * In case, you want to use this module or parts of it in a proprietary pro- *
26  * ject, you can purchase it under the NightLabs Commercial License. Please *
27  * contact NightLabs GmbH under info AT nightlabs DOT com for more infos or *
28  * visit http://www.NightLabs.com *
29  * ************************************************************************** */

30
31 /*
32  * Created on Dec 23, 2004
33  */

34 package com.nightlabs.l10n;
35
36 import java.text.DateFormat JavaDoc;
37 import java.text.DateFormatSymbols JavaDoc;
38 import java.text.SimpleDateFormat JavaDoc;
39 import java.util.Locale JavaDoc;
40
41 import com.nightlabs.config.ConfigModule;
42 import com.nightlabs.config.InitException;
43
44 /**
45  * @author Marco Schulze - marco at nightlabs dot de
46  */

47 public class DefaultDateFormatCfMod extends ConfigModule
48 {
49     private String JavaDoc dateLong;
50     private String JavaDoc dateShort;
51     private String JavaDoc dateLongWeekday;
52     private String JavaDoc dateShortWeekday;
53     private String JavaDoc timeHM;
54     private String JavaDoc timeHMS;
55     private String JavaDoc timeHMSms;
56     private String JavaDoc[] weekDaysLong;
57     private String JavaDoc[] weekDaysShort;
58     private String JavaDoc[] monthsLong;
59     private String JavaDoc[] monthsShort;
60     private String JavaDoc[] amPmStrings;
61     private String JavaDoc[] eras;
62
63     public DefaultDateFormatCfMod()
64     {
65     }
66     
67     /**
68      * @see com.nightlabs.config.ConfigModule#getIdentifier()
69      */

70     public String JavaDoc getIdentifier()
71     {
72         return super.getIdentifier();
73     }
74     /**
75      * @see com.nightlabs.config.ConfigModule#setIdentifier(java.lang.String)
76      */

77     public void setIdentifier(String JavaDoc _identifier)
78     {
79         super.setIdentifier(_identifier);
80     }
81
82     /**
83      * @see com.nightlabs.config.ConfigModule#init()
84      */

85     public void init() throws InitException
86     {
87         String JavaDoc identifier = getIdentifier();
88         if (identifier == null)
89             throw new IllegalStateException JavaDoc("identifier of this ConfigModule is null! It should be the language/country-code (e.g. en_US)!");
90
91         String JavaDoc[] sa = identifier.split("_");
92         if (sa.length < 1)
93             throw new IllegalStateException JavaDoc("identifier of this ConfigModule is invalid (empty?!)! It should be the language/country-code (e.g. en_US)!");
94
95         String JavaDoc language = sa[0];
96         String JavaDoc country = null;
97         if (sa.length > 1)
98             country = sa[1];
99
100         Locale JavaDoc locale = new Locale JavaDoc(language, country);
101         
102         if (dateShort == null) {
103             DateFormat JavaDoc df = DateFormat.getDateInstance(DateFormat.SHORT, locale);
104             if (df instanceof SimpleDateFormat JavaDoc) {
105                 SimpleDateFormat JavaDoc sdf = (SimpleDateFormat JavaDoc)df;
106                 setDateShort(sdf.toPattern());
107             }
108             else
109                 setDateShort("yyyy-MM-dd");
110         }
111
112         if (dateShortWeekday == null)
113             setDateShortWeekday("EE, " + dateShort);
114
115         DateFormatSymbols JavaDoc dfs = new DateFormatSymbols JavaDoc(locale);
116
117         if (dateLong == null) {
118             DateFormat JavaDoc df = DateFormat.getDateInstance(DateFormat.LONG, locale);
119             if (df instanceof SimpleDateFormat JavaDoc) {
120                 SimpleDateFormat JavaDoc sdf = (SimpleDateFormat JavaDoc)df;
121                 setDateLong(sdf.toPattern());
122             }
123             else
124                 setDateLong("yyyy MMMM dd");
125         }
126
127         if (dateLongWeekday == null)
128             setDateLongWeekday("EEEE, " + dateLong);
129
130         if (timeHM == null) {
131             DateFormat JavaDoc df = DateFormat.getTimeInstance(DateFormat.SHORT, locale);
132             if (df instanceof SimpleDateFormat JavaDoc) {
133                 SimpleDateFormat JavaDoc sdf = (SimpleDateFormat JavaDoc)df;
134                 setTimeHM(sdf.toPattern());
135             }
136             else
137                 setTimeHM("HH:mm");
138         }
139
140         if (timeHMS == null) {
141             DateFormat JavaDoc df = DateFormat.getTimeInstance(DateFormat.MEDIUM, locale);
142             if (df instanceof SimpleDateFormat JavaDoc) {
143                 SimpleDateFormat JavaDoc sdf = (SimpleDateFormat JavaDoc)df;
144                 setTimeHMS(sdf.toPattern());
145             }
146             else
147                 setTimeHMS("HH:mm:ss");
148         }
149
150         if (timeHMSms == null)
151             setTimeHMSms("HH:mm:ss.SSS");
152
153         if (weekDaysLong == null)
154             weekDaysLong = dfs.getWeekdays();
155
156         if (weekDaysShort == null)
157             weekDaysShort = dfs.getShortWeekdays();
158
159         if (monthsLong == null)
160             monthsLong = dfs.getMonths();
161
162         if (monthsShort == null)
163             monthsShort = dfs.getShortMonths();
164
165         if (amPmStrings == null)
166             amPmStrings = dfs.getAmPmStrings();
167
168         if (eras == null)
169             eras = dfs.getEras();
170     }
171
172     /**
173      * @return Returns the dateLong.
174      */

175     public String JavaDoc getDateLong()
176     {
177         return dateLong;
178     }
179     /**
180      * @param dateLong The dateLong to set.
181      */

182     public void setDateLong(String JavaDoc dateLong)
183     {
184         this.dateLong = dateLong;
185         setChanged();
186     }
187     /**
188      * @return Returns the dateLongWeekday.
189      */

190     public String JavaDoc getDateLongWeekday()
191     {
192         return dateLongWeekday;
193     }
194     /**
195      * @param dateLongWeekday The dateLongWeekday to set.
196      */

197     public void setDateLongWeekday(String JavaDoc dateLongWeekday)
198     {
199         this.dateLongWeekday = dateLongWeekday;
200         setChanged();
201     }
202     /**
203      * @return Returns the dateShort.
204      */

205     public String JavaDoc getDateShort()
206     {
207         return dateShort;
208     }
209     /**
210      * @param dateShort The dateShort to set.
211      */

212     public void setDateShort(String JavaDoc dateShort)
213     {
214         this.dateShort = dateShort;
215         setChanged();
216     }
217     /**
218      * @return Returns the dateShortWeekday.
219      */

220     public String JavaDoc getDateShortWeekday()
221     {
222         return dateShortWeekday;
223     }
224     /**
225      * @param dateShortWeekday The dateShortWeekday to set.
226      */

227     public void setDateShortWeekday(String JavaDoc dateShortWeekday)
228     {
229         this.dateShortWeekday = dateShortWeekday;
230         setChanged();
231     }
232     /**
233      * @return Returns the timeHM.
234      */

235     public String JavaDoc getTimeHM()
236     {
237         return timeHM;
238     }
239     /**
240      * @param timeHM The timeHM to set.
241      */

242     public void setTimeHM(String JavaDoc timeHM)
243     {
244         this.timeHM = timeHM;
245         setChanged();
246     }
247     /**
248      * @return Returns the timeHMS.
249      */

250     public String JavaDoc getTimeHMS()
251     {
252         return timeHMS;
253     }
254     /**
255      * @param timeHMS The timeHMS to set.
256      */

257     public void setTimeHMS(String JavaDoc timeHMS)
258     {
259         this.timeHMS = timeHMS;
260         setChanged();
261     }
262     /**
263      * @return Returns the timeHMSms.
264      */

265     public String JavaDoc getTimeHMSms()
266     {
267         return timeHMSms;
268     }
269     /**
270      * @param timeHMSms The timeHMSms to set.
271      */

272     public void setTimeHMSms(String JavaDoc timeHMSms)
273     {
274         this.timeHMSms = timeHMSms;
275         setChanged();
276     }
277     /**
278      * @return Returns the amPmStrings.
279      */

280     public String JavaDoc[] getAmPmStrings()
281     {
282         return amPmStrings;
283     }
284     /**
285      * @param amPmStrings The amPmStrings to set.
286      */

287     public void setAmPmStrings(String JavaDoc[] amPmStrings)
288     {
289         this.amPmStrings = amPmStrings;
290         setChanged();
291     }
292     /**
293      * @return Returns the eras.
294      */

295     public String JavaDoc[] getEras()
296     {
297         return eras;
298     }
299     /**
300      * @param eras The eras to set.
301      */

302     public void setEras(String JavaDoc[] eras)
303     {
304         this.eras = eras;
305         setChanged();
306     }
307     /**
308      * @return Returns the monthsLong.
309      */

310     public String JavaDoc[] getMonthsLong()
311     {
312         return monthsLong;
313     }
314     /**
315      * @param monthsLong The monthsLong to set.
316      */

317     public void setMonthsLong(String JavaDoc[] monthsLong)
318     {
319         this.monthsLong = monthsLong;
320         setChanged();
321     }
322     /**
323      * @return Returns the monthsShort.
324      */

325     public String JavaDoc[] getMonthsShort()
326     {
327         return monthsShort;
328     }
329     /**
330      * @param monthsShort The monthsShort to set.
331      */

332     public void setMonthsShort(String JavaDoc[] monthsShort)
333     {
334         this.monthsShort = monthsShort;
335         setChanged();
336     }
337     /**
338      * @return Returns the weekDaysLong.
339      */

340     public String JavaDoc[] getWeekDaysLong()
341     {
342         return weekDaysLong;
343     }
344     /**
345      * @param weekDaysLong The weekDaysLong to set.
346      */

347     public void setWeekDaysLong(String JavaDoc[] weekDaysLong)
348     {
349         this.weekDaysLong = weekDaysLong;
350         setChanged();
351     }
352     /**
353      * @return Returns the weekDaysShort.
354      */

355     public String JavaDoc[] getWeekDaysShort()
356     {
357         return weekDaysShort;
358     }
359     /**
360      * @param weekDaysShort The weekDaysShort to set.
361      */

362     public void setWeekDaysShort(String JavaDoc[] weekDaysShort)
363     {
364         this.weekDaysShort = weekDaysShort;
365         setChanged();
366     }
367 }
368
Popular Tags