001: package com.sun.portal.wireless.taglibs.cal.socs;
002:
003: import com.sun.portal.wireless.taglibs.base.Util;
004: import com.sun.portal.log.common.PortalLogger;
005: import com.sun.comclient.calendar.*;
006:
007: import java.util.logging.Logger;
008: import java.util.logging.Level;
009:
010: /**
011: * This exposes only the Email aspect of Reminder by extending ReminderBean
012: */
013:
014: public class EmailReminderBean extends ReminderBean {
015:
016: // Create a logger for this class
017: private static Logger debugLogger = PortalLogger
018: .getLogger(EmailReminderBean.class);
019:
020: private VAlarm alarm = null;
021:
022: /**
023: * This reminderBean does not have a default constructor
024: * Takes an alarm object ,
025: * which might have been created by event/task.createAlarm
026: * @param theAlarm object
027: */
028: public EmailReminderBean(VAlarm aAlarm) {
029: super (aAlarm);
030: this .alarm = aAlarm;
031: }
032:
033: /**
034: * Gets this object as String
035: * @return the String form of the object
036: **/
037: public String getString() {
038: return toString();
039: }
040:
041: /**
042: * Gets this object as String
043: * @return the String form of the object
044: **/
045: public String toString() {
046: return super .toString() + ":" + getEmailAttendee();
047: }
048:
049: /**
050: * Sets the Emails of attendees to the alarm
051: * It does not add the new attendees to the existing list ,
052: * but replaces the old list of attendees by the new list
053: * @param String list containing attendee email addresses
054: */
055: public void setEmailAttendee(String addrListSt) {
056: try {
057: //Remove all the attendee from alarm
058: Attendee[] attendees = alarm.getAttendees();
059: if (attendees != null && attendees.length > 0) {
060: for (int i = 0; i < attendees.length; i++) {
061: alarm.removeAttendee(attendees[i]);
062: }
063: }
064: if (addrListSt.indexOf("MAILTO") == -1) {
065: addrListSt = "MAILTO:" + addrListSt;
066: }
067: Attendee att = new Attendee(Attendee.INDIVIDUAL, addrListSt);
068: alarm.addAttendee(att);
069: alarm.setAction("EMAIL");
070: } catch (Exception ex) {
071: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0001", ex);
072: }
073: }
074:
075: /**
076: * verifies if the attendee list is Empty
077: * @return true if it is null or "" else false
078: */
079: public boolean isEmailAttendeeEmpty() {
080: String email = getEmailAttendee();
081: if (email == null || email.trim().equals("")) {
082: return true;
083: }
084: return false;
085: }
086:
087: /** <P> Gets the Email Address to prefill the
088: * change attendee's address field in reminder
089: * BEAWARE: it sepeartes the attendees by commas
090: * In our case we are dealing with one attendee with one or more emails
091: * like Mailto:a@sun.com,b@iplanet.com
092: * removes the "MAILTO:" if exist </P>
093: * @return String Email Address of the attendee
094: */
095: public String getEmailAttendee() {
096: StringBuffer result = new StringBuffer();
097: String delimiter = ",";
098: Attendee[] addrList = alarm.getAttendees();
099: if (addrList != null) {
100: for (int i = 0; i < addrList.length; i++) {
101: String addr = (String) addrList[i].getValue();
102: debugLogger.log(Level.FINER, "PSMA_CSPWTCS0002", addr);
103: if (addr.length() >= 7) {
104: String tmp = addr.substring(0, 7);
105: if (tmp.equalsIgnoreCase("Mailto:")) {
106: addr = addr.substring(7);
107: }
108: }
109: result.append(addr);
110: if (i != (addrList.length - 1)) {
111: result.append(delimiter);
112: }
113: }
114: }
115: return result.toString();
116: }
117:
118: /**
119: * <p>A small text note that can be included in the reminder. Some
120: * calendar servers may not support this.</p>
121: *
122: * @param note free form text
123: */
124: public void setReminderNote(String note) throws Exception {
125: if (note == null) {
126: note = "";
127: }
128: alarm.setDescription(note);
129: }
130:
131: /**
132: * <p>Returns any text the user may have entered to be included with the
133: * reminder.</p>
134: *
135: * @return free form textual notes
136: */
137: public String getReminderNote() {
138: return alarm.getDescription();
139: }
140: }
|