0001: /**
0002: * $Id: APimEvent.java,v 1.14 2003/11/21 00:42:38 rakeshn Exp $
0003: * Copyright 2002 Sun Microsystems, Inc. All
0004: * rights reserved. Use of this product is subject
0005: * to license terms. Federal Acquisitions:
0006: * Commercial Software -- Government Users
0007: * Subject to Standard License Terms and
0008: * Conditions.
0009: *
0010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0011: * are trademarks or registered trademarks of Sun Microsystems,
0012: * Inc. in the United States and other countries.
0013: *
0014: */package com.sun.ssoadapter.calendar.pim;
0015:
0016: import java.util.*;
0017: import java.text.SimpleDateFormat;
0018:
0019: import com.sun.comclient.calendar.*;
0020:
0021: import com.aligo.pim.interfaces.*;
0022: import com.aligo.pim.exceptions.*;
0023: import com.aligo.pim.*;
0024:
0025: public class APimEvent extends VEvent {
0026:
0027: private PimAppointmentItem event = null;
0028: private APimCalendar parentCal = null;
0029: private PimRecurrencePatternItem rpattern = null;
0030: private RecurrencePattern[] rpa = new RecurrencePattern[1];
0031:
0032: private SimpleDateFormat isoFormatter;
0033: private String isoFormat = "yyyyMMdd'T'HHmmss'Z'";
0034: private boolean isNew = false;
0035: private TimeZone tz = null;
0036:
0037: private DateTime start = null;
0038: private DateTime end = null;
0039: private boolean isAllDay = true;
0040: private String summary = null;
0041: private String description = null;
0042: private String location = null;
0043: private String id = null;
0044: private String organizerName = null;
0045: private ArrayList attendeeList = new ArrayList();
0046: private VAlarm alarm = null;
0047: private String meetingId = null;
0048:
0049: static final int FOREVER_DURATION = 1490000;
0050: private static boolean enableCache = true;
0051:
0052: public APimEvent(APimCalendar cal, PimAppointmentItem item,
0053: boolean isNew, PimMeetingItem meet) {
0054: parentCal = cal;
0055: this .isNew = isNew;
0056:
0057: //set the following before the call to toDateTime
0058: isoFormatter = new SimpleDateFormat(isoFormat);
0059: isoFormatter.setTimeZone(new SimpleTimeZone(0, "GMT"));
0060: isoFormatter.setLenient(false);
0061:
0062: tz = cal.getTimeZone();
0063: if (item != null) {
0064: try {
0065: event = item;
0066: id = item.getID();
0067: summary = event.getSubject();
0068: description = event.getText();
0069: location = event.getLocation();
0070: isAllDay = event.isAllDayEvent();
0071: if (event.getType().equals(PimCalendarType.ANNIVERSARY)) {
0072: isAllDay = true;
0073: }
0074: start = toDateTime(event.getStartTime());
0075: end = toDateTime(event.getEndTime());
0076: organizerName = event.getOrganizer().getName();
0077: rpattern = event.getRecurrencePatternItem();
0078:
0079: if (meet != null) {
0080: meetingId = meet.getID();
0081: }
0082: //rpattern is not set, not sure what immplication will it have
0083: //if any of the above fails than the event will be not null
0084:
0085: if (enableCache) {
0086: event = null;
0087: }
0088:
0089: } catch (PimException pex) {
0090: pex.printStackTrace();
0091: } catch (Exception ex) {
0092: ex.printStackTrace();
0093: }
0094: }
0095:
0096: }
0097:
0098: public APimEvent(APimCalendar cal, PimAppointmentItem item) {
0099: this (cal, item, false);
0100: }
0101:
0102: public APimEvent(APimCalendar cal, PimAppointmentItem item,
0103: boolean isNew) {
0104: this (cal, item, isNew, null);
0105: }
0106:
0107: private DateTime toDateTime(Date date) throws Exception {
0108: if (date != null) {
0109: String tmp = isoFormatter.format(date);
0110: return new DateTime(tmp, tz);
0111: }
0112: return null;
0113: }
0114:
0115: private RecurrencePattern toRecurrencePattern() throws Exception {
0116: if (rpattern != null) {
0117: int interval = rpattern.getInterval();
0118: PimRecurrencePatternType pType = rpattern.getType();
0119:
0120: int freq = RecurrencePattern.YEARLY;
0121: if (pType == PimRecurrencePatternType.DAILY) {
0122: freq = RecurrencePattern.DAILY;
0123: } else if (pType == PimRecurrencePatternType.WEEKLY) {
0124: freq = RecurrencePattern.WEEKLY;
0125: } else if (pType == PimRecurrencePatternType.MONTHLY) {
0126: freq = RecurrencePattern.MONTHLY;
0127: } else if (pType == PimRecurrencePatternType.YEARLY) {
0128: freq = RecurrencePattern.YEARLY;
0129: }
0130:
0131: int cnt = rpattern.getNoOfOccurrences();
0132: Date dt = rpattern.getRecurrenceEndDate();
0133:
0134: DateTime start = getStart();
0135:
0136: RecurrencePattern rp = new RecurrencePattern(freq,
0137: interval, cnt);
0138: rp.setUntilDate(toDateTime(dt));
0139:
0140: if (freq != RecurrencePattern.DAILY) {
0141: String days = null;
0142: try {
0143: Vector dow = rpattern.getDaysOfWeek();
0144: StringBuffer str = new StringBuffer();
0145:
0146: for (int i = 0; i < dow.size(); i++) {
0147: Object t = dow.elementAt(i);
0148: String tmp = t.toString();
0149: str.append(", ");
0150: str.append(tmp.substring(0, 2));
0151: }
0152: str.setCharAt(0, ' ');
0153:
0154: days = str.toString().trim();
0155:
0156: if (freq == RecurrencePattern.MONTHLY
0157: || freq == RecurrencePattern.YEARLY) {
0158: int weekOfMonth = start
0159: .get(java.util.Calendar.DAY_OF_WEEK_IN_MONTH);
0160: if (weekOfMonth > 4)
0161: weekOfMonth = -1;
0162:
0163: rp.setByDay(weekOfMonth + days);
0164: } else {
0165: rp.setByDay(days);
0166: }
0167: } catch (Exception e) {
0168: if (freq != RecurrencePattern.WEEKLY) {
0169: String monthdays = null;
0170: try {
0171: Vector dom = rpattern.getDaysOfMonth();
0172: StringBuffer str = new StringBuffer();
0173:
0174: for (int i = 0; i < dom.size(); i++) {
0175: Object t = dom.elementAt(i);
0176: String tmp = t.toString();
0177: str.append(", ");
0178: str.append(tmp);
0179: }
0180: str.setCharAt(0, ' ');
0181:
0182: monthdays = str.toString().trim();
0183: rp.setByMonthDay(monthdays);
0184: } catch (Exception ep) {
0185: ep.printStackTrace();
0186: throw new CalendarComponentException(ep
0187: .toString());
0188: }
0189: }
0190: }
0191:
0192: if (freq == RecurrencePattern.YEARLY) {
0193: int month = start.get(java.util.Calendar.MONTH) + 1;
0194: rp.setByMonth(month + "");
0195: }
0196: }
0197: return rp;
0198: }
0199:
0200: return null;
0201: }
0202:
0203: private void toAPimRecurrencePattern(RecurrencePattern rp)
0204: throws Exception {
0205: if (rp != null) {
0206: // rpattern is still null, means this is not an editable recurrence
0207: if (rpattern == null)
0208: throw new OperationNotSupportedException(
0209: "Can not create new recurrences, only modify existing ones");
0210:
0211: int interval = rp.getInterval();
0212: String freq = rp.getFrequency();
0213:
0214: PimRecurrencePatternType pType = PimRecurrencePatternType.YEARLY;
0215: if (freq.equals("DAILY")) {
0216: pType = PimRecurrencePatternType.DAILY;
0217: } else if (freq.equals("WEEKLY")) {
0218: pType = PimRecurrencePatternType.WEEKLY;
0219: } else if (freq.equals("MONTHLY")) {
0220: pType = PimRecurrencePatternType.MONTHLY;
0221: } else if (freq.equals("YEARLY")) {
0222: pType = PimRecurrencePatternType.YEARLY;
0223: }
0224:
0225: DateTime dt = rp.getUntilDate();
0226: int cnt = rp.getCount();
0227:
0228: rpattern.setType(pType);
0229:
0230: if (cnt == -1) {
0231: rpattern.setNoOfOccurrences(FOREVER_DURATION);
0232: } else if (dt != null)
0233: rpattern.setRecurrenceEndDate(dt.getTime());
0234: else if (freq.equals("WEEKLY")) { //bug#4953089
0235: rpattern.setNoOfInstances(cnt);
0236: } else {
0237: rpattern.setNoOfOccurrences(cnt);
0238: }
0239:
0240: rpattern.setInterval(interval);
0241:
0242: if (pType == PimRecurrencePatternType.WEEKLY) {
0243: String days = rp.getByDay();
0244: if (days != null) {
0245: String[] dayArry = split(',', days);
0246: Vector dow = toPimDay(dayArry);
0247: rpattern.setDaysOfWeek(dow);
0248: } else {
0249: DateTime start = getStart();
0250: int dow = start.get(Calendar.DAY_OF_WEEK);
0251:
0252: String[] arr = new String[1];
0253: switch (dow) {
0254: case Calendar.SUNDAY:
0255: arr[0] = "SU";
0256: break;
0257: case Calendar.MONDAY:
0258: arr[0] = "MO";
0259: break;
0260: case Calendar.TUESDAY:
0261: arr[0] = "TU";
0262: break;
0263: case Calendar.WEDNESDAY:
0264: arr[0] = "WE";
0265: break;
0266: case Calendar.THURSDAY:
0267: arr[0] = "TH";
0268: break;
0269: case Calendar.FRIDAY:
0270: arr[0] = "FR";
0271: break;
0272: case Calendar.SATURDAY:
0273: arr[0] = "SA";
0274: }
0275: rpattern.setDaysOfWeek(toPimDay(arr));
0276: }
0277: } else if (pType == PimRecurrencePatternType.MONTHLY
0278: || pType == PimRecurrencePatternType.YEARLY) {
0279: DateTime start = getStart();
0280: DateTime dateTmp = (DateTime) start.clone();
0281: String monthday = rp.getByMonthDay();
0282: if (monthday != null) {
0283: String[] arr = split(',', monthday);
0284: Vector monthDays = new Vector();
0285:
0286: for (int i = 0; i < arr.length; i++) {
0287: monthDays.add(new Integer(arr[i]));
0288: }
0289:
0290: rpattern.setDaysOfMonth(monthDays);
0291: } else {
0292: String days = rp.getByDay();
0293: if (days != null) {
0294: String[] arr = split(',', days);
0295:
0296: // only use the first one if there is more then one
0297: if (arr.length > 1) {
0298: String[] tmp = new String[1];
0299: tmp[0] = arr[0];
0300: arr = tmp;
0301: }
0302:
0303: int len = arr[0].length();
0304: String weekOfMonth = null;
0305: if (len > 2) {
0306: weekOfMonth = arr[0].substring(0, len - 2);
0307:
0308: int wom = Integer.parseInt(weekOfMonth);
0309: dateTmp.set(Calendar.DAY_OF_WEEK_IN_MONTH,
0310: wom);
0311: }
0312:
0313: // this is incomplete as there is no way to represent
0314: // a WeekOfMonth along with a DayOfWeek, etc.. in the
0315: // Aligo PIM recurrence objects.
0316:
0317: if (arr[0].equals("MO")) {
0318: dateTmp.set(Calendar.DAY_OF_WEEK,
0319: Calendar.MONDAY);
0320: } else if (arr[0].equals("TU")) {
0321: dateTmp.set(Calendar.DAY_OF_WEEK,
0322: Calendar.TUESDAY);
0323: } else if (arr[0].equals("WE")) {
0324: dateTmp.set(Calendar.DAY_OF_WEEK,
0325: Calendar.WEDNESDAY);
0326: } else if (arr[0].equals("TH")) {
0327: dateTmp.set(Calendar.DAY_OF_WEEK,
0328: Calendar.THURSDAY);
0329: } else if (arr[0].equals("FR")) {
0330: dateTmp.set(Calendar.DAY_OF_WEEK,
0331: Calendar.FRIDAY);
0332: } else if (arr[0].equals("SA")) {
0333: dateTmp.set(Calendar.DAY_OF_WEEK,
0334: Calendar.SATURDAY);
0335: } else if (arr[0].equals("SU")) {
0336: dateTmp.set(Calendar.DAY_OF_WEEK,
0337: Calendar.SUNDAY);
0338: }
0339:
0340: dateTmp.clear(Calendar.DAY_OF_MONTH);
0341: dateTmp.clear(Calendar.WEEK_OF_MONTH);
0342: } else {
0343: // Default action when neither "days" and "monthday"
0344: // are both null. This creates a monthly recurrence
0345: // based on the day of the month specified in the start date.
0346: int day = start.get(Calendar.DAY_OF_MONTH);
0347: Vector monthDays = new Vector();
0348: monthDays.add(new Integer(day));
0349: rpattern.setDaysOfMonth(monthDays);
0350: }
0351: }
0352:
0353: if (pType == PimRecurrencePatternType.YEARLY) {
0354: String month = rp.getByMonth();
0355: if (month != null) {
0356: int mon = Integer.parseInt(month);
0357: dateTmp.set(Calendar.MONTH, mon - 1);
0358: }
0359: }
0360:
0361: // Check to see if recurrence has changed the start date
0362: // if so, then reset the start date
0363: if (!start.equals(dateTmp)) {
0364: setStart(dateTmp);
0365: }
0366:
0367: }
0368: }
0369: }
0370:
0371: private Vector toPimDay(String[] dayArry) {
0372: Vector dow = new Vector();
0373: String tmp = null;
0374: for (int i = 0; i < dayArry.length; i++) {
0375: int len = dayArry[i].length();
0376:
0377: if (len > 2) {
0378: tmp = dayArry[i].substring(len - 2);
0379: } else {
0380: tmp = dayArry[i];
0381: }
0382:
0383: if (tmp.equals("MO")) {
0384: dow.add(PimRecurrencePatternDayType.MONDAY);
0385: } else if (tmp.equals("TU")) {
0386: dow.add(PimRecurrencePatternDayType.TUESDAY);
0387: } else if (tmp.equals("WE")) {
0388: dow.add(PimRecurrencePatternDayType.WEDNESDAY);
0389: } else if (tmp.equals("TH")) {
0390: dow.add(PimRecurrencePatternDayType.THURSDAY);
0391: } else if (tmp.equals("FR")) {
0392: dow.add(PimRecurrencePatternDayType.FRIDAY);
0393: } else if (tmp.equals("SA")) {
0394: dow.add(PimRecurrencePatternDayType.SATURDAY);
0395: } else if (tmp.equals("SU")) {
0396: dow.add(PimRecurrencePatternDayType.SUNDAY);
0397: }
0398: }
0399: return dow;
0400: }
0401:
0402: private String[] split(char splitChar, String str) {
0403: if (str != null) {
0404: int cnt = 1;
0405:
0406: // Count the number of pieces
0407: for (int i = 0; i < str.length(); i++) {
0408: if (str.charAt(i) == splitChar)
0409: cnt++;
0410: }
0411:
0412: // Create return array
0413: String r[] = new String[cnt];
0414:
0415: if (cnt > 1) {
0416: StringTokenizer t = new StringTokenizer(str, String
0417: .valueOf(splitChar));
0418: cnt = 0;
0419: while (t.hasMoreTokens()) {
0420: r[cnt] = t.nextToken().trim();
0421: cnt++;
0422: }
0423: } else {
0424: r[0] = str.trim();
0425: }
0426:
0427: return r;
0428: } else {
0429: return null;
0430: }
0431: }
0432:
0433: public void addAlarmComponent(VAlarm alarm)
0434: throws OperationNotSupportedException {
0435: this .alarm = alarm;
0436: }
0437:
0438: public void addAttachment(Attach attachment)
0439: throws OperationNotSupportedException {
0440: throw new OperationNotSupportedException("");
0441: }
0442:
0443: public void addCategory(java.lang.String category)
0444: throws OperationNotSupportedException {
0445: throw new OperationNotSupportedException("");
0446: }
0447:
0448: public void addExceptionDate(DateTime exceptionDate)
0449: throws OperationNotSupportedException {
0450: throw new OperationNotSupportedException("");
0451: }
0452:
0453: public void addExceptionRule(RecurrencePattern exceptionRule)
0454: throws OperationNotSupportedException {
0455: throw new OperationNotSupportedException("");
0456: }
0457:
0458: public void addRecurrenceDate(DateTime recurrenceDate)
0459: throws OperationNotSupportedException {
0460: throw new OperationNotSupportedException("");
0461: }
0462:
0463: public void addRecurrenceRule(RecurrencePattern recurrenceRule)
0464: throws CalendarComponentException {
0465: rpa[0] = recurrenceRule;
0466: }
0467:
0468: public void addRelatedTo(java.lang.String relatedTo)
0469: throws OperationNotSupportedException {
0470: throw new OperationNotSupportedException("");
0471: }
0472:
0473: public void addResource(java.lang.String resource)
0474: throws OperationNotSupportedException {
0475: throw new OperationNotSupportedException("");
0476: }
0477:
0478: public VAlarm[] getAlarmComponents()
0479: throws OperationNotSupportedException {
0480: if (alarm != null) {
0481: VAlarm[] result = new VAlarm[1];
0482: result[0] = alarm;
0483: return result;
0484: }
0485: return null;
0486: }
0487:
0488: public Attach[] getAttachments()
0489: throws OperationNotSupportedException {
0490: throw new OperationNotSupportedException("");
0491: }
0492:
0493: public String[] getCategories()
0494: throws OperationNotSupportedException {
0495: throw new OperationNotSupportedException("");
0496: }
0497:
0498: public String getClassification()
0499: throws OperationNotSupportedException {
0500: throw new OperationNotSupportedException("");
0501: }
0502:
0503: public DateTime getCreated() throws OperationNotSupportedException {
0504: throw new OperationNotSupportedException("");
0505: }
0506:
0507: public String getDescription() throws CalendarComponentException {
0508: try {
0509: if (event == null) {
0510: return description;
0511: }
0512: return event.getText();
0513: } catch (Exception pex) {
0514: pex.printStackTrace();
0515: throw new CalendarComponentException(pex.getMessage());
0516: }
0517: }
0518:
0519: public DateTime[] getExceptionDates()
0520: throws OperationNotSupportedException {
0521: throw new OperationNotSupportedException("");
0522: }
0523:
0524: public RecurrencePattern[] getExceptionRules()
0525: throws OperationNotSupportedException {
0526: throw new OperationNotSupportedException("");
0527: }
0528:
0529: public String getGeo() throws OperationNotSupportedException {
0530: throw new OperationNotSupportedException("");
0531: }
0532:
0533: public DateTime getLastModified()
0534: throws OperationNotSupportedException {
0535: throw new OperationNotSupportedException("");
0536: }
0537:
0538: public String getLocation() throws CalendarComponentException {
0539: try {
0540: if (event == null) {
0541: return location;
0542: }
0543: return event.getLocation();
0544: } catch (Exception pex) {
0545: pex.printStackTrace();
0546: throw new CalendarComponentException(pex.getMessage());
0547: }
0548: }
0549:
0550: public int getPriority() throws OperationNotSupportedException {
0551: throw new OperationNotSupportedException("");
0552: }
0553:
0554: public DateTime[] getRecurrenceDates()
0555: throws OperationNotSupportedException {
0556: throw new OperationNotSupportedException("");
0557: }
0558:
0559: public DateTime getRecurrenceID()
0560: throws OperationNotSupportedException,
0561: CalendarComponentException {
0562: throw new OperationNotSupportedException("");
0563: }
0564:
0565: public boolean isRecurring() throws CalendarComponentException {
0566: try {
0567: if (event == null) {
0568: if (isNew) {
0569: if (rpa[0] == null) {
0570: return false;
0571: }
0572: } else if (rpattern == null) {
0573: return false;
0574: }
0575:
0576: } else {
0577: rpattern = event.getRecurrencePatternItem();
0578: if (rpattern == null) {
0579: return false;
0580: }
0581: }
0582: } catch (Exception pex) {
0583: pex.printStackTrace();
0584: }
0585: return true;
0586: }
0587:
0588: public RecurrencePattern[] getRecurrenceRules()
0589: throws OperationNotSupportedException,
0590: CalendarComponentException {
0591: RecurrencePattern rp = null;
0592: try {
0593: if (rpa[0] != null) {
0594: //Even if event is valid still this will override.
0595: return rpa;
0596: }
0597: if (event == null) {
0598: return null;
0599: } else {
0600: if (rpattern == null)
0601: rpattern = event.getRecurrencePatternItem();
0602:
0603: if (rpattern != null) {
0604: rp = toRecurrencePattern();
0605: rpa[0] = rp;
0606: return rpa;
0607: } else
0608: return null;
0609: }
0610: } catch (Exception pex) {
0611: pex.printStackTrace();
0612: throw new CalendarComponentException(pex.getMessage());
0613: }
0614: }
0615:
0616: public String[] getRelatedTos()
0617: throws OperationNotSupportedException {
0618: throw new OperationNotSupportedException("");
0619: }
0620:
0621: public String[] getResources()
0622: throws OperationNotSupportedException {
0623: throw new OperationNotSupportedException("");
0624: }
0625:
0626: public int getSequence() throws OperationNotSupportedException {
0627: throw new OperationNotSupportedException("");
0628: }
0629:
0630: public DateTime getStart() throws CalendarComponentException {
0631:
0632: try {
0633: if (event != null) {
0634: start = toDateTime(event.getStartTime());
0635: }
0636: return start;
0637: } catch (Exception pex) {
0638: pex.printStackTrace();
0639: throw new CalendarComponentException(pex.getMessage());
0640: }
0641:
0642: }
0643:
0644: public String getStatus() throws OperationNotSupportedException,
0645: CalendarComponentException {
0646: throw new OperationNotSupportedException("");
0647: }
0648:
0649: public String getSummary() throws CalendarComponentException {
0650: try {
0651: if (event != null) {
0652: return event.getSubject();
0653: }
0654: return summary;
0655: } catch (Exception pex) {
0656: pex.printStackTrace();
0657: throw new CalendarComponentException(pex.getMessage());
0658: }
0659: }
0660:
0661: public boolean isAllDay() throws CalendarComponentException {
0662: try {
0663: if (event != null) {
0664: if (event.getType().equals(PimCalendarType.ANNIVERSARY)) {
0665: return true;
0666: } else {
0667: return event.isAllDayEvent();
0668: }
0669: }
0670: return isAllDay;
0671: } catch (Exception pex) {
0672: pex.printStackTrace();
0673: throw new CalendarComponentException(pex.getMessage());
0674: }
0675: }
0676:
0677: public void removeAlarmComponent(VAlarm alarm)
0678: throws OperationNotSupportedException {
0679: throw new OperationNotSupportedException("");
0680: }
0681:
0682: public void removeAllAlarmComponents()
0683: throws OperationNotSupportedException {
0684: throw new OperationNotSupportedException("");
0685: }
0686:
0687: public void removeAllAttachments()
0688: throws OperationNotSupportedException {
0689: throw new OperationNotSupportedException("");
0690: }
0691:
0692: public void removeAllCategories()
0693: throws OperationNotSupportedException {
0694: throw new OperationNotSupportedException("");
0695: }
0696:
0697: public void removeAllExceptionDates()
0698: throws OperationNotSupportedException {
0699: throw new OperationNotSupportedException("");
0700: }
0701:
0702: public void removeAllExceptionRules()
0703: throws OperationNotSupportedException {
0704: throw new OperationNotSupportedException("");
0705: }
0706:
0707: public void removeAllRecurrenceDates()
0708: throws OperationNotSupportedException {
0709: throw new OperationNotSupportedException("");
0710: }
0711:
0712: public void removeAllRecurrenceRules()
0713: // throws OperationNotSupportedException
0714: {
0715: // throw new OperationNotSupportedException("");
0716: }
0717:
0718: public void removeAllRelatedTos()
0719: throws OperationNotSupportedException {
0720: throw new OperationNotSupportedException("");
0721: }
0722:
0723: public void removeAllResources()
0724: throws OperationNotSupportedException {
0725: throw new OperationNotSupportedException("");
0726: }
0727:
0728: public void removeAttachment(Attach attachment)
0729: throws OperationNotSupportedException {
0730: throw new OperationNotSupportedException("");
0731: }
0732:
0733: public void removeCategory(java.lang.String category)
0734: throws OperationNotSupportedException {
0735: throw new OperationNotSupportedException("");
0736: }
0737:
0738: public void removeExceptionDate(DateTime exceptionDate)
0739: throws OperationNotSupportedException {
0740: throw new OperationNotSupportedException("");
0741: }
0742:
0743: public void removeExceptionRule(RecurrencePattern exceptionRule)
0744: throws OperationNotSupportedException {
0745: throw new OperationNotSupportedException("");
0746: }
0747:
0748: public void removeRecurrenceDate(DateTime recurrenceDate)
0749: throws OperationNotSupportedException {
0750: throw new OperationNotSupportedException("");
0751: }
0752:
0753: public void removeRecurrenceRule(RecurrencePattern recurrenceRule)
0754: throws OperationNotSupportedException,
0755: CalendarComponentException {
0756: throw new OperationNotSupportedException("");
0757: }
0758:
0759: public void removeRelatedTo(String relatedTo)
0760: throws OperationNotSupportedException {
0761: throw new OperationNotSupportedException("");
0762: }
0763:
0764: public void removeResource(String resource)
0765: throws OperationNotSupportedException {
0766: throw new OperationNotSupportedException("");
0767: }
0768:
0769: public void setAllDay(boolean allday)
0770: throws CalendarComponentException {
0771: try {
0772: if (event != null) {
0773: event.setAllDayEvent(allday);
0774: }
0775: isAllDay = allday;
0776: } catch (Exception pex) {
0777: pex.printStackTrace();
0778: throw new CalendarComponentException(pex.getMessage());
0779: }
0780: }
0781:
0782: public void setClassification(java.lang.String classification)
0783: throws OperationNotSupportedException {
0784: throw new OperationNotSupportedException("");
0785: }
0786:
0787: public void setDescription(java.lang.String description)
0788: throws CalendarComponentException {
0789: try {
0790: if (event != null) {
0791: event.setText(description);
0792: }
0793: this .description = description;
0794: } catch (Exception pex) {
0795: pex.printStackTrace();
0796: throw new CalendarComponentException(pex.getMessage());
0797: }
0798: }
0799:
0800: public void setDuration(Duration duration)
0801: throws OperationNotSupportedException {
0802: throw new OperationNotSupportedException("");
0803: }
0804:
0805: public void setGeo(java.lang.String geo)
0806: throws OperationNotSupportedException {
0807: throw new OperationNotSupportedException("");
0808: }
0809:
0810: public void setLastModified(DateTime lastModified)
0811: throws OperationNotSupportedException {
0812: throw new OperationNotSupportedException("");
0813: }
0814:
0815: public void setLocation(java.lang.String location)
0816: throws CalendarComponentException {
0817: try {
0818: if (event != null) {
0819: event.setLocation(location);
0820: }
0821: this .location = location;
0822: } catch (Exception pex) {
0823: pex.printStackTrace();
0824: throw new CalendarComponentException(pex.getMessage());
0825: }
0826: }
0827:
0828: public void setPriority(int priority)
0829: throws OperationNotSupportedException {
0830: throw new OperationNotSupportedException("");
0831: }
0832:
0833: public void setSequence(int sequence)
0834: throws OperationNotSupportedException {
0835: throw new OperationNotSupportedException("");
0836: }
0837:
0838: public void setStart(DateTime dtstart)
0839: throws CalendarComponentException {
0840: try {
0841: if (event != null) {
0842: event.setStartTime(dtstart.getTime());
0843: }
0844: start = dtstart;
0845: } catch (PimException pex) {
0846: pex.printStackTrace();
0847: throw new CalendarComponentException(pex.getMessage());
0848: }
0849: }
0850:
0851: public void setStatus(java.lang.String status)
0852: throws OperationNotSupportedException {
0853: throw new OperationNotSupportedException("");
0854: }
0855:
0856: public void setSummary(java.lang.String summary)
0857: throws CalendarComponentException {
0858: try {
0859: if (event != null) {
0860: event.setSubject(summary);
0861: }
0862: this .summary = summary;
0863: } catch (Exception pex) {
0864: pex.printStackTrace();
0865: throw new CalendarComponentException(pex.getMessage());
0866: }
0867: }
0868:
0869: public String toString() {
0870: try {
0871: return "\nStart: " + getStart() + "\nEnd: " + getEnd()
0872: + "\nSummary: " + getSummary() + "\nDescription: "
0873: + getDescription() + "\nAllDay: " + isAllDay()
0874: + "\n" + ((event == null) ? "" : event.toString());
0875: } catch (Exception e) {
0876: e.printStackTrace();
0877: return "";
0878: }
0879: }
0880:
0881: //**************************************************
0882:
0883: public void setEnd(DateTime dtend)
0884: throws CalendarComponentException {
0885: try {
0886: if (event != null) {
0887: event.setEndTime(dtend.getTime());
0888: }
0889: end = dtend;
0890: } catch (Exception pex) {
0891: throw new CalendarComponentException(pex.getMessage());
0892: }
0893: }
0894:
0895: public DateTime getEnd() throws CalendarComponentException {
0896: try {
0897: if (event != null) {
0898: return toDateTime(event.getEndTime());
0899: }
0900: return end;
0901: } catch (Exception pex) {
0902: throw new CalendarComponentException(pex.getMessage());
0903: }
0904: }
0905:
0906: public void setCalID(String id)
0907: throws OperationNotSupportedException,
0908: CalendarComponentException {
0909: throw new OperationNotSupportedException("");
0910: }
0911:
0912: public String getCalID() throws CalendarComponentException {
0913: return parentCal.getCalID();
0914: }
0915:
0916: public String getUrl() throws OperationNotSupportedException {
0917: throw new OperationNotSupportedException("");
0918: }
0919:
0920: public void setUrl(String url)
0921: throws OperationNotSupportedException {
0922: throw new OperationNotSupportedException("");
0923: }
0924:
0925: public String getID() throws CalendarComponentException {
0926: try {
0927: if (event != null)
0928: return event.getID();
0929: else
0930: return id;
0931: } catch (PimException pex) {
0932: throw new CalendarComponentException(pex.getMessage());
0933: }
0934: }
0935:
0936: public void setID(String uid) throws OperationNotSupportedException {
0937: throw new OperationNotSupportedException("");
0938: }
0939:
0940: public void removeAllRequestStatus()
0941: throws OperationNotSupportedException {
0942: throw new OperationNotSupportedException("");
0943: }
0944:
0945: public void removeRequestStatus(String requeststatus)
0946: throws OperationNotSupportedException {
0947: throw new OperationNotSupportedException("");
0948: }
0949:
0950: public void addRequestStatus(String requeststatus)
0951: throws OperationNotSupportedException {
0952: throw new OperationNotSupportedException("");
0953: }
0954:
0955: public String[] getRequestStatus()
0956: throws OperationNotSupportedException {
0957: throw new OperationNotSupportedException("");
0958: }
0959:
0960: public void setOrganizer(Organizer organizer)
0961: throws OperationNotSupportedException {
0962: throw new OperationNotSupportedException("");
0963: }
0964:
0965: public Organizer getOrganizer() throws CalendarComponentException,
0966: OperationNotSupportedException {
0967: try {
0968: if (event != null) {
0969: PimAddressEntryItem paei = event.getOrganizer();
0970: }
0971: } catch (Exception pex) {
0972: throw new CalendarComponentException(pex.getMessage());
0973: }
0974: return null;
0975: }
0976:
0977: public Duration getDuration() throws CalendarComponentException {
0978: try {
0979: if (event != null) {
0980: int i = event.getDuration();
0981: return new Duration(0, i);
0982: }
0983: return null;
0984: } catch (Exception pex) {
0985: throw new CalendarComponentException(pex.getMessage());
0986: }
0987: }
0988:
0989: public void setStamp(DateTime dtstamp)
0990: throws OperationNotSupportedException {
0991: throw new OperationNotSupportedException("");
0992: }
0993:
0994: public DateTime getStamp() throws OperationNotSupportedException {
0995: throw new OperationNotSupportedException("");
0996: }
0997:
0998: public void removeAllComments()
0999: throws OperationNotSupportedException {
1000: throw new OperationNotSupportedException("");
1001: }
1002:
1003: public void removeComment(String comment)
1004: throws OperationNotSupportedException {
1005: throw new OperationNotSupportedException("");
1006: }
1007:
1008: public void addComment(String comment)
1009: throws OperationNotSupportedException {
1010: throw new OperationNotSupportedException("");
1011: }
1012:
1013: public String[] getComments() throws OperationNotSupportedException {
1014: throw new OperationNotSupportedException("");
1015: }
1016:
1017: public void removeAllContacts()
1018: throws OperationNotSupportedException {
1019: throw new OperationNotSupportedException("");
1020: }
1021:
1022: public void removeContact(String contact)
1023: throws OperationNotSupportedException {
1024: throw new OperationNotSupportedException("");
1025: }
1026:
1027: public void addContact(java.lang.String contact)
1028: throws OperationNotSupportedException {
1029: throw new OperationNotSupportedException("");
1030: }
1031:
1032: public String[] getContacts() throws OperationNotSupportedException {
1033: throw new OperationNotSupportedException("");
1034: }
1035:
1036: public void removeAllAttendees()
1037: throws OperationNotSupportedException {
1038: throw new OperationNotSupportedException("");
1039: }
1040:
1041: public void removeAttendee(Attendee attendee)
1042: throws OperationNotSupportedException {
1043: throw new OperationNotSupportedException("");
1044: }
1045:
1046: public void addAttendee(Attendee attendee)
1047: throws OperationNotSupportedException {
1048: attendeeList.add(attendee);
1049: }
1050:
1051: public Attendee[] getAttendees()
1052: throws OperationNotSupportedException {
1053: return (Attendee[]) attendeeList
1054: .toArray(new Attendee[attendeeList.size()]);
1055: }
1056:
1057: public boolean hasAttendee() throws OperationNotSupportedException {
1058: throw new OperationNotSupportedException("");
1059: }
1060:
1061: public boolean isConfirmed() throws OperationNotSupportedException {
1062: throw new OperationNotSupportedException("");
1063: }
1064:
1065: public boolean isCalIdTheOrganizer(String calId)
1066: throws OperationNotSupportedException,
1067: CalendarComponentException {
1068:
1069: try {
1070: if (event != null && calId != null) {
1071: if (event.getOrganizer() != null) {
1072: return event.getOrganizer().getName().equals(calId);
1073: }
1074: }
1075: if (organizerName != null && calId != null) {
1076: return organizerName.equals(calId);
1077: }
1078: } catch (PimException ex) {
1079: throw new CalendarComponentException(ex.getMessage());
1080: }
1081:
1082: return true;
1083: }
1084:
1085: public Attendee getAttendee(String calid)
1086: throws OperationNotSupportedException {
1087: throw new OperationNotSupportedException("");
1088: }
1089:
1090: public void delete() throws PimException {
1091: if (event != null) {
1092: event.delete();
1093: } else if (id != null) {
1094: event = parentCal.getAppointmentItems().getAppointmentItem(
1095: id);
1096: event.delete();
1097: //not sure what to do with the event
1098: if (enableCache) {
1099: event = null;
1100: }
1101: }
1102: }
1103:
1104: public void update() throws PimException {
1105: if (event == null) {
1106: if (id == null) {
1107: event = parentCal.getAppointmentItems()
1108: .addAppointmentItem();
1109: } else {
1110: event = parentCal.getAppointmentItems()
1111: .getAppointmentItem(id);
1112: }
1113: if (summary != null) {
1114: event.setSubject(summary);
1115: }
1116: if (description != null) {
1117: event.setText(description);
1118: }
1119: if (location != null) {
1120: event.setLocation(location);
1121: }
1122: if (start != null) {
1123: event.setStartTime(start.getTime());
1124: }
1125: if (end != null) {
1126: event.setEndTime(end.getTime());
1127: }
1128: event.setAllDayEvent(isAllDay);
1129: }
1130: if (rpa[0] != null) {
1131: try {
1132: if (rpattern == null) {
1133: rpattern = event.getRecurrencePatternItem();
1134: }
1135: toAPimRecurrencePattern(rpa[0]);
1136: //printRecurrencePattern(rpattern);
1137: rpattern.update();
1138: rpa[0] = null;
1139: } catch (Exception pex) {
1140: }
1141: }
1142: if (attendeeList.size() != 0) {
1143: PimRecipientItems pimRecipientItems = event
1144: .getRecipientItems();
1145: for (int i = 0; i < attendeeList.size(); i++) {
1146: PimRecipientItem pimRecipientItem = pimRecipientItems
1147: .addRecipientItem();
1148: pimRecipientItem
1149: .setEmailAddress(((Attendee) attendeeList
1150: .get(i)).getValue());
1151: pimRecipientItem.setRecipientType(PimRecipientType.TO);
1152: pimRecipientItem.resolve();
1153: pimRecipientItem.update();
1154: }
1155: attendeeList.clear();
1156: }
1157: if (alarm != null) {
1158: PimReminderItem remItem = event.getReminderItem();
1159: Duration dur = alarm.getTrigger();
1160: remItem.setNoOfMinutesBeforeStart(dur.toSeconds() / 60);
1161: alarm = null;
1162: }
1163:
1164: event.update();
1165: isNew = false;
1166: if (id == null) {
1167: id = event.getID();
1168: }
1169:
1170: if (enableCache) {
1171: event = null;
1172: }
1173: }
1174:
1175: private void printRecurrencePattern(PimRecurrencePatternItem prpi)
1176: throws PimException {
1177: System.err
1178: .println("----[PimRecurrencePatternItem]-------------");
1179: System.err.println("getID: " + prpi.getID());
1180: System.err.println("getType: " + prpi.getType());
1181: System.err.println("Interval: " + prpi.getInterval());
1182: System.err.println("NoOfOccurrences: "
1183: + prpi.getNoOfOccurrences());
1184: System.err.println("EndDate: " + prpi.getRecurrenceEndDate());
1185: try {
1186: System.err.println("DaysOfMonth: " + prpi.getDaysOfMonth());
1187: } catch (PimException pex) {
1188: System.err.println("DaysOfMonth threw an exception");
1189: }
1190: try {
1191: System.err.println("DaysOfWeek: " + prpi.getDaysOfWeek());
1192: } catch (PimException pex) {
1193: System.err.println("DaysOfWeek threw an exception");
1194: }
1195: System.err
1196: .println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
1197: }
1198:
1199: public VAlarm createAlarm() throws OperationNotSupportedException {
1200: throw new OperationNotSupportedException("");
1201: }
1202:
1203: // todo
1204:
1205: public boolean isPublic() throws OperationNotSupportedException,
1206: CalendarComponentException {
1207: throw new OperationNotSupportedException("");
1208: }
1209:
1210: public boolean hasAlarm() throws OperationNotSupportedException,
1211: CalendarComponentException {
1212: throw new OperationNotSupportedException("");
1213: }
1214:
1215: public int getPendingAttendeesCount()
1216: throws OperationNotSupportedException,
1217: CalendarComponentException {
1218: throw new OperationNotSupportedException("");
1219: }
1220:
1221: public int getTentativeAttendeesCount()
1222: throws OperationNotSupportedException,
1223: CalendarComponentException {
1224: throw new OperationNotSupportedException("");
1225: }
1226:
1227: public int getDeclinedAttendeesCount()
1228: throws OperationNotSupportedException,
1229: CalendarComponentException {
1230: throw new OperationNotSupportedException("");
1231: }
1232:
1233: public int getAcceptedAttendeesCount()
1234: throws OperationNotSupportedException,
1235: CalendarComponentException {
1236: throw new OperationNotSupportedException("");
1237: }
1238:
1239: }
|