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.http.*;
007: import javax.servlet.jsp.*;
008: import javax.servlet.jsp.tagext.*;
009:
010: import com.sun.portal.wireless.taglibs.base.Util;
011: import com.sun.portal.wireless.taglibs.base.Context;
012: import com.sun.portal.wireless.taglibs.cal.*;
013: import com.sun.portal.log.common.PortalLogger;
014:
015: import com.sun.comclient.calendar.CalendarStore;
016: import com.sun.comclient.calendar.VEvent;
017: import com.sun.comclient.calendar.VTodo;
018: import com.sun.comclient.calendar.CalendarStoreException;
019: import com.sun.comclient.calendar.CalendarException;
020: import com.sun.comclient.calendar.OperationNotSupportedException;
021:
022: import com.sun.comclient.calendar.socs.*;
023:
024: import com.sun.comclient.calendar.ICalendar;
025:
026: import java.util.logging.Logger;
027: import java.util.logging.Level;
028:
029: /**
030: * SOCSContext - This Context adds SOCS specfic features to CalContext
031: * This SOCSContext uses the same ContextCache,ContextType as CalContext.
032: * Hence this instance replaces the CalContext but hold the CalContext as parentContext.
033: * It delegates all the calls to this parentcontext and exposes the SOCS features only.
034: *
035: * @version 1.0
036: * @see com.sun.portal.wireless.taglibs.cal.Context
037: */
038:
039: public class SOCSContext extends CalContextHolder {
040:
041: public static final String CONTEXT_CLASS_NAME = "com.sun.portal.wireless.taglibs.cal.socs.SOCSContext";
042:
043: // Create a logger for this class
044: private static Logger debugLogger = PortalLogger
045: .getLogger(SOCSContext.class);
046:
047: /**
048: * the default constructor
049: */
050: public SOCSContext() {
051: super ();
052: }
053:
054: /**
055: * Returns a SOCSContext for this session.
056: * @param pageContext
057: * @exception Exception
058: */
059: public static CalContext getContext(PageContext pageContext)
060: throws Exception {
061: return (SOCSContext) Context.getContext(pageContext,
062: CONTEXT_CLASS_NAME, CONTEXT_CACHE_CLASS_NAME,
063: CONTEXT_TYPE);
064: }
065:
066: //SOCS Specfic fetaures Follows
067: private String[] calIds = new String[0]; //list of calids , could be subscribed calids or searchresults depends on Fetch
068:
069: /**
070: * Set the user's subscribed Calendars as t
071: *
072: */
073: public void setCalIds(String[] subCals) {
074: calIds = subCals;
075: }
076:
077: /**
078: * gets the user's subscribed Calendars
079: *
080: * @return the list of subscribed calendars
081: */
082: public String[] getCalIds() {
083: return calIds;
084: }
085:
086: /**
087: * Returns whether the calid list is empty or not
088: *
089: * @return true if the calid list is empty
090: * false otherwise
091: */
092: public boolean isCalIdsEmpty() {
093: return getCalIdsCount() == 0;
094: }
095:
096: /**
097: * Get the count of the current calId list
098: *
099: * @return the event list count
100: */
101: public int getCalIdsCount() {
102: return (calIds != null) ? calIds.length : 0;
103: }
104:
105: /**
106: * Get the Email addr of the user for Reminder from CalSession's property
107: * @return the email Addr.
108: */
109: public String getReminderEmail() {
110: CalendarStore calStore = getCalStore();
111: String defEmail = calStore.getSession().getProperty(
112: "ceDefaultAlarmEmail");
113: if ((defEmail == null) || (defEmail.equals(""))) {
114: if (calStore instanceof SOCSCalendarStore) {
115: try {
116: defEmail = (((SOCSCalendarStore) calStore)
117: .getSOCSSession()
118: .getPreference("ceDefaultAlarmEmail"));
119: if (defEmail == null) {
120: defEmail = (((SOCSCalendarStore) calStore)
121: .getSOCSSession().getPreference("mail"));
122: }
123: } catch (CalendarStoreException cs) {
124: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0007", cs);
125: }
126: } else {
127: defEmail = " ";
128: }
129: }
130: if (defEmail != null)
131: defEmail = defEmail.trim();
132: return (defEmail);
133: }
134:
135: /**
136: * Checks if user is the Owner of this calendar
137: * @return true if the user can modify it, false otherwise
138: */
139: public boolean isUserTheOwner() {
140: try {
141: return getCalendar().isUserTheOwner();
142: } catch (CalendarException ex) {
143: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0007", ex);
144: } catch (OperationNotSupportedException ex1) {
145: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0007", ex1);
146: }
147: return true;
148: }
149:
150: /**
151: * Checks if user has the modify permission for this calendar
152: * @return true if the user can modify it, false otherwise
153: */
154: public boolean isWritePermGranted() {
155: try {
156: String uid = getSessionProperty(CalendarACL.CAL_USER);
157: ICalendar ical = getCalendar();
158: CalendarACL calendarACL = new CalendarACL(ical);
159: return calendarACL.checkPermission(uid,
160: CalendarACL.CAL_COMPONENTS,
161: CalendarACL.CAL_WRITE_PERMISSION);
162: } catch (CalendarException ex) {
163: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0007", ex);
164: } catch (OperationNotSupportedException ex) {
165: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0007", ex);
166: }
167: return false;
168: }
169:
170: /**
171: * Checks if user has the delete permission for this calendar
172: * @return true if the user can delete it, false otherwise
173: */
174: public boolean isDeletePermGranted() {
175: try {
176: String uid = getSessionProperty(CalendarACL.CAL_USER);
177: ICalendar ical = getCalendar();
178: CalendarACL calendarACL = new CalendarACL(ical);
179: return calendarACL.checkPermission(uid,
180: CalendarACL.CAL_COMPONENTS,
181: CalendarACL.CAL_DELETE_PERMISSION);
182: } catch (CalendarException ex) {
183: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0007", ex);
184: } catch (OperationNotSupportedException ex) {
185: debugLogger.log(Level.INFO, "PSMA_CSPWTCS0007", ex);
186: }
187: return false;
188: }
189:
190: /**
191: * Get the SubComponent Specific EventBean
192: * @return an instance of SOCSEventBean
193: */
194: public EventBean toEventBean(VEvent event) {
195: if (event instanceof SOCSEvent) {
196: EventBean eb = new SOCSEventBean((SOCSEvent) event);
197: return eb;
198: }
199: return null;
200: }
201:
202: /**
203: * Get the SubComponent Specific TaskBean
204: * @return an instance of SOCSTaskBean
205: */
206: public TaskBean toTaskBean(VTodo task) {
207: if (task instanceof SOCSTodo) {
208: return new SOCSTaskBean((SOCSTodo) task);
209: }
210: return null;
211: }
212:
213: }
|