001: /**
002: * $Id: SOCSTaskBean.java,v 1.12 2005/09/21 10:51:35 dg154973 Exp $
003: * Copyright 2003 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.wireless.taglibs.cal.socs;
014:
015: import com.sun.portal.wireless.taglibs.base.*;
016: import com.sun.comclient.calendar.*;
017: import com.sun.comclient.calendar.socs.*;
018: import com.sun.portal.wireless.taglibs.cal.*;
019: import com.sun.portal.log.common.PortalLogger;
020:
021: import java.util.*;
022: import java.util.logging.Logger;
023: import java.util.logging.Level;
024:
025: public class SOCSTaskBean extends TaskBean {
026:
027: private SOCSTodo theTask;
028: private String modifier;
029: private ReminderBean firstRemBean;
030:
031: // Create a logger for this class
032: private static Logger debugLogger = PortalLogger
033: .getLogger(SOCSTaskBean.class);
034:
035: /**
036: * Creates a taglib SOCSTaskBean from JCAPI SOCSTask
037: */
038: public SOCSTaskBean(SOCSTodo task) {
039: super (task);
040: this .theTask = task;
041: }
042:
043: /**
044: * Gets the JCAPI VTodo object from SOCSTaskBean
045: * <br><br>
046: * @return JCAPI task object
047: */
048:
049: public VTodo getTask() {
050: return theTask;
051: }
052:
053: /**
054: * Returns true if the todo is recurrent
055: * <br><br>
056: * @return true if the todo is recurrent
057: * @throws Exception indicating error in processing
058: */
059:
060: public boolean isRecurrence() throws Exception {
061: return theTask.isRecurring();
062: }
063:
064: /**
065: * Returns the recurrence pattern of this todo
066: * <br><br>
067: * @return first recurrence pattern object, null if does not exist
068: * @throws Exception indicating error in processing
069: */
070:
071: public RecurrencePattern getRecurrencePattern() throws Exception {
072:
073: if ((theTask.getRecurrenceRules() != null)
074: && (theTask.getRecurrenceRules().length > 0)) {
075: return theTask.getRecurrenceRules()[0];
076: }
077: return null;
078: }
079:
080: /**
081: * Sets the recurrence pattern for this todo
082: * NOTE: Currently setting only one recurrence pattern is supported
083: * <br><br>
084: * @param rPattern recurrence pattern for this todo
085: * @throws Exception indicating error in processing
086: */
087:
088: public void setRecurrencePattern(RecurrencePattern rPattern)
089: throws Exception {
090: RecurrencePattern[] rules = theTask.getRecurrenceRules();
091: if (rules != null && rules.length > 0) {
092: theTask.removeAllRecurrenceRules();
093: }
094: theTask.addRecurrenceRule(rPattern);
095: }
096:
097: /**
098: * Sets the location for a todo
099: * <br><br>
100: * @param String location to be set
101: * @throws Exception indicating error in processing
102: */
103: public void setLocation(String loc) throws Exception {
104: theTask.setLocation(loc);
105: }
106:
107: /**
108: * Returns location of a todo
109: * <br><br>
110: * @return String location of the todo
111: * @throws Exception indicating error in processing
112: */
113: public String getLocation() throws Exception {
114: return theTask.getLocation();
115: }
116:
117: /**
118: * Returns the status of the todo
119: * <br><br>
120: * @return status of this todo
121: * @throws Exception indicating error in processing
122: */
123:
124: public String getStatus() throws Exception {
125: return theTask.getStatus();
126: }
127:
128: /**
129: * Sets the status of this todo
130: * <br><br>
131: * @param String status of this todo
132: * @see com.sun.comclient.calendar.socs.SOCSTodo
133: */
134:
135: public void setStatus(String status) {
136: try {
137: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0011", status);
138:
139: if ((status.equalsIgnoreCase(SOCSTodo.STATUS_NEEDS_ACTION))
140: || (status
141: .equalsIgnoreCase(SOCSTodo.STATUS_IN_PROCESS))
142: || (status
143: .equalsIgnoreCase(SOCSTodo.STATUS_COMPLETED))
144: || (status
145: .equalsIgnoreCase(SOCSTodo.STATUS_CANCELLED))) {
146: //Also set the percent to 100 if task is completed
147: if (status.equalsIgnoreCase(SOCSTodo.STATUS_COMPLETED)) {
148: theTask.setStatus(status);
149: theTask.setPercent(100);
150: } else {
151: theTask.setStatus(SOCSTodo.STATUS_IN_PROCESS);
152: theTask.setPercent(0);
153: }
154: }
155:
156: } catch (Exception ex) {
157: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0007", ex);
158: }
159: }
160:
161: /**
162: * Returns the Recurrence Modifier of this todo
163: * <br><br>
164: * @return String Recurrence Modifier
165: */
166: public String getRecurrenceModifier() {
167: return modifier;
168: }
169:
170: /**
171: * Returns the modifier of this todo
172: * <br><br>
173: * @return String modifier
174: */
175:
176: public String getModifier() {
177: return getRecurrenceModifier();
178: }
179:
180: /**
181: * Sets the Recurrence Modifier of this todo
182: * <br><br>
183: * @param String Recurrence Modifier
184: */
185:
186: public void setRecurrenceModifier(String mod) {
187: modifier = mod;
188: }
189:
190: /**
191: * Sets the modifier of this todo
192: * <br><br>
193: * @param String modifier
194: */
195:
196: public void setModifier(String mod) {
197: setRecurrenceModifier(mod);
198: }
199:
200: /**
201: * Adds the attendees to the SchedulingComponent for group invite
202: * <br><br>
203: * @param string containing calendarid(s) seperated by comma
204: * @throws Exception indicating error in processing
205: */
206:
207: public void setAttendees(String attListCalIds) throws Exception {
208: StringTokenizer strTok = new StringTokenizer(attListCalIds,
209: ",;");
210: while (strTok.hasMoreTokens()) {
211: String token = strTok.nextToken().trim();
212: if (!token.equals("")) {
213: Attendee att = new Attendee(Attendee.INDIVIDUAL,
214: Attendee.REQ_PARTICIPANT, token);
215: att.setRSVPRequired(true);
216: component.addAttendee(att);
217: }
218: }
219: }
220:
221: /**
222: * Returns the list of attendees as a comma seperated string
223: * <br><br>
224: * @return String containing attendees list
225: * @throws Exception in case of error
226: */
227: public String getAttendees() throws Exception {
228: if (component.getAttendees() != null) {
229: Attendee[] attArr = component.getAttendees();
230: StringBuffer result = new StringBuffer();
231: for (int i = 0; i < attArr.length; i++) {
232: Attendee att = attArr[i];
233: result.append(att.getValue());
234: if (i != attArr.length) {
235: result.append(",");
236: }
237: }
238: return result.toString();
239: }
240: return new String();
241: }
242:
243: /** Checks presence of any attendees
244: * <br><br>
245: * @return true if number of attendees is zero
246: * @throws Exception in case of error
247: */
248: public boolean isAttendeesEmpty() {
249: boolean result = true;
250: try {
251: result = (!component.hasAttendee());
252: } catch (Exception ex) {
253: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0007", ex);
254: }
255: return result;
256: }
257:
258: /**
259: * Returns a collection iterator object containing all
260: * attendee objects
261: * <br><br>
262: * @return CollectionIterator containing attendee objects
263: * @throws Exception in case of error
264: */
265:
266: public CollectionIterator getAttendeesIterator() throws Exception {
267: Collection result = new Vector();
268: Attendee[] attArr = component.getAttendees();
269: if (attArr != null) {
270: for (int i = 0; i < attArr.length; i++) {
271: Attendee att = attArr[i];
272: if (att != null) {
273: result.add(new CalIdBean(att.getValue()));
274: }
275: }
276: }
277: return new CollectionIterator(result);
278: }
279:
280: /**
281: * Removes parameter string attendee from the list of attendees
282: * <br><br>
283: * @throws Exception in case of error
284: */
285: public void setRemovedAttendee(String remove) throws Exception {
286: StringTokenizer strTok = new StringTokenizer(remove, ",;");
287: while (strTok.hasMoreTokens()) {
288: String token = strTok.nextToken().trim();
289: if (!token.equals("")) {
290: Attendee[] attArr = component.getAttendees();
291: if (attArr != null) {
292: for (int i = 0; i < attArr.length; i++) {
293: if (attArr[i].getValue().equals(token)) {
294: component.removeAttendee(attArr[i]);
295: }
296: }
297: }
298: }
299: }
300: }
301:
302: /**
303: * Returns the first reminder/alarm
304: * <br><br>
305: * @return VAlarm the first reminder
306: * @throws Exception in case of error
307: */
308:
309: public VAlarm getFirstAlarm() throws Exception {
310: VAlarm firstAlarm = null;
311: VAlarm[] alarms = theTask.getAlarmComponents();
312: if ((alarms != null) && (alarms.length > 0)) {
313: firstAlarm = alarms[0];
314: } else {
315: firstAlarm = theTask.createAlarm();
316: theTask.addAlarmComponent(firstAlarm);
317: }
318: if (firstAlarm == null) {
319: debugLogger.info("PSMA_CSPWTCS0012");
320: }
321: return firstAlarm;
322: }
323:
324: /**
325: * Returns a ReminderBean instance associated with the todo
326: * <br><br>
327: * @return ReminderBean instance for this todo
328: * @throws Exception in case of processing error
329: */
330:
331: public ReminderBean getReminderBean() throws Exception {
332: if (firstRemBean == null) {
333: try {
334: firstRemBean = toReminderBean(getFirstAlarm());
335: } catch (Exception ex) {
336: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0013", ex);
337: throw ex;
338: }
339: }
340: return firstRemBean;
341: }
342:
343: protected ReminderBean toReminderBean(VAlarm alarm) {
344: return new EmailReminderBean(alarm);
345: }
346:
347: /**
348: * Checks if the todo is an all day todo
349: * <br><br>
350: * @return true if the task is an all day todo
351: */
352: public boolean isAllDay() throws Exception {
353: return theTask.isAllDay();
354: }
355:
356: /**
357: * Set this todo as all day
358: * <br><br>
359: * @param boolean allday indicating an All Day todo
360: */
361:
362: public void setAllDay(boolean allday) throws Exception {
363: if (allday) {
364: theTask.setAllDay(true);
365: } else {
366: theTask.setAllDay(false);
367: }
368: }
369:
370: /**
371: * Checks if the task has a due date
372: * <br><br>
373: * @return true if the todo has a due date
374: */
375: public boolean isDue() {
376: return theTask.hasProperty(SOCSTodo.DUE);
377: }
378:
379: /**
380: * Set this todo with no due date
381: * <br><br>
382: * @param boolean flag when false sets duedate to false
383: */
384:
385: public void setDue(boolean flag) {
386: if (!flag) {
387: theTask.removeProperty(SOCSTodo.DUE);
388: }
389: }
390:
391: /**
392: * Returns the completion status of the todo
393: * <br><br>
394: * @return true if the todo status is complete
395: */
396:
397: public boolean isCompleted() {
398: try {
399: if (theTask.isCompleted()) {
400: return true;
401: } else {
402: return false;
403: }
404: } catch (Exception e) {
405: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0014", e);
406: return false;
407: }
408: }
409:
410: }
|