001: /**
002: * $Id: TaskTag.java,v 1.7 2003/08/26 22:24:03 amlan Exp $
003: * Copyright 2003 Sun Microsystems, Inc. All
004: * rights reserved. Use of this product is subject
005: * to license terms. Federal Acquisitions:
006: * Commercial Software -- Government Users
007: * Subject to Standard License Terms and
008: * Conditions.
009: *
010: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011: * are trademarks or registered trademarks of Sun Microsystems,
012: * Inc. in the United States and other countries.
013: */package com.sun.portal.wireless.taglibs.cal;
014:
015: import javax.servlet.jsp.*;
016: import javax.servlet.jsp.tagext.*;
017: import com.sun.comclient.calendar.VTodo;
018: import com.sun.portal.wireless.taglibs.base.BeanTag;
019:
020: /**
021: * TaskTag - tag that represents an ical Task bean
022: * @version 6.0
023: * @since 1.0
024: * @see com.sun.comclient.calendar.VTodo
025: */
026:
027: public class TaskTag extends BeanTag {
028:
029: /**
030: * The index attribute; specifies which Task to
031: * use from the context's current task list.
032: */
033: private Integer index;
034:
035: /**
036: * the default constructor
037: */
038: public TaskTag() {
039: super ();
040: }
041:
042: /**
043: * Set the index into the context task list
044: * @param index index of Task to use
045: */
046:
047: public void setIndex(String index) {
048: try {
049: this .index = new Integer(evalAttribute(index));
050: } catch (NumberFormatException e) {
051: index = null;
052: }
053: }
054:
055: /**
056: * Create a new Task bean object
057: * @return the Task object
058: */
059:
060: public Object newBean() throws Exception {
061: CalContext calcontext;
062: TaskBean task;
063:
064: calcontext = CalContext.getContext(pageContext);
065: if (calcontext == null) {
066: throw new Exception(
067: "TaskTag.newBean(): No CalContext found");
068: }
069:
070: VTodo todoInst = calcontext.getCalendar().createTodo();
071: //now create the new task bean
072: task = calcontext.toTaskBean(todoInst);
073:
074: if (task == null) {
075: throw new Exception(
076: "TaskTag.newBean(): Failed to create new Task");
077: }
078:
079: return task;
080: }
081:
082: /**
083: * Find the task bean. If the index attribute is
084: * specified then retrieve the task from the
085: * context's current task collection. Otherwise
086: * use the default BeanTag behavior.
087: *
088: * @return the Task object that TaskTag represents
089: */
090:
091: public Object findBean() throws Exception {
092:
093: if (index == null) {
094: return super .findBean();
095: }
096:
097: TaskBean task;
098:
099: CalContext calcontext = CalContext.getContext(pageContext);
100: if (calcontext == null) {
101: throw new Exception(
102: "TaskTag.findBean(): No CalContext found");
103: }
104:
105: int indexval = index.intValue();
106: if (indexval < 0) {
107: throw new Exception(
108: "TaskTag.findBean(): Index out of range");
109: }
110:
111: task = calcontext.getTask(indexval);
112: if (task == null) {
113: throw new Exception("TaskTag.findBean(): No Task found");
114: }
115: if (id != null) {
116: pageContext.setAttribute(id, task);
117: }
118:
119: return task;
120: }
121:
122: /**
123: * Cleanup
124: */
125: public void release() {
126: super.release();
127: index = null;
128: }
129: }
|