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.comclient.calendar.socs.*;
011:
012: import com.sun.portal.wireless.taglibs.cal.*;
013:
014: /**
015: * FetchCalIdTag : It fetches the list of calIds
016: * Gets the list of subscribed calendarIds by default
017: * If search parameter is specified it searches and returns search result-
018: *
019: * */
020:
021: public class FetchCalIdTag extends CalCommandTag {
022:
023: private String searchString = null;
024: private boolean exact = false;
025:
026: /**
027: * the default constructor
028: */
029: public FetchCalIdTag() {
030: super ();
031: }
032:
033: /**
034: * Perform the fetch operation,
035: * if search is specified
036: * searches the calids which "contains" the searchstring
037: * return only 10 results
038: * @return true
039: * @exception JspException
040: */
041: public boolean execute() throws JspException {
042: SOCSContext context = (SOCSContext) getContext();
043: CalendarStore calStore = getCalStore();
044: String[] result = null;
045: if (searchString != null && (!searchString.trim().equals(""))) {
046: try {
047: // searches the calids which "contains" the searchstring
048: // return only 10 results
049: // WCAP only supports CONTAINS and BEGINS_WITH searches, so we cant use EXACT searches
050: // Instead, we implement an EXACT search by creating a (client-side) calendar with the
051: // given name, and try to fetch its properties from the server. This throws a CalendarException if
052: // the calender does not exist on the server.
053: if (exact) {
054: ICalendar cal = calStore.openCalendar(searchString);
055: try {
056: cal.getCalProps();
057: result = new String[1];
058: result[0] = cal.getCalID();
059: } catch (CalendarException e) {
060: result = null;
061: }
062: } else {
063: ICalendar[] calArr = calStore.searchCalendars(
064: searchString, SOCSCalendarStore.CONTAINS,
065: 10);
066: result = new String[calArr.length];
067: for (int i = 0; i < calArr.length; i++) {
068: result[i] = (calArr[i]).getCalID();
069: }
070: }
071: } catch (CalendarStoreException ex1) {
072: throw new JspException(ex1.getMessage());
073: } catch (OperationNotSupportedException ex2) {
074: throw new JspException(ex2.getMessage());
075: }
076:
077: } else {
078: try {
079: result = calStore.getSubscribedCalenders();
080: } catch (CalendarStoreException ex) {
081: throw new JspException(ex.getMessage());
082: } catch (OperationNotSupportedException ex1) {
083: throw new JspException(ex1.getMessage());
084: }
085: }
086: context.setCalIds(result);
087: return true;
088: }
089:
090: /**
091: * Sets the searchString, Optional parameter for this Tag
092: * searches the calids which "contains" the searchstring
093: * fetches only 10 results
094: * @param the string to be searched
095: */
096:
097: public void setSearch(String searchSt) {
098: this .searchString = searchSt;
099: }
100:
101: /**
102: * Sets the exact flag, optional parameter for this Tag
103: * controls whether an exact search is made
104: * @param exact boolean
105: */
106: public void setExact(String e) {
107: this .exact = "true".equalsIgnoreCase(e);
108: }
109:
110: public void release() {
111: exact = false;
112: super.release();
113: }
114: }
|