001: // Copyright %G% Sun Microsystems, Inc. All Rights Reserved.
002: // "%W% %E% Sun Microsystems"
003:
004: package com.sun.portal.wireless.taglibs.cal.socs;
005:
006: import javax.servlet.jsp.*;
007: import javax.servlet.jsp.tagext.*;
008:
009: import com.sun.comclient.calendar.*;
010: import com.sun.portal.wireless.taglibs.base.Util;
011: import com.sun.portal.wireless.taglibs.cal.*;
012: import com.sun.portal.log.common.PortalLogger;
013:
014: import java.util.logging.Logger;
015: import java.util.logging.Level;
016: import java.util.logging.LogRecord;
017:
018: /**
019: * OpenCalTag - execute a openCalendar operation on a CalStore
020: * By this the user can open his own or other calendars
021: * Attributes:
022: * field
023: * the String calId
024: */
025:
026: public class OpenCalTag extends CalCommandTag {
027:
028: // Create a logger for this class
029: private static Logger debugLogger = PortalLogger
030: .getLogger(OpenCalTag.class);
031:
032: private String calId;
033:
034: /**
035: * the default constructor
036: */
037: public OpenCalTag() {
038: super ();
039: }
040:
041: /**
042: * Set the calId attribute
043: * @param newCalId
044: */
045: public void setCalId(String newCalId) {
046: this .calId = newCalId;
047: }
048:
049: /**
050: * Get the calId attribute value as an Integer
051: * @return null if calId is not set
052: */
053: public String getCalId() {
054: return calId;
055: }
056:
057: /**
058: * Execute the openCalendar of the String
059: * If the user does not permission (ACL), fetch throws an exception
060: * hence try to fetch, if it fails than rolls back
061: * @return true , false if permisson denied by ACL
062: * @exception JspException
063: */
064: public boolean execute() throws JspException {
065:
066: CalContext calContext = getContext();
067: if (calId == null) {
068: throw new JspException("OpenCalTag: no calId specified");
069: }
070: String oldCalId = calContext.getCalendarID();
071: calContext.setCalendar(calId);
072: ICalendar newCal = calContext.getCalendar();
073:
074: //TBD: check for the ACL, replace this if there is any better way
075: try {
076: newCal.fetchComponents(new DateTime(calContext
077: .getTimeZone()), ICalendar.VEVENT);
078: } catch (CalendarException ex) {
079: //rollback the operation
080: //// CAL_002=Permission Denied for this Calendar
081: getContext().setErrorCode("CAL_002");
082: if (debugLogger.isLoggable(Level.FINE)) {
083: LogRecord logRecord = new LogRecord(Level.FINE,
084: "PSMA_CSPWTCS0003");
085: logRecord.setParameters(new Object[] { calId });
086: logRecord.setThrown(ex);
087: logRecord.setLoggerName(debugLogger.getName());
088: debugLogger.log(logRecord);
089: }
090: calContext.setCalendar(oldCalId);
091: return false;
092: }
093: return true;
094: }
095:
096: /**
097: * Cleanup
098: */
099: public void release() {
100: calId = null;
101: super.release();
102: }
103: }
|