Source code: com/aendvari/tethys/tag/html/AbstractTag.java
1 /*
2 * AbstractTag.java
3 *
4 * Copyright (c) 2001, 2002 Aendvari, Ltd. All Rights Reserved.
5 *
6 * See the file LICENSE for terms of use.
7 *
8 */
9
10 package com.aendvari.tethys.tag.html;
11
12 import java.io.IOException;
13
14 import javax.servlet.http.*;
15 import javax.servlet.jsp.*;
16 import javax.servlet.jsp.tagext.*;
17
18 import com.aendvari.common.model.*;
19
20 import com.aendvari.tethys.context.*;
21 import com.aendvari.tethys.tag.*;
22 import com.aendvari.tethys.tag.model.*;
23
24
25 /**
26 * This is the base class for all the html tags in this package. You are required
27 * to implement the <code>doStartTag()</code> and <code>doEnTag()</code> methods in
28 * a subclass of your own. You cannot use this class directly.
29 *
30 * @author Scott Milne
31 *
32 */
33
34 public abstract class AbstractTag extends ModelTreeBodyTag
35 {
36 /* Other */
37
38 /** The <code>accesskey</code> HTML attribute. */
39 private String accessKey= null;
40
41 /** The <code>tabindex</code> HTML attribute. */
42 private String tabIndex = null;
43
44
45 /* Style */
46
47 /** The <code>style</code> HTML attribute. */
48 private String style = null;
49
50 /** The <code>class</code> HTML attribute. */
51 private String styleClass = null;
52
53
54 /* JavaScript */
55
56 /** The <code>onclick</code> JavaScript event. */
57 private String onClick = null;
58
59 /** The <code>ondblclick</code> JavaScript event. */
60 private String onDblClick = null;
61
62 /** The <code>onmouseover</code> JavaScript event. */
63 private String onMouseOver = null;
64
65 /** The <code>onmouseout</code> JavaScript event. */
66 private String onMouseOut = null;
67
68 /** The <code>onmousemove</code> JavaScript event. */
69 private String onMouseMove = null;
70
71 /** The <code>onmousedown</code> JavaScript event. */
72 private String onMouseDown = null;
73
74 /** The <code>onmouseup</code> JavaScript event. */
75 private String onMouseUp = null;
76
77 /** The <code>onkeydown</code> JavaScript event. */
78 private String onKeyDown = null;
79
80 /** The <code>onKeyup</code> JavaScript event. */
81 private String onKeyUp = null;
82
83 /** The <code>onkeypress</code> JavaScript event. */
84 private String onKeyPress = null;
85
86 /** The <code>onselect</code> JavaScript event. */
87 private String onSelect = null;
88
89 /** The <code>onchange</code> JavaScript event. */
90 private String onChange = null;
91
92 /** The <code>onblur</code> JavaScript event. */
93 private String onBlur = null;
94
95 /** The <code>onfocus</code> JavaScript event. */
96 private String onFocus = null;
97
98
99 /* Accessors */
100
101 public String getAccesskey() { return accessKey; }
102 public void setAccesskey(String param) { accessKey = param; }
103
104 public String getTabindex() { return tabIndex; }
105 public void setTabindex(String param) { tabIndex = param; }
106
107 public String getStyle() { return style; }
108 public void setStyle(String param) { style = param; }
109
110 public String getStyleClass() { return styleClass; }
111 public void setStyleClass(String param) { styleClass = param; }
112
113 public String getOnclick() { return onClick; }
114 public void setOnclick(String param) { onClick = param; }
115
116 public String getOndblclick() { return onDblClick; }
117 public void setOndblclick(String param) { onDblClick = param; }
118
119 public String getOnmousedown() { return onMouseDown; }
120 public void setOnmousedown(String param) { onMouseDown = param; }
121
122 public String getOnmouseup() { return onMouseUp; }
123 public void setOnmouseup(String param) { onMouseUp = param; }
124
125 public String getOnmousemove() { return onMouseMove; }
126 public void setOnmousemove(String param) { onMouseMove = param; }
127
128 public String getOnmouseover() { return onMouseOver; }
129 public void setOnmouseover(String param) { onMouseOver = param; }
130
131 public String getOnmouseout() { return onMouseOut; }
132 public void setOnmouseout(String param) { onMouseOut = param; }
133
134 public String getOnkeydown() { return onKeyDown; }
135 public void setOnkeydown(String param) { onKeyDown = param; }
136
137 public String getOnkeyup() { return onKeyUp; }
138 public void setOnkeyup(String param) { onKeyUp = param; }
139
140 public String getOnkeypress() { return onKeyPress; }
141 public void setOnkeypress(String param) { onKeyPress = param; }
142
143 public String getOnchange() { return onChange; }
144 public void setOnchange(String param) { onChange = param; }
145
146 public String getOnselect() { return onSelect; }
147 public void setOnselect(String param) { onSelect = param; }
148
149 public String getOnblur() { return onBlur; }
150 public void setOnblur(String param) { onBlur = param; }
151
152 public String getOnfocus() { return onFocus; }
153 public void setOnfocus(String param) { onFocus = param; }
154
155
156 /**
157 * Generates the HTML style attribute from the <code>style</code> and <code>styleClass</code> attribute.
158 *
159 * @return The generates String for the HTML <code>style</code> attribute.
160 *
161 */
162
163 protected String generateStyleAttribute()
164 {
165 StringBuffer styleAttribute = new StringBuffer();
166
167 if (style != null)
168 {
169 styleAttribute.append(" style=\"");
170 styleAttribute.append(style);
171 styleAttribute.append("\"");
172 }
173
174 if (styleClass != null)
175 {
176 styleAttribute.append(" class=\"");
177 styleAttribute.append(styleClass);
178 styleAttribute.append("\"");
179 }
180
181 return styleAttribute.toString();
182 }
183
184 /**
185 * Generates the <code>JavaScript</code> atrributes for the tag.
186 *
187 * @return The generated string for the JavaScript attributes.
188 *
189 */
190
191 protected String generateScriptAttribtues()
192 {
193 StringBuffer scriptAttribtues = new StringBuffer();
194
195 // mouse events
196
197 if (onClick != null)
198 {
199 scriptAttribtues.append(" onclick=\"");
200 scriptAttribtues.append(onClick);
201 scriptAttribtues.append("\"");
202 }
203
204 if (onDblClick != null)
205 {
206 scriptAttribtues.append(" ondblclick=\"");
207 scriptAttribtues.append(onDblClick);
208 scriptAttribtues.append("\"");
209 }
210
211 if (onMouseOver != null)
212 {
213 scriptAttribtues.append(" onmouseover=\"");
214 scriptAttribtues.append(onMouseOver);
215 scriptAttribtues.append("\"");
216 }
217
218 if (onMouseOut != null)
219 {
220 scriptAttribtues.append(" onmouseout=\"");
221 scriptAttribtues.append(onMouseOut);
222 scriptAttribtues.append("\"");
223 }
224
225 if (onMouseMove != null)
226 {
227 scriptAttribtues.append(" onmousemove=\"");
228 scriptAttribtues.append(onMouseMove);
229 scriptAttribtues.append("\"");
230 }
231
232 if (onMouseDown != null)
233 {
234 scriptAttribtues.append(" onmousedown=\"");
235 scriptAttribtues.append(onMouseDown);
236 scriptAttribtues.append("\"");
237 }
238
239 if (onMouseUp != null)
240 {
241 scriptAttribtues.append(" onmouseup=\"");
242 scriptAttribtues.append(onMouseUp);
243 scriptAttribtues.append("\"");
244 }
245
246
247 // key events
248
249 if (onKeyDown != null)
250 {
251 scriptAttribtues.append(" onkeydown=\"");
252 scriptAttribtues.append(onKeyDown);
253 scriptAttribtues.append("\"");
254 }
255
256 if (onKeyUp != null)
257 {
258 scriptAttribtues.append(" onkeyup=\"");
259 scriptAttribtues.append(onKeyUp);
260 scriptAttribtues.append("\"");
261 }
262
263 if (onKeyPress != null)
264 {
265 scriptAttribtues.append(" onkeypress=\"");
266 scriptAttribtues.append(onKeyPress);
267 scriptAttribtues.append("\"");
268 }
269
270
271 // other events
272
273 if (onSelect != null)
274 {
275 scriptAttribtues.append(" onselect=\"");
276 scriptAttribtues.append(onSelect);
277 scriptAttribtues.append("\"");
278 }
279
280 if (onChange != null)
281 {
282 scriptAttribtues.append(" onchange=\"");
283 scriptAttribtues.append(onChange);
284 scriptAttribtues.append("\"");
285 }
286
287 if (onBlur != null)
288 {
289 scriptAttribtues.append(" onblur=\"");
290 scriptAttribtues.append(onBlur);
291 scriptAttribtues.append("\"");
292 }
293
294 if (onFocus != null)
295 {
296 scriptAttribtues.append(" onfocus=\"");
297 scriptAttribtues.append(onFocus);
298 scriptAttribtues.append("\"");
299 }
300
301
302 return scriptAttribtues.toString();
303 }
304
305
306 /** Releases the tag resources. */
307 public void release()
308 {
309 super.release();
310 accessKey = null;
311 tabIndex = null;
312 onClick = null;
313 onDblClick = null;
314 onMouseOver = null;
315 onMouseOut = null;
316 onMouseMove = null;
317 onMouseDown = null;
318 onMouseUp = null;
319 onKeyDown = null;
320 onKeyUp = null;
321 onKeyPress = null;
322 onSelect = null;
323 onChange = null;
324 onBlur = null;
325 onFocus = null;
326 style = null;
327 styleClass = null;
328 }
329
330 /**
331 * This is for extracting a value from a node at the given path.
332 *
333 * @param path The path to a {@link ModelNode}.
334 *
335 * @return The node value found at the given path.
336 *
337 */
338
339 protected String extractModelValue(String path) throws Exception
340 {
341 // establish tag context
342 establishModelContext();
343
344 // get the value from the path
345 ModelNode modelNode = getModelNode(path, true);
346
347 String ls_output = "";
348
349 if (modelNode != null)
350 {
351 // set the tag value to return
352 String value = modelNode.getNodeValue();
353 ls_output = value;
354 }
355
356 return ls_output;
357 }
358 }
359