1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package de.bea.domingo.groupware;
24
25 import java.io.InvalidObjectException;
26 import java.io.ObjectStreamException;
27 import java.util.ArrayList;
28 import java.util.Calendar;
29 import java.util.Collection;
30 import java.util.List;
31
32 import de.bea.domingo.map.BaseInstance;
33 import de.bea.domingo.util.DateUtil;
34 import de.bea.domingo.util.GregorianDate;
35 import de.bea.domingo.util.GregorianTime;
36
37 /***
38 * Calendar entry, e.g. in Notes mail databases.
39 *
40 * @author <a href=mailto:kriede@users.sourceforge.net>Kurt Riede</a>
41 * @author Thanx to <a href=mailto:d-rizzle at users.sourceforge.net>Dave Rowe</a> for some patches
42 */
43 public class CalendarEntry extends BaseInstance {
44
45 /***
46 * Represents all possible values for the importance.
47 */
48 public static final class Type {
49
50 /*** calendar entry type: Appointment. */
51 public static final Type APPOINTMENT = new Type((byte) 0, "appointment");
52
53 /*** calendar entry type: Anniversary. */
54 public static final Type ANNIVERSARY = new Type((byte) 1, "anniversary");
55
56 /*** calendar entry type: All Day Event. */
57 public static final Type ALLDAYEVENT = new Type((byte) 2, "all-day-event");
58
59 /*** calendar entry type: Appointment. */
60 public static final Type MEETING = new Type((byte) 3, "meeting");
61
62 /*** calendar entry type: Reminder. */
63 public static final Type REMINDER = new Type((byte) 4, "reminder");
64
65 /*** calendar entry type value: Appointment. */
66 public static final int APPOINTMENT_VALUE = 0;
67
68 /*** calendar entry type value: Anniversary. */
69 public static final int ANNIVERSARY_VALUE = 1;
70
71 /*** calendar entry type value: All Day Event. */
72 public static final int ALLDAYEVENT_VALUE = 2;
73
74 /*** calendar entry type value: Appointment. */
75 public static final int MEETING_VALUE = 3;
76
77 /*** calendar entry type value: Reminder. */
78 public static final int REMINDER_VALUE = 4;
79
80 private static final Type[] TYPES;
81
82 static {
83 TYPES = new Type[REMINDER.fValue + 1];
84 int i = 0;
85 TYPES[i++] = APPOINTMENT;
86 TYPES[i++] = ANNIVERSARY;
87 TYPES[i++] = ALLDAYEVENT;
88 TYPES[i++] = MEETING;
89 TYPES[i++] = REMINDER;
90 }
91
92 private byte fValue;
93
94 private transient final String fName;
95
96 private Type(final byte i, final String name) {
97 fValue = i;
98 fName = name;
99 }
100
101 /***
102 * {@inheritDoc}
103 * @see java.lang.Object#toString()
104 */
105 public String toString() {
106 return fName;
107 }
108
109 private Object readResolve() throws ObjectStreamException {
110 if (fValue >= 0 && fValue <= TYPES.length) {
111 return TYPES[fValue];
112 }
113 throw new InvalidObjectException("Attempt to resolve unknown type: " + fValue);
114 }
115 }
116
117 /*** Subject. */
118 private String fTitle;
119
120 /*** The person who has the chair. */
121 private String fChair;
122
123 /***
124 * Type of a calendar entry. Can be one of {@link #APPOINTMENT},
125 * {@link #ANNIVERSARY}, {@link #ALLDAYEVENT}, {@link #MEETING} or
126 * {@link #REMINDER}, defaults to {@link #MEETING}.
127 */
128 private Type fType = Type.MEETING;
129
130 /*** Location. */
131 private String fLocation;
132
133 /*** Categories (List of Strings). */
134 private List fCategories = new ArrayList();
135
136 /*** Sent attachments with the meeting invitation. */
137 private boolean fSendAttachments;
138
139 /*** The date when the Calendar Entry starts (in local time). */
140 private Calendar fStartDate;
141
142 /*** The date when the Calendar Entry ends (in local time). */
143 private Calendar fEndDate;
144
145 /*** The time when the Calendar Entry starts (in local time). */
146 private Calendar fStartTime;
147
148 /*** The time when the Calendar Entry ends (in local time). */
149 private Calendar fEndTime;
150
151 /*** The list of Start/End Times for a repeating event. */
152 private List fStartDateTime;
153
154 /*** Required invitees (List of Strings). */
155 private List fRequiredInvitees;
156
157 /*** Optional invitees (List of Strings). */
158 private List fOptionalInvitees;
159
160 /*** Optional informed persons (List of Strings). */
161 private List fInformedInvitees;
162
163 /*** List of allocated rooms. */
164 private List fRooms;
165
166 /*** Single allocated room. */
167 private String fRoom;
168
169 /*** List of allocated resources. */
170 private List fResources;
171
172 /*** Appointment Unique ID - this is UNID of the event's parent document, or an imported iCalendar event UID */
173 private String fAppointmentUnid;
174
175
176
177 /***
178 * Default Constructor.
179 */
180 public CalendarEntry () {
181
182 }
183
184 /***
185 * Copy constructor.
186 *
187 * @param copyFrom CalendarEntry to copy from.
188 */
189 public CalendarEntry (final CalendarEntry copyFrom) {
190 fTitle = copyFrom.getTitle();
191 fChair = copyFrom.getChair();
192 fType = copyFrom.getType();
193 fLocation = copyFrom.getLocation();
194 fCategories = copyFrom.getCategories();
195 fSendAttachments = copyFrom.isSendAttachments();
196 fStartDate = copyFrom.getStartDate();
197 fEndDate = copyFrom.getEndDate();
198 fStartTime = copyFrom.getStartTime();
199 fEndTime = copyFrom.getEndTime();
200 fStartDateTime = copyFrom.getStartDateTime();
201 fRequiredInvitees = copyFrom.getRequiredInvitees();
202 fOptionalInvitees = copyFrom.getOptionalInvitees();
203 fInformedInvitees = copyFrom.getInformedInvitees();
204 fRooms = copyFrom.getRooms();
205 fResources = copyFrom.getResources();
206 fAppointmentUnid = copyFrom.getAppointmentUnid();
207 }
208
209 /***
210 * Returns the end date of a calendar entry.
211 *
212 * @return Returns the endDate.
213 */
214 public final Calendar getEndDate() {
215 return fEndDate;
216 }
217
218 /***
219 * @param date The endDate to set.
220 */
221 public final void setEndDate(final Calendar date) {
222 this.fEndDate = date instanceof GregorianDate ? date : new GregorianDate(date);
223 }
224
225 /***
226 * Sets the start date of a calendar entry.
227 *
228 * <p>The first month of the year is <code>JANUARY</code> which is 0; the
229 * last month is <code>DEDCEMBER</code> which is 11.</p>
230 *
231 * @param year the year of the endDate to set.
232 * @param month the month of the endDate to set.
233 * @param day the day of the endDate to set.
234 */
235 public final void setEndDate(final int year, final int month, final int day) {
236 fEndDate = new GregorianDate(year, month, day);
237 }
238
239 /***
240 * Returns the end time of a calendar entry.
241 *
242 * @return Returns the endTime.
243 */
244 public final Calendar getEndTime() {
245 return fEndTime;
246 }
247
248 /***
249 * Sets the end time of a calendar entry.
250 *
251 * @param time The endTime to set.
252 */
253 public final void setEndTime(final Calendar time) {
254 this.fEndTime = time instanceof GregorianTime ? time : new GregorianTime(time);
255 }
256
257 /***
258 * Sets the end time of a calendar entry.
259 *
260 * @param hours the hours of the endDate to set.
261 * @param minutes the minutes of the endDate to set.
262 * @param seconds the seconds of the endDate to set.
263 */
264 public final void setEndTime(final int hours, final int minutes, final int seconds) {
265 this.fEndTime = new GregorianTime(hours, minutes, seconds);
266 }
267
268 /***
269 * Returns the start date of a calendar entry.
270 *
271 * @return Returns the startDate.
272 */
273 public final Calendar getStartDate() {
274 return fStartDate;
275 }
276
277 /***
278 * Sets the start date of a calendar entry.
279 *
280 * @param date The startDate to set.
281 */
282 public final void setStartDate(final Calendar date) {
283 this.fStartDate = date instanceof GregorianDate ? date : new GregorianDate(date);
284 }
285
286 /***
287 * Sets the start date of a calendar entry.
288 *
289 * <p>The first month of the year is <code>JANUARY</code> which is 0; the
290 * last month is <code>DEDCEMBER</code> which is 11.</p>
291 *
292 * @param year the year of the endDate to set.
293 * @param month the month of the endDate to set.
294 * @param day the day of the endDate to set.
295 */
296 public final void setStartDate(final int year, final int month, final int day) {
297 fStartDate = new GregorianDate(year, month, day);
298 }
299
300 /***
301 * Returns the start time.
302 *
303 * @return Returns the startTime.
304 */
305 public final Calendar getStartTime() {
306 return fStartTime;
307 }
308
309 /***
310 * Sets the start time.
311 *
312 * @param time The startTime to set.
313 */
314 public final void setStartTime(final Calendar time) {
315 this.fStartTime = time instanceof GregorianTime ? time : new GregorianTime(time);
316 }
317
318 /***
319 * Sets the start time.
320 *
321 * @param hours the hours of the endDate to set.
322 * @param minutes the minutes of the endDate to set.
323 * @param seconds the seconds of the endDate to set.
324 */
325 public final void setStartTime(final int hours, final int minutes, final int seconds) {
326 this.fStartTime = new GregorianTime(hours, minutes, seconds);
327 }
328
329 /***
330 * Sets the title.
331 *
332 * @param title the title
333 */
334 public final void setTitle(final String title) {
335 fTitle = title;
336 }
337
338 /***
339 * Returns the chair of a calendar entry.
340 *
341 * @return chair the chair
342 */
343 public final String getChair() {
344 return fChair;
345 }
346
347 /***
348 * Sets the chair of a calendar entry.
349 *
350 * @param chair the chair
351 */
352 public final void setChair(final String chair) {
353 fChair = chair;
354 }
355
356 /***
357 * Returns the informed invitees of a calendar entry.
358 *
359 * @return chair the informed invitees
360 */
361 public final List getInformedInvitees() {
362 return fInformedInvitees;
363 }
364
365 /***
366 * Sets the informed invitees of a calendar entry.
367 *
368 * @param informedInvitees the informed invitees
369 */
370 public final void setInformedInvitees(final List informedInvitees) {
371 fInformedInvitees = informedInvitees;
372 }
373
374 /***
375 * Returns the location of a calendar entry.
376 *
377 * @return chair the location
378 */
379 public final String getLocation() {
380 if (fLocation == null) {
381 return fRoom;
382 }
383 return fLocation;
384 }
385
386 /***
387 * Sets the location a calendar entry.
388 *
389 * @param location the location
390 */
391 public final void setLocation(final String location) {
392 fLocation = location;
393 }
394
395 /***
396 * Returns the optional invitees of a calendar entry.
397 *
398 * @return chair the optional invitees
399 */
400 public final List getOptionalInvitees() {
401 return fOptionalInvitees;
402 }
403
404 /***
405 * Sets the optional invitees of a calendar entry.
406 *
407 * @param optionalInvitees the optional invitees
408 */
409 public final void setOptionalInvitees(final List optionalInvitees) {
410 fOptionalInvitees = optionalInvitees;
411 }
412
413 /***
414 * Returns the required invitees of a calendar entry.
415 *
416 * @return chair the required invitees
417 */
418 public final List getRequiredInvitees() {
419 return fRequiredInvitees;
420 }
421
422 /***
423 * Sets the required invitees of a calendar entry.
424 *
425 * @param requiredInvitees the required invitees
426 */
427 public final void setRequiredInvitees(final List requiredInvitees) {
428 fRequiredInvitees = requiredInvitees;
429 }
430
431 /***
432 * Returns the resources of a calendar entry.
433 *
434 * @return chair the resources
435 */
436 public final List getResources() {
437 return fResources;
438 }
439
440 /***
441 * Sets the resources of a calendar entry.
442 *
443 * @param resources the resources
444 */
445 public final void setResources(final List resources) {
446 fResources = resources;
447 }
448
449 /***
450 * Returns the rooms of a calendar entry.
451 *
452 * @return chair the rooms
453 */
454 public final List getRooms() {
455 return fRooms;
456 }
457
458 /***
459 * Sets the rooms of a calendar entry.
460 *
461 * @param rooms the rooms
462 */
463 public final void setRooms(final List rooms) {
464 fRooms = rooms;
465 }
466
467 /***
468 *
469 * @return room
470 */
471 public final String getRoom() {
472 if (fRoom == null) {
473 return fLocation;
474 }
475 return fRoom;
476 }
477
478 /***
479 *
480 * @param room room to set.
481 */
482 public final void setRoom(final String room) {
483 fRoom = room;
484 }
485
486 /***
487 * Checks if attachments should be sent.
488 *
489 * @return <code>true</code> if attachments should be sent else <code>false</code>
490 */
491 public final boolean isSendAttachments() {
492 return fSendAttachments;
493 }
494
495 /***
496 * Sets if attachments should be sent.
497 *
498 * @param sendAttachments <code>true</code> if attachments should be sent else <code>false</code>
499 */
500 public final void setSendAttachments(final boolean sendAttachments) {
501 fSendAttachments = sendAttachments;
502 }
503
504 /***
505 * Returns the type of a calendar entry.
506 *
507 * @return type of calendar entry
508 */
509 public final Type getType() {
510 return fType;
511 }
512
513 /***
514 * Sets the type of a calendar entry.
515 *
516 * @param type of type
517 */
518 public final void setType(final Type type) {
519 fType = type;
520 }
521
522 /***
523 * Returns the title of a calendar entry.
524 *
525 * @return title of calendar entry
526 */
527 public final String getTitle() {
528 return fTitle;
529 }
530
531 /***
532 * Returns the categories of a calendar entry.
533 *
534 * @return list of categories of calendar entry
535 */
536 public final List getCategories() {
537 return fCategories;
538 }
539
540 /***
541 * Adds a category to a calendar entry.
542 *
543 * @param category the category
544 */
545 public final void addCategory(final String category) {
546 fCategories.add(category);
547 }
548
549 /***
550 * Adds categories to a calendar entry.
551 *
552 * @param categories the categories
553 */
554 public final void addCategories(final Collection categories) {
555 fCategories.addAll(categories);
556 }
557
558 /***
559 * Sets the categories of a calendar entry.
560 *
561 * @param categories the categories
562 */
563 public final void setCategories(final List categories) {
564 fCategories = categories;
565 }
566
567 /***
568 * Returns the list of occurences for a repeating event.
569 *
570 * @return list of start/end times for a repeating event.
571 */
572 public final List getStartDateTime() {
573 return fStartDateTime;
574 }
575
576 /***
577 * Set list of occurences for repeating event.
578 *
579 * @param startDateTime list of occurences.
580 */
581 public final void setStartDateTime(final List startDateTime) {
582 fStartDateTime = startDateTime;
583 }
584
585 /***
586 * Returns the Appointment UNID of the calendar document.
587 * @return Appointment UNID
588 */
589 public final String getAppointmentUnid() {
590 return fAppointmentUnid;
591
592 }
593
594 /***
595 * @param appointmentUnid the appointmentUnid to set
596 */
597 public final void setAppointmentUnid(final String appointmentUnid) {
598 fAppointmentUnid = appointmentUnid;
599 }
600
601 /***
602 * @return a string representation of the object.
603 * @see java.lang.Object#toString()
604 */
605 public final String toString() {
606 return fChair + " " + fTitle + " " + fLocation + " Start: " + DateUtil.getDateString(fStartDate) + " " + DateUtil.getTimeString(fStartTime);
607 }
608 }