001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portlet.calendar.util;
022:
023: import com.liferay.portal.kernel.util.CalendarFactoryUtil;
024: import com.liferay.portal.kernel.util.GetterUtil;
025: import com.liferay.portal.kernel.util.StringMaker;
026: import com.liferay.portal.kernel.util.StringPool;
027: import com.liferay.portal.kernel.util.Validator;
028: import com.liferay.portal.util.ContentUtil;
029: import com.liferay.portal.util.PropsUtil;
030: import com.liferay.portlet.calendar.model.CalEvent;
031: import com.liferay.util.Time;
032:
033: import java.io.IOException;
034:
035: import java.util.Calendar;
036: import java.util.Date;
037: import java.util.Locale;
038: import java.util.TimeZone;
039:
040: import javax.portlet.PortletPreferences;
041:
042: /**
043: * <a href="CalUtil.java.html"><b><i>View Source</i></b></a>
044: *
045: * @author Brian Wing Shun Chan
046: *
047: */
048: public class CalUtil {
049:
050: public static String getEmailFromAddress(PortletPreferences prefs) {
051: String emailFromAddress = PropsUtil
052: .get(PropsUtil.CALENDAR_EMAIL_FROM_ADDRESS);
053:
054: return prefs.getValue("email-from-address", emailFromAddress);
055: }
056:
057: public static String getEmailFromName(PortletPreferences prefs) {
058: String emailFromName = PropsUtil
059: .get(PropsUtil.CALENDAR_EMAIL_FROM_NAME);
060:
061: return prefs.getValue("email-from-name", emailFromName);
062: }
063:
064: public static boolean getEmailEventReminderEnabled(
065: PortletPreferences prefs) {
066:
067: String emailEventReminderEnabled = prefs.getValue(
068: "email-event-reminder-enabled", StringPool.BLANK);
069:
070: if (Validator.isNotNull(emailEventReminderEnabled)) {
071: return GetterUtil.getBoolean(emailEventReminderEnabled);
072: } else {
073: return GetterUtil
074: .getBoolean(PropsUtil
075: .get(PropsUtil.CALENDAR_EMAIL_EVENT_REMINDER_ENABLED));
076: }
077: }
078:
079: public static String getEmailEventReminderBody(
080: PortletPreferences prefs) throws IOException {
081:
082: String emailEventReminderBody = prefs.getValue(
083: "email-event-reminder-body", StringPool.BLANK);
084:
085: if (Validator.isNotNull(emailEventReminderBody)) {
086: return emailEventReminderBody;
087: } else {
088: return ContentUtil.get(PropsUtil
089: .get(PropsUtil.CALENDAR_EMAIL_EVENT_REMINDER_BODY));
090: }
091: }
092:
093: public static String getEmailEventReminderSubject(
094: PortletPreferences prefs) throws IOException {
095:
096: String emailEventReminderSubject = prefs.getValue(
097: "email-event-reminder-subject", StringPool.BLANK);
098:
099: if (Validator.isNotNull(emailEventReminderSubject)) {
100: return emailEventReminderSubject;
101: } else {
102: return ContentUtil
103: .get(PropsUtil
104: .get(PropsUtil.CALENDAR_EMAIL_EVENT_REMINDER_SUBJECT));
105: }
106: }
107:
108: public static Date getEndTime(CalEvent event) {
109: long startTime = event.getStartDate().getTime();
110:
111: long endTime = startTime
112: + (Time.HOUR * event.getDurationHour())
113: + (Time.MINUTE * event.getDurationMinute());
114:
115: return new Date(endTime);
116: }
117:
118: public static boolean isAllDay(CalEvent event, TimeZone timeZone,
119: Locale locale) {
120:
121: Calendar cal = null;
122:
123: if (event.getTimeZoneSensitive()) {
124: cal = CalendarFactoryUtil.getCalendar(timeZone, locale);
125: } else {
126: cal = CalendarFactoryUtil.getCalendar();
127: }
128:
129: cal.setTime(event.getStartDate());
130:
131: int hour = cal.get(Calendar.HOUR_OF_DAY);
132: int minute = cal.get(Calendar.MINUTE);
133: int second = cal.get(Calendar.SECOND);
134: int millisecond = cal.get(Calendar.MILLISECOND);
135:
136: int dHour = event.getDurationHour();
137: int dMinute = event.getDurationMinute();
138:
139: if ((hour == 0) && (minute == 0) && (second == 0)
140: && (millisecond == 0) && (dHour == 24)
141: && (dMinute == 0)) {
142:
143: return true;
144: }
145:
146: return false;
147: }
148:
149: public static String toString(Calendar cal) {
150: StringMaker sm = new StringMaker();
151:
152: sm.append(cal.get(Calendar.YEAR));
153: sm.append(StringPool.PERIOD);
154: sm.append(cal.get(Calendar.MONTH));
155: sm.append(StringPool.PERIOD);
156: sm.append(cal.get(Calendar.DATE));
157: sm.append(StringPool.PERIOD);
158: sm.append(cal.getTimeZone().getRawOffset());
159:
160: return sm.toString();
161: }
162:
163: }
|