01: // Copyright %G% Sun Microsystems, Inc. All Rights Reserved.
02: // "%W% %E% Sun Microsystems"
03:
04: package com.sun.portal.wireless.taglibs.cal.socs;
05:
06: import javax.servlet.jsp.*;
07: import javax.servlet.jsp.tagext.*;
08:
09: import com.sun.portal.wireless.taglibs.base.BeanTag;
10: import com.sun.portal.wireless.taglibs.cal.*;
11:
12: /**
13: * CalIdTag - tag that represents an ical CalId bean
14: * @see CalIdBean
15: */
16:
17: public class CalIdTag extends BeanTag {
18:
19: /**
20: * The index attribute; specifies which CalId to
21: * use from the context's current calId list.
22: */
23: private Integer index;
24:
25: /**
26: * the default constructor
27: */
28: public CalIdTag() {
29: super ();
30: }
31:
32: /**
33: * Set the index into the context calId list
34: *
35: * @param index index of CalId to use
36: */
37: public void setIndex(String index) {
38: try {
39: this .index = new Integer(evalAttribute(index));
40: } catch (NumberFormatException e) {
41: index = null;
42: }
43: }
44:
45: /**
46: * Create a new CalId bean object
47: *
48: * @return the CalId object
49: */
50: public Object newBean() throws Exception {
51: return new CalIdBean();
52: }
53:
54: /**
55: * Find the calId bean. If the index attribute is
56: * specified then retrieve the calId from the
57: * context's current calId collection. Otherwise
58: * use the default BeanTag behavior.
59: *
60: * @return the CalId this tag represents
61: */
62: public Object findBean() throws Exception {
63:
64: if (index == null) {
65: return super .findBean();
66: }
67:
68: SOCSContext calcontext;
69: CalIdBean calId;
70:
71: if ((calcontext = (SOCSContext) CalContext
72: .getContext(pageContext)) == null) {
73: throw new Exception("No CalContext found");
74: }
75:
76: int indexval = index.intValue();
77:
78: if (indexval < 0) {
79: throw new Exception("Index out of range");
80: }
81:
82: String[] calIds = calcontext.getCalIds();
83: calId = new CalIdBean(calIds[indexval]);
84:
85: if (calId == null) {
86: throw new Exception("No CalId found");
87: }
88:
89: return calId;
90: }
91:
92: /**
93: * Cleanup
94: */
95: public void release() {
96: super.release();
97: index = null;
98: }
99: }
|