001: package com.sun.portal.wireless.taglibs.cal.socs;
002:
003: import com.sun.portal.wireless.taglibs.base.*;
004: import com.sun.comclient.calendar.*;
005: import com.sun.comclient.calendar.socs.*;
006: import com.sun.portal.wireless.taglibs.cal.*;
007: import com.sun.portal.log.common.PortalLogger;
008:
009: import java.util.*;
010: import java.util.logging.Logger;
011: import java.util.logging.Level;
012:
013: public class SOCSEventBean extends EventBean {
014:
015: private SOCSEvent theEvent;
016: private ReminderBean firstRemBean;
017:
018: // Create a logger for this class
019: private static Logger debugLogger = PortalLogger
020: .getLogger(SOCSEventBean.class);
021:
022: /**
023: * The constructor which creates a taglib SOCSEventBean out of JCAPI SOCSEvent
024: * @param a JCAPI SOCSEvent
025: */
026:
027: public SOCSEventBean(SOCSEvent event) {
028: super (event);
029: this .theEvent = event;
030: }
031:
032: /**
033: * Gets the JCAPI Event out of the taglib SOCSEventBean
034: * @return JCAPI event object
035: */
036:
037: public VEvent getEvent() {
038: return theEvent;
039: }
040:
041: /**
042: *verifies if the currentCalID is the Orgainzer of the Event
043: *@return true if calId and Orgainzer are the same, false otherwise
044: */
045: public boolean isCalIdTheOrganizer() throws Exception {
046: String calId = theEvent.getCalID();
047: if (!isNew()) {
048: return theEvent.isCalIdTheOrganizer(calId);
049: }
050: return true;
051: }
052:
053: /**
054: * Sets the RSVP response to the event
055: * @param the ParticipantStatus as String.
056: * @exception it throws exception for invalid values of participation status
057: */
058: public void setReply(String replyStatus) throws Exception {
059: Attendee att = getCalIdAsAttendee();
060: if (att != null) {
061: att.setParticipantStatus(replyStatus);
062: }
063: }
064:
065: private Attendee getCalIdAsAttendee() {
066: return theEvent.getAttendee(theEvent.getCalID());
067: }
068:
069: /**
070: * Gets the RSVP response of this user in the event
071: * @return the ParticipantStatus as String
072: */
073: public String getReply() throws Exception {
074: Attendee att = getCalIdAsAttendee();
075: if (att != null) {
076: return att.getParticipantStatus();
077: }
078: return "";
079: }
080:
081: /**
082: * Returns whether the component is part of a recurrence.
083: * <br><br>
084: *
085: * @return true if the component repeats
086: */
087: public boolean isRecurrence() throws Exception {
088: return theEvent.isRecurring();
089: }
090:
091: /**
092: * Set the Reminder Objcet
093: * <br><br>
094: * @param reminder
095: */
096: public void setReminderBean(ReminderBean remBean) throws Exception {
097: //remove and add the first one as we do not
098: //currently support multiple alarms
099: VAlarm[] alarms = theEvent.getAlarmComponents();
100: try {
101: if ((alarms != null) && (alarms.length > 0)) {
102: debugLogger.finer("PSMA_CSPWTCS0008");
103: theEvent.removeAlarmComponent(alarms[0]);
104: }
105: theEvent.addAlarmComponent(remBean.getAlarm());
106: } catch (Exception e) {
107: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0009", e);
108: }
109: }
110:
111: /**
112: * adds the attendees to the Component for group invite
113: * @param the string containing calendarids seperated by comma
114: * @exception throws exception
115: * TBD: for Aligo Adapter
116: */
117:
118: public void setAttendees(String attListCalIds) throws Exception {
119: StringTokenizer strTok = new StringTokenizer(attListCalIds,
120: ",;");
121: while (strTok.hasMoreTokens()) {
122: String token = strTok.nextToken().trim();
123: if (!token.equals("")) {
124: Attendee att = new Attendee(Attendee.INDIVIDUAL,
125: Attendee.REQ_PARTICIPANT, token);
126: att.setRSVPRequired(true);
127: component.addAttendee(att);
128: }
129: }
130: }
131:
132: /**
133: * Gets the list of attendees as a comma seperated string
134: * @retun the string form of attendees calids
135: */
136: public String getAttendees() throws Exception {
137: if (component.getAttendees() != null) {
138: Attendee[] attArr = component.getAttendees();
139: StringBuffer result = new StringBuffer();
140: for (int i = 0; i < attArr.length; i++) {
141: Attendee att = attArr[i];
142: result.append(att.getValue());
143: if (i != (attArr.length - 1)) {
144: result.append(",");
145: }
146: }
147: return result.toString();
148: }
149: return new String();
150: }
151:
152: /**
153: * Verifies if there are attendees
154: * @return true if any exist, false otherwise
155: */
156: public boolean isAttendeesEmpty() {
157: boolean result = true;
158: try {
159: result = (!component.hasAttendee());
160: } catch (Exception ex) {
161: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0010", ex);
162: }
163: return result;
164: }
165:
166: public CollectionIterator getAttendeesIterator() throws Exception {
167: Collection result = new Vector();
168: Attendee[] attArr = component.getAttendees();
169: if (attArr != null) {
170: for (int i = 0; i < attArr.length; i++) {
171: Attendee att = attArr[i];
172: if (att != null) {
173: result.add(new CalIdBean(att.getValue()));
174: }
175: }
176: }
177: return new CollectionIterator(result);
178: }
179:
180: public void setRemovedAttendee(String remove) throws Exception {
181: StringTokenizer strTok = new StringTokenizer(remove, ",;");
182: while (strTok.hasMoreTokens()) {
183: String token = strTok.nextToken().trim();
184: if (!token.equals("")) {
185: Attendee[] attArr = component.getAttendees();
186: if (attArr != null) {
187: for (int i = 0; i < attArr.length; i++) {
188: if (attArr[i].getValue().equals(token)) {
189: component.removeAttendee(attArr[i]);
190: }
191: }
192: }
193: }
194: }
195: }
196:
197: public VAlarm getFirstAlarm() throws Exception {
198: VAlarm firstAlarm = null;
199: VAlarm[] alarms = theEvent.getAlarmComponents();
200: if ((alarms != null) && (alarms.length > 0)) {
201: firstAlarm = alarms[0];
202: } else {
203: firstAlarm = theEvent.createAlarm();
204: theEvent.addAlarmComponent(firstAlarm);
205: }
206: if (firstAlarm == null) {
207: throw new Exception("No alrams set or able to create");
208: }
209: return firstAlarm;
210: }
211:
212: public ReminderBean getReminderBean() throws Exception {
213: if (firstRemBean == null) {
214: try {
215: firstRemBean = toReminderBean(getFirstAlarm());
216: } catch (Exception ex) {
217: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0007", ex);
218: throw ex;
219: }
220: }
221: return firstRemBean;
222: }
223:
224: protected ReminderBean toReminderBean(VAlarm alarm) {
225: return new EmailReminderBean(alarm);
226: }
227:
228: }
|