KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ivata > groupware > util > SettingDateFormatter


1 /*
2  * Copyright (c) 2001 - 2005 ivata limited.
3  * All rights reserved.
4  * -----------------------------------------------------------------------------
5  * ivata groupware may be redistributed under the GNU General Public
6  * License as published by the Free Software Foundation;
7  * version 2 of the License.
8  *
9  * These programs are free software; you can redistribute them and/or
10  * modify them under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; version 2 of the License.
12  *
13  * These programs are distributed in the hope that they will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License in the file LICENSE.txt for more
18  * details.
19  *
20  * If you would like a copy of the GNU General Public License write to
21  *
22  * Free Software Foundation, Inc.
23  * 59 Temple Place - Suite 330
24  * Boston, MA 02111-1307, USA.
25  *
26  *
27  * To arrange commercial support and licensing, contact ivata at
28  * http://www.ivata.com/contact.jsp
29  * -----------------------------------------------------------------------------
30  * $Log: SettingDateFormatter.java,v $
31  * Revision 1.2.2.1 2005/10/08 17:32:37 colinmacleod
32  * Now requires SecuritySession in the constructor.
33  *
34  * Revision 1.2 2005/04/09 17:19:58 colinmacleod
35  * Changed copyright text to GPL v2 explicitly.
36  *
37  * Revision 1.1.1.1 2005/03/10 17:51:45 colinmacleod
38  * Restructured ivata op around Hibernate/PicoContainer.
39  * Renamed ivata groupware.
40  *
41  * Revision 1.3 2004/11/12 15:57:20 colinmacleod
42  * Removed dependencies on SSLEXT.
43  * Moved Persistence classes to ivata masks.
44  *
45  * Revision 1.2 2004/11/03 16:10:13 colinmacleod
46  * Changed todo comments to TODO: all caps.
47  *
48  * Revision 1.1 2004/09/30 15:16:04 colinmacleod
49  * Split off addressbook elements into security subproject.
50  *
51  * Revision 1.3 2004/07/13 19:41:17 colinmacleod
52  * Moved project to POJOs from EJBs.
53  * Applied PicoContainer to services layer (replacing session EJBs).
54  * Applied Hibernate to persistence layer (replacing entity EJBs).
55  *
56  * Revision 1.2 2004/03/21 21:16:19 colinmacleod
57  * Shortened name to ivata op.
58  *
59  * Revision 1.1.1.1 2004/01/27 20:58:00 colinmacleod
60  * Moved ivata openportal to SourceForge..
61  *
62  * Revision 1.2 2003/10/17 12:36:13 jano
63  * fixing problems with building
64  * converting intranet -> portal
65  * Eclipse building
66  *
67  * Revision 1.1.1.1 2003/10/13 20:50:15 colin
68  * Restructured portal into subprojects
69  *
70  * Revision 1.19 2003/06/02 06:03:31 peter
71  * userName check commented out
72  *
73  * Revision 1.18 2003/02/25 16:57:20 peter
74  * fixed bugs: mistyped variable names
75  *
76  * Revision 1.17 2003/02/24 19:27:31 colin
77  * restructured file paths
78  *
79  * Revision 1.16 2003/02/21 16:22:05 peter
80  * serializable now
81  *
82  * Revision 1.15 2003/02/20 16:21:19 peter
83  * added input format for date/time
84  *
85  * Revision 1.14 2003/02/20 14:25:28 peter
86  * 24H time formats removed
87  *
88  * Revision 1.13 2003/02/20 07:47:41 colin
89  * changed name of setting from timeZone to i18nTimeZone
90  *
91  * Revision 1.12 2003/02/04 17:43:52 colin
92  * copyright notice
93  *
94  * Revision 1.10 2003/01/30 16:40:39 peter
95  * time zone awareness added
96  *
97  * Revision 1.9 2003/01/15 10:58:44 jano
98  * fixing bug with language
99  *
100  * Revision 1.8 2002/12/18 13:14:26 peter
101  * the locale information read from db, moved to
102  * SimpleDateFormat's locale aware constructor
103  *
104  * Revision 1.6 2002/09/23 11:47:32 colin
105  * Split date formatter constants off into separate file.
106  *
107  * Revision 1.5 2002/08/29 16:40:42 colin
108  * improved error handling of missing settings
109  *
110  * Revision 1.4 2002/07/30 14:12:27 jano
111  * set lenient to FALSE of format when is DateFormater created
112  *
113  * Revision 1.3 2002/07/15 14:59:32 jano
114  * added format time for 24H
115  *
116  * Revision 1.2 2002/07/10 13:16:43 colin
117  * bug fixes
118  * completed implementation of SettingDateFormatter
119  * -----------------------------------------------------------------------------
120  */

121 package com.ivata.groupware.util;
122
123 import java.io.Serializable JavaDoc;
124 import java.text.MessageFormat JavaDoc;
125 import java.text.ParseException JavaDoc;
126 import java.text.SimpleDateFormat JavaDoc;
127 import java.util.Date JavaDoc;
128 import java.util.GregorianCalendar JavaDoc;
129 import java.util.Locale JavaDoc;
130 import java.util.TimeZone JavaDoc;
131
132 import org.apache.log4j.Logger;
133
134 import com.ivata.groupware.admin.security.server.SecuritySession;
135 import com.ivata.groupware.admin.setting.Settings;
136 import com.ivata.groupware.admin.setting.SettingsInitializationException;
137 import com.ivata.mask.util.SystemException;
138 import com.ivata.mask.web.format.DateFormatter;
139 import com.ivata.mask.web.format.DateFormatterConstants;
140 import com.ivata.mask.web.format.DateFormatterException;
141
142
143 /**
144  * <p>Handles conversion of dates to/from strings in a unified way
145  * throughout the intranet system.</p>
146  *
147  * @since 2002-06-22
148  * @author Colin MacLeod
149  * <a HREF='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
150  * @version $Revision: 1.2.2.1 $
151  * TODO: the <code>DATE_FORMAT_RELATIVE</code> handling could be
152  * extended to
153  * include future dates
154  */

155 public class SettingDateFormatter implements Serializable JavaDoc, DateFormatter {
156     /**
157      * Refer to {@link Logger}.
158      */

159     private static Logger log = Logger.getLogger(SettingDateFormatter.class);
160     /**
161      * <p>Set this to one of the
162      * <code>DateFormatterConstants.DATE_FORMAT_.</code> constants to use
163      * that date format.</p>
164      */

165     private int dateFormat = DateFormatterConstants.DATE_LONG;
166     /**
167      * <p>This is the pattern string which is passed to the
168      * <code>SimpleDateFormat</code> which is used internally. Used to
169      * display error texts.</p>
170      */

171     String JavaDoc dateFormatString = null;
172     /**
173      * <p>Stores how the date and time are used in the output. Change this
174      * text to
175      * restrict the output to just date or just time, or to change the
176      * text between
177      * them.</p>
178      *
179      * <p>The format used is the same as the format for
180      * <code>java.text.MessageFormat</code> and the string
181      * <code>{0}</code> will be
182      * replaced with the date format chosen, <code>{1}</code> is replaced
183      * with the
184      * time format chosen.</p>
185      */

186     private String JavaDoc dateTimeText = "{0}, ''at'' {1}";
187     /**
188      * <p>This member is used to do the actual date conversions.</p>
189      */

190     private SimpleDateFormat JavaDoc format;
191     /**
192      * <p>Used to form the string which connects the date format with the
193      * time
194      * format.</p>
195      */

196     MessageFormat JavaDoc messageFormat;
197     /**
198      * <p>This is the pattern string which is passed to the
199      * <code>SimpleDateFormat</code> which is used internally. Used to
200      * display error texts.</p>
201      */

202     String JavaDoc pattern = null;
203
204     /**
205      * <p>
206      * Each date formatter can only apply to one security session. This is used
207      * to retrieve settings for the current user.
208      * </p>
209      */

210     SecuritySession securitySession;
211     /**
212      * <p>Used to access the date formats from the system settings.</p>
213      */

214     private Settings settings;
215     /**
216      * <p>Set this to one of the
217      * <code>DateFormatterConstants.TIME_FORMAT_.</code> to use that time
218      * format.</p>
219      */

220     private int timeFormat = DateFormatterConstants.TIME_SHORT;
221     /**
222      * <p>This is the pattern string which is passed to the
223      * <code>SimpleDateFormat</code> which is used internally. Used to
224      * display error texts.</p>
225      */

226     String JavaDoc timeFormatString = null;
227     /**
228      * <p>holds the time zone used in this formatter to return dates
229      * specific to user;s geographic location</p>
230      */

231     private TimeZone JavaDoc timeZone;
232
233     /**
234      * <p>Date format settings (as with all other settings in
235      * ivata groupware) can be
236      * made specific to each user. This user name identifies the user
237      * whose
238      * individual preferences will be applied </p>
239      *
240      * <p>Leave this setting <code>null</code> (the default) to use the
241      * standard,
242      * system-wide settings.</p>
243      */

244     private String JavaDoc userName = null;
245
246     /**
247      * Construct a date formatter.
248      *
249      * @param securitySession used to retrieve settings for the current user.
250      * @param settings used to access the date formats from the system settings.
251      */

252     public SettingDateFormatter(SecuritySession securitySession,
253             Settings settings) {
254         this.securitySession = securitySession;
255         this.settings = settings;
256     }
257
258     /**
259      * <p>Used by the class internally to initialize the
260      * <code>SimpleDateFormat</code> instance used when the format
261      * changes.</p>
262      *
263      * @param date for relative date formats, the returned string is
264      * dependent upon
265      * the date being formatted. In these cases, this date is used to
266      * create a
267      * relative format.
268      * @throws SettingsInitializationException if the settings for this
269      * formatter
270      * have not yet been set.
271      * @throws DateFormatterException if the settings for this date format
272      *
273      * are not set, or not set correctly
274      */

275     private void createFormat(Date JavaDoc date) throws SettingsInitializationException, DateFormatterException {
276         if (securitySession == null) {
277             String JavaDoc message = "createFormat - securitySession is null";
278             log.error(message);
279             throw new NullPointerException JavaDoc(message);
280         }
281         // prerequisites: check that the settings are not null
282
if (settings == null) {
283             throw new SettingsInitializationException("ERROR in SettingDateFormatter: null settings: you must first call setSettings.");
284         }
285         // prerequisites: check that the userName is not null
286
// TODO: This could be a warning or a new exception, as there are cases when setting userName to null is OK
287
// if (userName == null) {
288
// throw new SettingsInitializationException("ERROR in SettingDateFormatter: null userName: you must first call setUserName.");
289
// }
290
try {
291             if (messageFormat == null) {
292                 messageFormat = new MessageFormat JavaDoc(dateTimeText);
293             }
294             // now work out the format to use
295
// if the date is relative, there is nothing we can do here without a
296
// date object
297
if (((dateFormat == DateFormatterConstants.DATE_RELATIVE) ||
298                     (dateFormat == DateFormatterConstants.DATE_SHORT_RELATIVE)) &&
299                 (date == null)) {
300                 format = null;
301                 return;
302             }
303             // other date formats are constant
304
String JavaDoc formatString="", dateFormatSetting="", timeFormatSetting="";
305
306             switch (dateFormat) {
307                 case DateFormatterConstants.DATE_LONG:
308                     dateFormatSetting = "i18nDateLong";
309                     break;
310
311                 case DateFormatterConstants.DATE_LONG_YEAR:
312                     dateFormatSetting = "i18nDateLongYear";
313                     break;
314
315                 case DateFormatterConstants.DATE_LONG_DAY:
316                     dateFormatSetting = "i18nDateLongDay";
317                     break;
318
319                 case DateFormatterConstants.DATE_SHORT:
320                     dateFormatSetting = "i18nDateShort";
321                     break;
322
323                 case DateFormatterConstants.DATE_SHORT_YEAR:
324                     dateFormatSetting = "i18nDateShortYear";
325                     break;
326
327                 case DateFormatterConstants.DATE_INPUT:
328                     dateFormatSetting = "i18nDateInput";
329                     break;
330
331                 case DateFormatterConstants.DATE_INPUT_DISPLAY:
332                     dateFormatSetting = "i18nDateInputDisplay";
333                     break;
334
335                 case DateFormatterConstants.DATE_SHORT_RELATIVE:
336                 case DateFormatterConstants.DATE_RELATIVE:
337                     GregorianCalendar JavaDoc now = new GregorianCalendar JavaDoc();
338
339                     now.setTime(new Date JavaDoc());
340                     GregorianCalendar JavaDoc yesterday = new GregorianCalendar JavaDoc();
341
342                     yesterday.setTime(new Date JavaDoc());
343                     yesterday.roll(GregorianCalendar.DATE, false);
344                     GregorianCalendar JavaDoc lastWeek = new GregorianCalendar JavaDoc();
345
346                     lastWeek.setTime(new Date JavaDoc());
347                     lastWeek.roll(GregorianCalendar.WEEK_OF_YEAR, false);
348                     GregorianCalendar JavaDoc compare = new GregorianCalendar JavaDoc();
349
350                     compare.setTime(date);
351                     // is it today?
352
if ((now.get(GregorianCalendar.YEAR) == compare.get(GregorianCalendar.YEAR)) &&
353                         (now.get(GregorianCalendar.DAY_OF_YEAR) == compare.get(GregorianCalendar.DAY_OF_YEAR))) {
354                         if (dateFormat == DateFormatterConstants.DATE_SHORT_RELATIVE) {
355                             dateFormatSetting = "i18nDateShortToday";
356                         } else {
357                             // it is today: now we need to compare the time
358
int hour = compare.get(GregorianCalendar.HOUR_OF_DAY);
359
360                             if (hour < 12) {
361                                 dateFormatSetting = "i18nDateThisMorning";
362                             } else if (hour < 18) {
363                                 dateFormatSetting = "i18nDateThisAfternoon";
364                             } else {
365                                 dateFormatSetting = "i18nDateThisEvening";
366                             }
367                         }
368                     } else if ((now.get(GregorianCalendar.YEAR) == compare.get(GregorianCalendar.YEAR)) &&
369                         (yesterday.get(GregorianCalendar.DAY_OF_YEAR) == compare.get(GregorianCalendar.DAY_OF_YEAR))) {
370                         if (dateFormat == DateFormatterConstants.DATE_SHORT_RELATIVE) {
371                             dateFormatSetting = "i18nDateShortYesterday";
372                         } else {
373                             // it is yesterday: now we need to compare the time
374
int hour = compare.get(GregorianCalendar.HOUR_OF_DAY);
375
376                             if (hour < 12) {
377                                 dateFormatSetting = "i18nDateYesterdayMorning";
378                             } else if (hour < 18) {
379                                 dateFormatSetting = "i18nDateYesterdayAfternoon";
380                             } else {
381                                 dateFormatSetting = "i18nDateYesterdayEvening";
382                             }
383                         }
384                     } else if ((now.get(GregorianCalendar.YEAR) == compare.get(GregorianCalendar.YEAR)) &&
385                         (now.get(GregorianCalendar.WEEK_OF_YEAR) == compare.get(GregorianCalendar.WEEK_OF_YEAR))) {
386                         // so it this week
387
dateFormatSetting = "i18nDateWeekDay";
388                     } else if (now.get(GregorianCalendar.YEAR) == compare.get(GregorianCalendar.YEAR)) {
389                         // it is this year
390
if (dateFormat == DateFormatterConstants.DATE_SHORT_RELATIVE) {
391                             dateFormatSetting = "i18nDateShort";
392                         } else {
393                             dateFormatSetting = "i18nDateLong";
394                         }
395                     } else {
396                         // everything else is long year format
397
if (dateFormat == DateFormatterConstants.DATE_SHORT_RELATIVE) {
398                             dateFormatSetting = "i18nDateShortYear";
399                         } else {
400                             dateFormatSetting = "i18nDateLongYear";
401                         }
402                     }
403                     break;
404             }
405             dateFormatString = settings.getStringSetting(securitySession, dateFormatSetting,
406                 securitySession.getUser());
407
408             // times are simpler
409
switch (timeFormat) {
410                 case DateFormatterConstants.TIME_LONG:
411                     timeFormatSetting = "i18nTimeLong";
412                     break;
413
414                 case DateFormatterConstants.TIME_SHORT:
415                     timeFormatSetting = "i18nTimeShort";
416                     break;
417
418                 case DateFormatterConstants.TIME_INPUT:
419                     timeFormatSetting = "i18nTimeInput";
420                     break;
421
422                 case DateFormatterConstants.TIME_INPUT_DISPLAY:
423                     timeFormatSetting = "i18nTimeInputDisplay";
424                     break;
425
426             }
427             timeFormatString = settings.getStringSetting(securitySession,
428                 timeFormatSetting, securitySession.getUser());
429
430             // now just format the dateTimeText and use the result to create the
431
// simple date format
432
Object JavaDoc arguments[] = {
433                     dateFormatString,
434                     timeFormatString
435                 };
436             Locale JavaDoc locale =
437                 new Locale JavaDoc(settings.getStringSetting(securitySession,
438                     "i18nLocaleLanguage", securitySession.getUser()),
439                         settings.getStringSetting(securitySession,
440                             "i18nLocaleCountry", securitySession.getUser()));
441
442             pattern = MessageFormat.format(dateTimeText, arguments);
443             format = new SimpleDateFormat JavaDoc(pattern, locale);
444             format.setLenient(false);
445             format.setTimeZone(getTimeZone());
446         } catch (com.ivata.mask.util.SystemException e) {
447             throw new DateFormatterException("Error in SettingDateFormatter: RemoteException " + e.getMessage());
448         }
449     }
450
451     /**
452      * <p>Format the date provided as a string, using the date format from
453      * the settings.</p>
454      *
455      * @param date the date to convert into a string.
456      * @return date string, converted to a string, using the requested
457      * format.
458      * @throws SettingsInitializationException if the settings for this
459      * formatter
460      * have not yet been set.
461      * @throws DateFormatterException if there is a problem creating the
462      * string
463      * because of an incorrect format pattern, for example.
464      */

465     public String JavaDoc format(final Date JavaDoc date) throws DateFormatterException {
466         if ((format == null) ||
467             (dateFormat == DateFormatterConstants.DATE_RELATIVE) ||
468             (dateFormat == DateFormatterConstants.DATE_SHORT_RELATIVE)) {
469             try {
470                 createFormat(date);
471             } catch (SettingsInitializationException e1) {
472                 throw new DateFormatterException(e1);
473             }
474         }
475         String JavaDoc returnString = "";
476
477         try {
478             returnString = format.format(date);
479         } catch (Exception JavaDoc e) {
480             throw new DateFormatterException("ERROR in SettingDateFormatter: format threw "
481                     + e.getClass()
482                     + " formatting '"
483                     + date
484                     + "', using date format '"
485                     + dateFormatString
486                     + "', time format '"
487                     + timeFormatString
488                     + "': "
489                     + e.getMessage());
490         }
491         return returnString;
492     }
493
494     /**
495      * <p>Get the number of the date format used in this object. This
496      * should
497      * correspond to one of the <code>DATE_FORMAT_...</code>
498      * constants.</p>
499      *
500      * @return the current value of the date format used.
501      */

502     public int getDateFormat() {
503         return dateFormat;
504     }
505
506     /**
507      * <p>Get how the date and time are used in the output.</p>
508      *
509      * <p>The format used is the same as the format for
510      * <code>java.text.MessageFormat</code> and the string
511      * <code>{0}</code> will be
512      * replaced with the date format chosen, <code>{1}</code> is replaced
513      * with the
514      * time format chosen.</p>
515      *
516      * @return the current text used to combine date and time formats.
517      */

518     public String JavaDoc getDateTimeText() {
519         return dateTimeText;
520     }
521
522     /**
523      * <p>Get the number of the time format used in this object. This
524      * should
525      * correspond to one of the <code>TIME_FORMAT_...</code>
526      * constants.</p>
527      *
528      * @return the current value of the time format used.
529      */

530     public int getTimeFormat() {
531         return timeFormat;
532     }
533
534     /**
535      * <p>returns the private variable timeZone, when not set yet,
536      * fetches it from settings first</p>
537      *
538      * @return the timeZone
539      * @exception DateFormatterException if there is a remote exception
540      * accessing the settings, or the settings is of an unexpected data
541      * type.
542      */

543     private TimeZone JavaDoc getTimeZone() throws DateFormatterException {
544         assert (securitySession != null);
545         if (this.timeZone == null) {
546             try {
547                 String JavaDoc timeZoneID = settings.getStringSetting(securitySession,
548                     "i18nTimeZone", securitySession.getUser());
549
550                 timeZone = TimeZone.getTimeZone(timeZoneID);
551             } catch(SystemException e) {
552                 throw new DateFormatterException("Error in SettingDateFormatter getting the timeZone: RemoteException " + e.getMessage());
553             }
554         }
555         return timeZone;
556     }
557
558     /**
559      * <p>Get the user name used for date/time system settings.</p>
560      *
561      * <p>Date format settings (as with all other settings in
562      * ivata groupware) can be
563      * made specific to each user. This user name identifies the user
564      * whose
565      * indifvidual preferences will be applied </p>
566      *
567      * @return the current value of the user name used for settings.
568      */

569     public String JavaDoc getUserName() {
570         return userName;
571     }
572
573     /**
574      * <p>Parse the given string to a date, using the current date
575      * format.</p>
576      *
577      * @param formatString the string to convert into a date.
578      * @return date parsed from the string provided.
579      * @throws SettingsInitializationException if the settings for this
580      * formatter
581      * have not yet been set.
582      * @throws ParseException if the string provided does not match the
583      * date/time
584      * format
585      * @throws DateFormatterException if the settings for this date format
586      *
587      * are not set, or not set correctly
588      */

589     public Date JavaDoc parse(final String JavaDoc formatString) throws ParseException JavaDoc,
590                 DateFormatterException {
591         if ((dateFormat == DateFormatterConstants.DATE_RELATIVE) ||
592             (dateFormat == DateFormatterConstants.DATE_SHORT_RELATIVE)) {
593             // TODO: go through all of the possible date formats and try to parse
594
// each one
595
return null;
596         }
597         if (format == null) {
598             try {
599                 createFormat(null);
600             } catch (SettingsInitializationException e1) {
601                 throw new DateFormatterException(e1);
602             }
603         }
604         return format.parse(formatString);
605     }
606
607     /**
608      * <p>Set the number of the date format used in this object. This
609      * should
610      * correspond to one of the <code>DATE_FORMAT_...</code>
611      * constants.</p>
612      *
613      * @param dateFormat the new value of the date format used.
614      * @throws DateFormatterException if the settings for this date format
615      * are not set, or not set correctly
616      */

617     public void setDateFormat(final int dateFormat)
618             throws DateFormatterException {
619         this.dateFormat = dateFormat;
620         try {
621             // date format has changed, create the format
622
createFormat(null);
623         } catch (SettingsInitializationException e) {
624             throw new DateFormatterException(e);
625         }
626     }
627
628     /**
629      * <p>Set this text to restrict the output to just date or just time,
630      * or to
631      * change the text between
632      * them.</p>
633      *
634      * <p>The format used is the same as the format for
635      * <code>java.text.MessageFormat</code> and the string
636      * <code>{0}</code> will be
637      * replaced with the date format chosen, <code>{1}</code> is replaced
638      * with the
639      * time format chosen.</p>
640      *
641      * @param dateTimeText the new value of the text used to combine date
642      * and time
643      * formats.
644      * @throws DateFormatterException if the settings for this date format
645      * are not set, or not set correctly
646      */

647     public void setDateTimeText(final String JavaDoc dateTimeText)
648             throws DateFormatterException {
649         this.dateTimeText = dateTimeText;
650         // this affects the message format: force a new one
651
messageFormat = null;
652         try {
653             createFormat(null);
654         } catch (SettingsInitializationException e) {
655             throw new DateFormatterException(e);
656         }
657     }
658     /**
659      * This is needed by the mail implementation, which does not have a security
660      * session at creation time.
661      * @param securitySessionParam The securitySession to set.
662      */

663     public void setSecuritySession(SecuritySession securitySessionParam) {
664         if (log.isDebugEnabled()) {
665             log.debug(toString() + " setSecuritySession before: '"
666                     + securitySession + "', after: '" + securitySessionParam
667                     + "'");
668         }
669
670         securitySession = securitySessionParam;
671     }
672
673     /**
674      * <p>Set the number of the time format used in this object. This
675      * should
676      * correspond to one of the <code>TIME_FORMAT_...</code>
677      * constants.</p>
678      *
679      * @param timeFormat the new value of the time format used.
680      * @throws SettingsInitializationException if the settings for this
681      * formatter
682      * have not yet been set.
683      * @throws DateFormatterException if the settings for this date format
684      *
685      * are not set, or not set correctly
686      */

687     public void setTimeFormat(final int timeFormat) throws DateFormatterException {
688         this.timeFormat = timeFormat;
689         try {
690             // time format has changed, create the format
691
createFormat(null);
692         } catch (SettingsInitializationException e) {
693             throw new DateFormatterException(e);
694         }
695     }
696
697     /**
698      * <p>Set the user name used for date/time system settings.</p>
699      *
700      * <p>Date format settings (as with all other settings in
701      * ivata groupware) can be
702      * made specific to each user. This user name identifies the user
703      * whose
704      * individual preferences will be applied </p>
705      *
706      * <p>Leave this setting <code>null</code> (the default) to use the
707      * standard,
708      * system-wide settings.</p>
709      *
710      * @param userName the new value of the user name used for system
711      * settings.
712      * @throws SettingsInitializationException if the settings for this
713      * formatter
714      * have not yet been set.
715      * @throws DateFormatterException if the settings for this date format
716      *
717      * are not set, or not set correctly
718      */

719     public void setUserName(String JavaDoc userName) throws SettingsInitializationException, DateFormatterException {
720         this.userName = userName;
721         // user has changed, create the format
722
createFormat(null);
723     }
724 }
725
Popular Tags