001: package com.sun.portal.app.sharedtasks.util;
002:
003: import java.util.Calendar;
004: import java.util.ResourceBundle;
005: import java.util.TimeZone;
006: import java.util.logging.Logger;
007:
008: import com.sun.comclient.calendar.DateTime;
009: import com.sun.comclient.calendar.Duration;
010: import com.sun.portal.log.common.PortalLogger;
011:
012: /**
013: * Constants file.
014: *
015: * @author ashwin.mathew@sun.com
016: */
017: public class SharedConstants {
018:
019: public static final String TASKS_RESOURCE_BUNDLE = "com.sun.portal.app.sharedtasks.bundle.sharedtasks";
020:
021: // Resource bundle keys
022:
023: public static final String KEY_NO_DUE_DATE = "tasklist_table_no_due_date";
024:
025: public static final String KEY_VIEW_DAY = "tasklist_table_view_day";
026: public static final String KEY_VIEW_WEEK = "tasklist_table_view_week";
027: public static final String KEY_VIEW_MONTH = "tasklist_table_view_month";
028:
029: public static final String KEY_DAY_FORMAT = "tasklist_table_day_format";
030: public static final String KEY_WEEK_FORMAT = "tasklist_table_week_format";
031: public static final String KEY_MONTH_FORMAT = "tasklist_table_month_format";
032:
033: public static final String KEY_PAGETITLE_NEW_TASK = "task_pagetitle_newtask";
034: public static final String KEY_PAGETITLE_EDIT_TASK = "task_pagetitle_edittask";
035:
036: public static final String KEY_PRIORITY_NONE = "task_priority_none";
037: public static final String KEY_PRIORITY_LOW = "task_priority_low";
038: public static final String KEY_PRIORITY_NORMAL = "task_priority_normal";
039: public static final String KEY_PRIORITY_HIGH = "task_priority_high";
040:
041: public static final String KEY_STATUS_0 = "task_status_0";
042: public static final String KEY_STATUS_25 = "task_status_25";
043: public static final String KEY_STATUS_50 = "task_status_50";
044: public static final String KEY_STATUS_75 = "task_status_75";
045: public static final String KEY_STATUS_100 = "task_status_100";
046:
047: public static final String KEY_SAVE_FAILED = "task_save_failed";
048: public static final String KEY_DELETE_FAILED = "task_delete_failed";
049: public static final String KEY_RETRIEVE_FAILED = "task_retrieve_failed";
050:
051: public static final String KEY_OP_FAILED_DETAIL = "error_operation_failed_detail";
052:
053: public static final String KEY_FILTER_ALL_TASKS = "tasklist_table_filter_alltasks";
054: public static final String KEY_FILTER_COMPLETED_TASKS = "tasklist_table_filter_completedtasks";
055: public static final String KEY_FILTER_INCOMPLETE_TASKS = "tasklist_table_filter_incompletetasks";
056:
057: public static final String KEY_ACTION_DAYVIEW = "tasklist_table_action_dayview";
058: public static final String KEY_ACTION_WEEKVIEW = "tasklist_table_action_weekview";
059: public static final String KEY_ACTION_MONTHVIEW = "tasklist_table_action_monthview";
060:
061: /**
062: * Separator to use when storing task id and rid on a single field.
063: */
064: public static final String ID_RID_SEPARATOR = ";";
065:
066: /**
067: * Session attribute in which the task list data provider is stored.
068: */
069: public static final String SESSION_PARAM_TASK_LIST_DATA = "taskListData";
070:
071: public static final String URL_TASK_PORTLET_ACTION = "taskPortletUrl";
072:
073: public static final String URL_COMM_SEARCH_TASKS = "commSearchTasks";
074:
075: public static final String URL_VISIBLE_FOR_MENUCONTAINER = "ps.visibleurl";
076:
077: /**
078: * Request parameter for task id when navigating from list view.
079: */
080: public static final String REQ_PARAM_TASKID = "taskId";
081:
082: /**
083: * Request parameter for task rid when navigating from list view.
084: */
085: public static final String REQ_PARAM_TASKRID = "taskRid";
086:
087: /**
088: * View tasks for a single day.
089: */
090: public static final String VIEW_CTX_DAY = "VIEW_CTX_DAY";
091:
092: /**
093: * View tasks for a week.
094: */
095: public static final String VIEW_CTX_WEEK = "VIEW_CTX_WEEK";
096:
097: /**
098: * View tasks for a month.
099: */
100: public static final String VIEW_CTX_MONTH = "VIEW_CTX_MONTH";
101:
102: /**
103: * No filtering, all tasks are displayed.
104: */
105: public static final String FILTER_ALL_TASKS = "FILTER_ALL_TASKS";
106:
107: /**
108: * All incomplete tasks are shown.
109: */
110: public static final String FILTER_INCOMPLETE_TASKS = "FILTER_INCOMPLETE_TASKS";
111:
112: /**
113: * All completed tasks are shown.
114: */
115: public static final String FILTER_COMPLETED_TASKS = "FILTER_COMPLETED_TASKS";
116:
117: // User Info attributes that should be specified in portlet.xml
118: // & userinfomapping files for PortletUser preferences.
119: public static final String USER_INFO_TIMEZONE = "timezone";
120:
121: public static final String DUMMY = "DUMMY";
122:
123: public static final String QQ = "??";
124: public static final String QQQQ = "????";
125: public static final String CQQ = ":??";
126: public static final String DATE_FORMAT_M_D_Y = "MM/DD/YYYY";
127: public static final String DATE_FORMAT_D_M_Y = "DD/MM/YYYY";
128: public static final String DATE_FORMAT_Y_M_D = "YYYY/MM/DD";
129:
130: public static final String DEFAULT_DATE_FORMAT = DATE_FORMAT_M_D_Y;
131: public static final String DEFAULT_DATE_DELIMITER = "/";
132: public static final String GMT_TIME_ZONE_STRING = "GMT";
133: public static final String TIME_FORMAT_12 = "12";
134: public static final String TIME_FORMAT_24 = "24";
135: public static final String DEFAULT_TIME_FORMAT = TIME_FORMAT_24;
136: public static final String EVENT_RECURRENCE_ONETIME = "onetime";
137: public static final String EVENT_RECURRENCE_HOURLY = "hourly";
138: public static final String EVENT_RECURRENCE_DAILY = "daily";
139: public static final String EVENT_RECURRENCE_WEEKLY = "weekly";
140: public static final String EVENT_RECURRENCE_MONTHLY = "monthly";
141: public static final String EVENT_RECURRENCE_MWF = "mwf";
142: public static final String EVENT_RECURRENCE_TT = "tt";
143: public static final String EVENT_RECURRENCE_SS = "ss";
144: public static final String EVENT_RECURRENCE_MTWTF = "mtwtf";
145: public static final int MINUTES_PRECISION = 5;
146: public static String SHOW_ALERT_TYPE_ERROR = "error";
147: public static String SHOW_ALERT_TYPE_INFO = "information";
148:
149: public static final String displayableMonthLabels[] = { "01", "02",
150: "03", "04", "05", "06", "07", "08", "09", "10", "11", "12" };
151:
152: public static final String displayableDayLabels[] = { "01", "02",
153: "03", "04", "05", "06", "07", "08", "09", "10", "11", "12",
154: "13", "14", "15", "16", "17", "18", "19", "20", "21", "22",
155: "23", "24", "25", "26", "27", "28", "29", "30", "31" };
156:
157: public static final String displayableYearLabels[] = { "2005",
158: "2006", "2007", "2008", "2009", "2009", "2010" };
159:
160: public static final String[] hoursIn12HourFormatNames = { "1", "2",
161: "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" };
162: public static final String[] hoursIn12HourFormatValues = { "1",
163: "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "0" };
164:
165: public static final String[] hoursIn24HourFormatNames = { "00",
166: "01", "02", "03", "04", "05", "06", "07", "08", "09", "10",
167: "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
168: "21", "22", "23" };
169: public static final String[] hoursIn24HourFormatValues = { "0",
170: "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11",
171: "12", "13", "14", "15", "16", "17", "18", "19", "20", "21",
172: "22", "23" };
173:
174: public static final String[] minutesIn12HourFormatValues = { "00",
175: "05", "10", "15", "20", "25", "30", "35", "40", "45", "50",
176: "55", "720", "725", "730", "735", "740", "745", "750",
177: "755", "760", "765", "770", "775" };
178:
179: public static final String[] minutesIn24HourFormatNames = { "00",
180: "05", "10", "15", "20", "25", "30", "35", "40", "45", "50",
181: "55" };
182: public static final String[] minutesIn24HourFormatValues = { "0",
183: "5", "10", "15", "20", "25", "30", "35", "40", "45", "50",
184: "55" };
185:
186: private static Logger logger = PortalLogger
187: .getLogger(SharedConstants.class);
188:
189: public static String getDisplayableDateTime(DateTime startdt,
190: DateTime enddt, String usersDateFormatPref,
191: String usersDateDelimiterPref, String usersTimeFormatPref,
192: TimeZone tz, ResourceBundle rb) {
193: StringBuffer DDT = new StringBuffer(32);
194:
195: String isoDt = null;
196: DateTime tmpDt1 = null;
197: DateTime tmpDt2 = null;
198:
199: // Convert dates to the TZ passed
200: if (tz != null) {
201: isoDt = startdt.toISO8601();
202: try {
203: tmpDt1 = new DateTime(isoDt, tz);
204: } catch (Exception e1) {
205: tmpDt1 = null;
206: }
207:
208: if (tmpDt1 != null) {
209: startdt = tmpDt1;
210: }
211:
212: isoDt = enddt.toISO8601();
213: try {
214: tmpDt2 = new DateTime(isoDt, tz);
215: } catch (Exception e1) {
216: tmpDt2 = null;
217: }
218:
219: if (tmpDt2 != null) {
220: enddt = tmpDt2;
221: }
222:
223: }
224:
225: DDT.append(getDisplayableDate(startdt, usersDateFormatPref,
226: usersDateDelimiterPref));
227: DDT.append(" ");
228: DDT.append(getDisplayableTime(startdt, usersTimeFormatPref));
229: DDT.append(" ");
230:
231: Duration dur = null;
232: try {
233: dur = new Duration(startdt, enddt);
234: } catch (Exception e) {
235: logger
236: .warning("Couldn't find duration: Not puuting duration value in Displayble Date Time string. Reason: "
237: + e);
238: }
239:
240: if (null != dur) {
241: DDT.append("(");
242: DDT.append(dur.getHours());
243: if (dur.getMinutes() > 5) {
244: DDT.append(".");
245: DDT.append(dur.getMinutes() / 6);
246: }
247: DDT.append(" ");
248:
249: String hoursString = null;
250: if (null == hoursString) {
251: hoursString = rb.getString("task_hoursText");
252: }
253: DDT.append(hoursString);
254: DDT.append(")");
255: }
256:
257: return DDT.toString();
258: }
259:
260: /**
261: * Gets Displayble Date such as mm/dd/yy or dd/mm/yy or 07/30/2002
262: * <p>
263: * This displayable date form will be used in events display (tiled view)
264: * in invitations view, events management/search views.
265: * <p>
266: */
267: public static String getDisplayableDate(DateTime dt,
268: String usersDateFormatPref, String usersDateDelimiterPref) {
269: if (null == dt) {
270: return null;
271: }
272:
273: int m = dt.get(Calendar.MONTH);
274: int d = dt.get(Calendar.DAY_OF_MONTH) - 1;
275:
276: String monthLabel = SharedConstants.displayableMonthLabels[m];
277: if (monthLabel == null) {
278: monthLabel = SharedConstants.QQ;
279: }
280: String dayLabel = SharedConstants.displayableDayLabels[d];
281: if (dayLabel == null) {
282: dayLabel = SharedConstants.QQ;
283: }
284:
285: String yearLabel = getYearLabel(dt);
286: if (yearLabel == null) {
287: yearLabel = SharedConstants.QQQQ;
288: }
289:
290: if (null == usersDateFormatPref) {
291: usersDateFormatPref = SharedConstants.DEFAULT_DATE_FORMAT;
292: }
293:
294: if (null == usersDateDelimiterPref) {
295: usersDateDelimiterPref = SharedConstants.DEFAULT_DATE_DELIMITER;
296: }
297: StringBuffer DD = new StringBuffer(16);
298:
299: if (SharedConstants.DATE_FORMAT_D_M_Y
300: .equalsIgnoreCase(usersDateFormatPref)) {
301: DD.append(dayLabel);
302: DD.append(usersDateDelimiterPref);
303: DD.append(monthLabel);
304: DD.append(usersDateDelimiterPref);
305: DD.append(yearLabel);
306: } else if (SharedConstants.DATE_FORMAT_Y_M_D
307: .equalsIgnoreCase(usersDateFormatPref)) {
308: DD.append(yearLabel);
309: DD.append(usersDateDelimiterPref);
310: DD.append(monthLabel);
311: DD.append(usersDateDelimiterPref);
312: DD.append(dayLabel);
313: } else {
314: DD.append(monthLabel);
315: DD.append(usersDateDelimiterPref);
316: DD.append(dayLabel);
317: DD.append(usersDateDelimiterPref);
318: DD.append(yearLabel);
319: }
320:
321: return DD.toString();
322: }
323:
324: /**
325: * Returns displayble time string as in 12 hour format or 24 hour format,
326: * for example it returns displayble time such as 16:45 or 4:45pm.
327: * If this method fails to retrieve hours or minutes component or both
328: * then it will returns "??" value; for example in such case it may return
329: * displayble time such as ??:?? or ??:45 or ??:45pm or 16:?? or 4:??.
330: * Default user's TimeFormat preference is '12' hour format in case if
331: * 'usersTimeFormatPref' value passed is null.
332: * <p>
333: */
334: public static String getDisplayableTime(DateTime dt,
335: String usersTimeFormatPref) {
336: String timehours = getHoursValue(dt, usersTimeFormatPref);
337: String timeminutes = getMinutesValue(dt, usersTimeFormatPref);
338:
339: timehours = ((null == timehours) ? SharedConstants.QQ
340: : timehours);
341: timeminutes = ((null == timeminutes) ? SharedConstants.CQQ
342: : timeminutes);
343:
344: return (timehours + ":" + timeminutes);
345: }
346:
347: /**
348: * Returns displayable hours string as in 12 hour format or 24 hour format.
349: * Default user's TimeFormat preference is '12' hour format in case if
350: * 'usersTimeFormatPref' value passed is null.
351: * <p>
352: * This method will return the appropriate indexed hours displayable
353: * string usable by tiled logic's of events and todos, either from
354: * 24'-hours-names-list or from 12'-hours-names-list based on
355: * user's time format preference.
356: * <p>
357: */
358: public static String getDisplayableHours(DateTime dt,
359: String usersTimeFormatPref) {
360: if (null == dt) {
361: return null;
362: }
363:
364: int h = dt.get(Calendar.HOUR_OF_DAY);
365:
366: if (SharedConstants.TIME_FORMAT_24.equals(usersTimeFormatPref)) {
367: // Keep hours as same in 24 hour format
368: //
369: } else {
370: // Hours conversion: 0 -> 12 am, 12 -> 12 pm,
371: //1 to 11 --> 1 to 11 am, 13 to 23 --> 1 to 11 pm
372: //
373: h = (h + 12 - 1) % 12;
374:
375: }
376:
377: return Integer.toString(h);
378: }
379:
380: /**
381: * Returns displayable minutes string as in 12 hour format or 24
382: * hour format.
383: * Default user's TimeFormat preference is '12' hour format in case if
384: * 'usersTimeFormatPref' value passed is null.
385: * <p>
386: */
387: public static String getDisplayableMinutes(DateTime dt,
388: String usersTimeFormatPref) {
389: if (null == dt) {
390: return null;
391: }
392:
393: int h = dt.get(Calendar.HOUR_OF_DAY);
394: int m = dt.get(Calendar.MINUTE)
395: / SharedConstants.MINUTES_PRECISION;
396:
397: // Default user's TimeFormat is '12' hour format
398: //
399: if (SharedConstants.TIME_FORMAT_24.equals(usersTimeFormatPref)) {
400: // Keep minutes as same in 24 hour format
401: //
402:
403: } else {
404: // Convert to 12 hour format
405: //
406: m = ((h > 11) ? (m + 12) : m);
407:
408: }
409:
410: return Integer.toString(m);
411:
412: }
413:
414: public static String getYearLabel(DateTime dt) {
415: if (null != dt) {
416: int y = dt.get(Calendar.YEAR) - 2005;
417: if ((y >= 0) && (y <= 5)) {
418: return SharedConstants.displayableYearLabels[y];
419:
420: } else {
421: return Integer.toString(dt.get(Calendar.YEAR));
422: }
423: }
424: return null;
425: }
426:
427: /**
428: * Returns hours value as in 12 hour format or 24 hour format.
429: * Default user's TimeFormat preference is '12' hour format in case if
430: * 'usersTimeFormatPref' value passed is null.
431: * <p>
432: */
433: public static String getHoursValue(DateTime dt,
434: String usersTimeFormatPref) {
435: if (null == dt) {
436: return null;
437: }
438:
439: int h = dt.get(Calendar.HOUR_OF_DAY);
440:
441: if (SharedConstants.TIME_FORMAT_24.equals(usersTimeFormatPref)) {
442: // Keep hours as same in 24 hour format
443: //
444: return SharedConstants.hoursIn24HourFormatValues[h];
445:
446: } else {
447: // Hours conversion: 0 -> 12 am, 12 -> 12 pm,
448: //1 to 11 --> 1 to 11 am, 13 to 23 --> 1 to 11 pm
449: //
450: h = (h + 12 - 1) % 12;
451: return SharedConstants.hoursIn12HourFormatValues[h];
452:
453: }
454: }
455:
456: /**
457: * Returns minutes value as in 12 hour format or 24 hour format.
458: * Default user's TimeFormat preference is '12' hour format in case if
459: * 'usersTimeFormatPref' value passed is null.
460: * <p>
461: * This method will be useful for EventsModel, TasksModel,
462: * new/edit/update event or task views.
463: * <p>
464: * This method will return the appropriate indexed minutes value
465: * usable by EventsModel or TasksModel; either from 24'-minutes-values-list
466: * or from 12'-minutes-values-list based on user's time format preference.
467: * <p>
468: */
469: public static String getMinutesValue(DateTime dt,
470: String usersTimeFormatPref) {
471: if (null == dt) {
472: return null;
473: }
474:
475: int h = dt.get(Calendar.HOUR_OF_DAY);
476: int m = dt.get(Calendar.MINUTE)
477: / SharedConstants.MINUTES_PRECISION;
478:
479: // Default user's TimeFormat is '12' hour format
480: //
481: if (SharedConstants.TIME_FORMAT_24.equals(usersTimeFormatPref)) {
482: // Keep minutes as same in 24 hour format
483: //
484: return SharedConstants.minutesIn24HourFormatValues[m];
485: } else {
486: // Convert to 12 hour format
487: //
488: m = ((h > 11) ? (m + 12) : m);
489: return SharedConstants.minutesIn12HourFormatValues[m];
490: }
491: }
492: }
|