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.model.impl;
022:
023: import com.liferay.portal.SystemException;
024: import com.liferay.portal.kernel.cal.DayAndPosition;
025: import com.liferay.portal.kernel.cal.Duration;
026: import com.liferay.portal.kernel.cal.Recurrence;
027: import com.liferay.portal.kernel.util.Base64;
028: import com.liferay.portal.kernel.util.Validator;
029: import com.liferay.portal.util.PortalUtil;
030: import com.liferay.portal.util.PropsUtil;
031: import com.liferay.portlet.calendar.model.CalEvent;
032: import com.liferay.util.Time;
033:
034: /**
035: * <a href="CalEventImpl.java.html"><b><i>View Source</i></b></a>
036: *
037: * @author Brian Wing Shun Chan
038: *
039: */
040: public class CalEventImpl extends CalEventModelImpl implements CalEvent {
041:
042: public static final String[] TYPES = PropsUtil
043: .getArray(PropsUtil.CALENDAR_EVENT_TYPES);
044:
045: public static final String BIRTHDAY = "birthday";
046:
047: public static final String REMIND_BY_NONE = "none";
048:
049: public static final String REMIND_BY_EMAIL = "email";
050:
051: public static final String REMIND_BY_SMS = "sms";
052:
053: public static final String REMIND_BY_AIM = "aim";
054:
055: public static final String REMIND_BY_ICQ = "icq";
056:
057: public static final String REMIND_BY_MSN = "msn";
058:
059: public static final String REMIND_BY_YM = "ym";
060:
061: public static final long[] REMINDERS = { Time.MINUTE * 5,
062: Time.MINUTE * 15, Time.MINUTE * 30, Time.HOUR,
063: Time.HOUR * 2, Time.HOUR * 3, Time.HOUR * 6,
064: Time.HOUR * 12, Time.DAY, Time.DAY * 2, Time.DAY * 3,
065: Time.DAY * 4, Time.DAY * 5, Time.DAY * 6, Time.DAY * 7,
066: Time.DAY * 8, Time.DAY * 9, Time.DAY * 10, Time.DAY * 11,
067: Time.DAY * 12, Time.DAY * 13, Time.DAY * 14 };
068:
069: public CalEventImpl() {
070: }
071:
072: public String getUserUuid() throws SystemException {
073: return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
074: }
075:
076: public void setUserUuid(String userUuid) {
077: _userUuid = userUuid;
078: }
079:
080: public void setRecurrence(String recurrence) {
081: _recurrenceObj = null;
082:
083: super .setRecurrence(recurrence);
084: }
085:
086: /**
087: * @deprecated
088: */
089: public Recurrence getRecurrenceObj() {
090: if (_recurrenceObj == null) {
091: String recurrence = getRecurrence();
092:
093: if (Validator.isNotNull(recurrence)) {
094: Object obj = Base64.stringToObject(recurrence);
095:
096: if (obj instanceof Recurrence) {
097: _recurrenceObj = (Recurrence) obj;
098: } else if (obj instanceof com.liferay.util.cal.Recurrence) {
099: com.liferay.util.cal.Recurrence oldRecurrence = (com.liferay.util.cal.Recurrence) obj;
100:
101: com.liferay.util.cal.Duration oldDuration = oldRecurrence
102: .getDuration();
103:
104: Duration duration = new Duration(oldDuration
105: .getDays(), oldDuration.getHours(),
106: oldDuration.getMinutes(), oldDuration
107: .getSeconds());
108:
109: duration.setWeeks(oldDuration.getWeeks());
110: duration.setInterval(oldDuration.getInterval());
111:
112: _recurrenceObj = new Recurrence(oldRecurrence
113: .getDtStart(), duration, oldRecurrence
114: .getFrequency());
115:
116: com.liferay.util.cal.DayAndPosition[] oldDayPos = oldRecurrence
117: .getByDay();
118:
119: DayAndPosition[] dayPos = null;
120:
121: if (oldDayPos != null) {
122: dayPos = new DayAndPosition[oldDayPos.length];
123:
124: for (int i = 0; i < oldDayPos.length; i++) {
125: dayPos[i] = new DayAndPosition(oldDayPos[i]
126: .getDayOfWeek(), oldDayPos[i]
127: .getDayPosition());
128: }
129: }
130:
131: _recurrenceObj.setByDay(dayPos);
132: _recurrenceObj.setByMonth(oldRecurrence
133: .getByMonth());
134: _recurrenceObj.setByMonthDay(oldRecurrence
135: .getByMonthDay());
136: _recurrenceObj.setInterval(oldRecurrence
137: .getInterval());
138: _recurrenceObj.setOccurrence(oldRecurrence
139: .getOccurrence());
140: _recurrenceObj.setWeekStart(oldRecurrence
141: .getWeekStart());
142: _recurrenceObj.setUntil(oldRecurrence.getUntil());
143: }
144: }
145: }
146:
147: return _recurrenceObj;
148: }
149:
150: public void setRecurrenceObj(Recurrence recurrenceObj) {
151: _recurrenceObj = recurrenceObj;
152:
153: super .setRecurrence(Base64.objectToString(recurrenceObj));
154: }
155:
156: private String _userUuid;
157: private Recurrence _recurrenceObj = null;
158:
159: }
|