KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > uitags > tag > calendar > CalendarGridTag


1 package net.sf.uitags.tag.calendar;
2
3 import javax.servlet.jsp.JspException JavaDoc;
4 import javax.servlet.jsp.PageContext JavaDoc;
5
6 import net.sf.uitags.tag.AbstractUiTag;
7 import net.sf.uitags.tagutil.AttributeSupport;
8 import net.sf.uitags.tagutil.AttributeSupportHelper;
9 import net.sf.uitags.tagutil.ScopedIdGenerator;
10 import net.sf.uitags.tagutil.TaglibProperties;
11 import net.sf.uitags.tagutil.i18n.MessageFinder;
12 import net.sf.uitags.tagutil.i18n.MessageFinderFactory;
13 import net.sf.uitags.util.ArrayUtils;
14
15 public class CalendarGridTag extends AbstractUiTag implements AttributeSupport {
16   ///////////////////////////////
17
////////// Constants //////////
18
///////////////////////////////
19

20   /**
21    * Serial Version UID.
22    */

23   private static final long serialVersionUID = 100L;
24   /**
25    * Key of the scoped attribute that stores auto-incremented ID for
26    * instances of this tag handler.
27    */

28   private static final String JavaDoc TAG_INSTANCE_ID_KEY =
29       "net.sf.uitags.tag.calendar.CalendarGridTag.instanceId";
30
31
32   ///////////////////////////////////////////////
33
////////// Property keys (constants) //////////
34
///////////////////////////////////////////////
35

36   private static final String JavaDoc PROP_CSS_CLASS =
37       "calendar.calendarGrid.class";
38
39   private static final String JavaDoc PROP_DAY_LABELS =
40       "calendar.calendarGrid.dayLabels";
41
42   private static final String JavaDoc PROP_CLASS_RESOLVER =
43       "calendar.calendarGrid.classResolver";
44
45   private static final String JavaDoc PROP_ACTION_RESOLVER =
46       "calendar.calendarGrid.actionResolver";
47
48
49   ////////////////////////////
50
////////// Fields //////////
51
////////////////////////////
52

53   /**
54    * The 'class' tag attribute.
55    */

56   private String JavaDoc cssClass;
57   /**
58    * The 'dayLabels' tag attribute.
59    */

60   private String JavaDoc[] dayLabels;
61   /**
62    * The 'classResolver' tag attribute.
63    */

64   private String JavaDoc classResolver;
65   /**
66    * The 'actionResolver' tag attribute.
67    */

68   private String JavaDoc actionResolver;
69   /**
70    * Helper for tag that allows arbitrary HTML attributes.
71    */

72   private AttributeSupportHelper attributeHelper;
73
74
75   ///////////////////////////////////////////
76
////////// Tag attribute setters //////////
77
///////////////////////////////////////////
78

79   public void setId(String JavaDoc val) {
80     super.setId(val);
81   }
82
83   public void setClass(String JavaDoc val) {
84     this.cssClass = val;
85   }
86
87   public void setDayLabels(String JavaDoc[] val) {
88     this.dayLabels = val;
89   }
90
91   public void setClassResolver(String JavaDoc val) {
92     this.classResolver = val;
93   }
94
95   public void setActionResolver(String JavaDoc val) {
96     this.actionResolver = val;
97   }
98
99
100   ///////////////////////////////
101
////////// Tag logic //////////
102
///////////////////////////////
103

104   public int doStartTag() throws JspException JavaDoc {
105     this.attributeHelper = new AttributeSupportHelper();
106
107     return EVAL_BODY_INCLUDE;
108   }
109
110   public int doEndTag() throws JspException JavaDoc {
111     CalendarTag parentCalendar = (CalendarTag) findParent(CalendarTag.class);
112     parentCalendar.setCalendarGrid(this);
113
114     // so that when the tag is reused the widget ID gets generated again
115
setId(null);
116
117     return EVAL_PAGE;
118   }
119
120   private String JavaDoc generateUniqueId() {
121     return "uiCalendar_calendarGrid" + ScopedIdGenerator.nextId(
122         PageContext.REQUEST_SCOPE, TAG_INSTANCE_ID_KEY, this.pageContext);
123   }
124
125   /** {@inheritDoc} */
126   public void addAttribute(String JavaDoc attrName, String JavaDoc attrValue) {
127     this.attributeHelper.addAttribute(attrName, attrValue);
128   }
129
130
131   //////////////////////////////////////////////////////////
132
////////// To be used by the parent CalendarTag //////////
133
//////////////////////////////////////////////////////////
134

135   /*
136    * This method is defined as public by the superclass so we can't narrow
137    * the visibility to package-private.
138    */

139   public String JavaDoc getId() {
140     if (super.getId() == null) {
141       super.setId(generateUniqueId());
142     }
143     return super.getId();
144   }
145
146   String JavaDoc getCssClass() {
147     TaglibProperties props = TaglibProperties.getInstance();
148     props.setRuntimeProperty(PROP_CSS_CLASS, this.cssClass);
149
150     return props.get(PROP_CSS_CLASS);
151   }
152
153   String JavaDoc[] getDayLabels() {
154     if (this.dayLabels == null) {
155       TaglibProperties props = TaglibProperties.getInstance();
156       MessageFinder messageFinder =
157           MessageFinderFactory.getInstance(this.pageContext);
158       this.dayLabels =
159           ArrayUtils.toArray(messageFinder.get(props.get(PROP_DAY_LABELS)));
160     }
161
162     return this.dayLabels;
163   }
164
165   String JavaDoc getClassResolver() {
166     TaglibProperties props = TaglibProperties.getInstance();
167     props.setRuntimeProperty(PROP_CLASS_RESOLVER, this.classResolver);
168
169     return props.get(PROP_CLASS_RESOLVER);
170   }
171
172   String JavaDoc getActionResolver() {
173     TaglibProperties props = TaglibProperties.getInstance();
174     props.setRuntimeProperty(PROP_ACTION_RESOLVER, this.actionResolver);
175
176     return props.get(PROP_ACTION_RESOLVER);
177   }
178
179   String JavaDoc getCustomHtmlAttributes() {
180     return this.attributeHelper.eval();
181   }
182 }
183
Popular Tags