KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > view > jsp > html > HtmlBaseTag


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.view.jsp.html;
8
9
10 import java.util.ArrayList JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.List JavaDoc;
13 import java.util.Map JavaDoc;
14
15 import javax.servlet.jsp.JspException JavaDoc;
16 import javax.servlet.jsp.tagext.BodyTagSupport JavaDoc;
17
18 import com.inversoft.verge.mvc.view.HtmlConstants;
19 import com.inversoft.verge.mvc.view.jsp.JspTools;
20
21
22 /**
23  * This class is the base class for all html tags. This is
24  * where common methods that are to be used by form tags as
25  * well as other html tags can be put. Common variables are
26  * also stored here, some will be used by all children,
27  * some children won't use any.
28  *
29  * @author Brian Pontarelli
30  */

31 public abstract class HtmlBaseTag extends BodyTagSupport JavaDoc {
32
33     private String JavaDoc name;
34     protected String JavaDoc localName;
35     private String JavaDoc style;
36     protected String JavaDoc localStyle;
37     private String JavaDoc styleclass;
38     protected String JavaDoc localStyleclass;
39     private String JavaDoc title;
40     protected String JavaDoc localTitle;
41     private String JavaDoc lang;
42     protected String JavaDoc localLang;
43     private String JavaDoc dir;
44     protected String JavaDoc localDir;
45     private String JavaDoc onclick;
46     protected String JavaDoc localOnclick;
47     private String JavaDoc ondblclick;
48     protected String JavaDoc localOndblclick;
49     private String JavaDoc onmousedown;
50     protected String JavaDoc localOnmousedown;
51     private String JavaDoc onmouseup;
52     protected String JavaDoc localOnmouseup;
53     private String JavaDoc onmousemove;
54     protected String JavaDoc localOnmousemove;
55     private String JavaDoc onmouseout;
56     protected String JavaDoc localOnmouseout;
57     private String JavaDoc onkeypress;
58     protected String JavaDoc localOnkeypress;
59     private String JavaDoc onkeydown;
60     protected String JavaDoc localOnkeydown;
61     private String JavaDoc onkeyup;
62     protected String JavaDoc localOnkeyup;
63     private String JavaDoc onmouseover;
64     protected String JavaDoc localOnmouseover;
65     private String JavaDoc alt;
66     protected String JavaDoc localAlt;
67     private String JavaDoc tabindex;
68     protected String JavaDoc localTabindex;
69     private String JavaDoc accesskey;
70     protected String JavaDoc localAccesskey;
71     private String JavaDoc accept;
72     protected String JavaDoc localAccept;
73     protected Map JavaDoc attributes;
74     protected List JavaDoc singleAttrs;
75
76
77     /**
78      * Constructs a new html base tag and creates the attribute hash and list
79      */

80     public HtmlBaseTag() {
81         attributes = new HashMap JavaDoc();
82         singleAttrs = new ArrayList JavaDoc();
83     }
84
85
86     //-------------------------------------------------------------------------
87
//----------------------- Core attributes for HTML tags -------------------
88
//-------------------------------------------------------------------------
89

90     /**
91      * Gets the tags name.
92      *
93      * @return The tags name
94      */

95     public String JavaDoc getName() {
96         return name;
97     }
98
99     /**
100      * Sets the tags name. This method should only be called by the container.
101      * Sub-classes should not call this name under any circumstances. Instead they
102      * should use the variable directly.
103      *
104      * @param name The name of the tag
105      */

106     public void setName(String JavaDoc name) {
107         this.name = name;
108     }
109
110     /**
111      * Gets the tags style.
112      *
113      * @return The tags style
114      */

115     public String JavaDoc getStyle() {
116         return style;
117     }
118
119     /**
120      * Sets the tags style and adds it to the attributes hash
121      *
122      * @param style The new style of the tag
123      */

124     public void setStyle(String JavaDoc style) {
125         this.style = style;
126     }
127
128     /**
129      * Gets the tags StyleClass, which is also the class html attribute
130      *
131      * @return The tags style class
132      */

133     public String JavaDoc getStyleclass() {
134         return styleclass;
135     }
136
137     /**
138      * Sets the tags StyleClass (class attribuet) and adds it to the attributes
139      * hash
140      *
141      * @param styleclass The new style class of the tag
142      */

143     public void setStyleclass(String JavaDoc styleclass) {
144         this.styleclass = styleclass;
145     }
146
147     /**
148      * Gets the tags title
149      *
150      * @return The tags title
151      */

152     public String JavaDoc getTitle() {
153         return title;
154     }
155
156     /**
157      * Sets the tags title
158      *
159      * @param title The new title of the tag
160      */

161     public void setTitle(String JavaDoc title) {
162         this.title = title;
163     }
164
165
166     //-------------------------------------------------------------------------
167
//------------ Internationalization attributes for HTML tags --------------
168
//-------------------------------------------------------------------------
169

170     /**
171      * Retrieves the tags lang attribute
172      *
173      * @return Returns the tags lang attribute
174      */

175     public String JavaDoc getLang() {
176         return lang;
177     }
178
179     /**
180      * Populates the tags lang attribute
181      *
182      * @param lang The value of the tags lang attribute
183      */

184     public void setLang(String JavaDoc lang) {
185         this.lang = lang;
186     }
187
188     /**
189      * Retrieves the tags dir attribute
190      *
191      * @return Returns the tags dir attribute
192      */

193     public String JavaDoc getDir() {
194         return dir;
195     }
196
197     /**
198      * Populates the tags dir attribute
199      *
200      * @param dir The value of the tags dir attribute
201      */

202     public void setDir(String JavaDoc dir) {
203         this.dir = dir;
204     }
205
206     //-------------------------------------------------------------------------
207
//--------------------- UI event attributes for HTML tags -----------------
208
//-------------------------------------------------------------------------
209

210     /**
211      * Retrieves the onclick attribute of the tag
212      *
213      * @return Returns the onclick attribute of the tag
214      */

215     public String JavaDoc getOnclick() {
216         return onclick;
217     }
218
219     /**
220      * Populates the onclick attribute of the tag
221      *
222      * @param onclick The value of the onclick attribute of the tag
223      */

224     public void setOnclick(String JavaDoc onclick) {
225         this.onclick = onclick;
226     }
227
228     /**
229      * Retrieves the tags ondblclick attribute
230      *
231      * @return Returns the tags ondblclick attribute
232      */

233     public String JavaDoc getOndblclick() {
234         return ondblclick;
235     }
236
237     /**
238      * Populates the tags ondblclick attribute
239      *
240      * @param ondblclick The value of the tags ondblclick attribute
241      */

242     public void setOndblclick(String JavaDoc ondblclick) {
243         this.ondblclick = ondblclick;
244     }
245
246     /**
247      * Retrieves the tags onmousedown attribute
248      *
249      * @return Returns the tags onmousedown attribute
250      */

251     public String JavaDoc getOnmousedown() {
252         return onmousedown;
253     }
254
255     /**
256      * Populates the tags onmousedown attribute
257      *
258      * @param onmousedown The value of the tags onmousedown attribute
259      */

260     public void setOnmousedown(String JavaDoc onmousedown) {
261         this.onmousedown = onmousedown;
262     }
263
264     /**
265      * Retrieves the tags onmouseup attribute
266      *
267      * @return Returns the tags onmouseup attribute
268      */

269     public String JavaDoc getOnmouseup() {
270         return onmouseup;
271     }
272
273     /**
274      * Populates the tags onmouseup attribute
275      *
276      * @param onmouseup The value of the tags onmouseup attribute
277      */

278     public void setOnmouseup(String JavaDoc onmouseup) {
279         this.onmouseup = onmouseup;
280     }
281
282     /**
283      * Retrieves the tags onmouseover attribute
284      *
285      * @return Returns the tags onmouseover attribute
286      */

287     public String JavaDoc getOnmouseover() {
288         return onmouseover;
289     }
290
291     /**
292      * Populates the tags onmouseover attribute
293      *
294      * @param onmouseover The value of the tags onmouseover attribute
295      */

296     public void setOnmouseover(String JavaDoc onmouseover) {
297         this.onmouseover = onmouseover;
298     }
299
300     /**
301      * Retrieves the tags onmousemove attribute
302      *
303      * @return Returns the tags onmousemove attribute
304      */

305     public String JavaDoc getOnmousemove() {
306         return onmousemove;
307     }
308
309     /**
310      * Populates the tags onmousemove attribute
311      *
312      * @param onmousemove The value of the tags onmousemove attribute
313      */

314     public void setOnmousemove(String JavaDoc onmousemove) {
315         this.onmousemove = onmousemove;
316     }
317
318     /**
319      * Retrieves the tags onmouseout attribute
320      *
321      * @return Returns the tags onmouseout attribute
322      */

323     public String JavaDoc getOnmouseout() {
324         return onmouseout;
325     }
326
327     /**
328      * Populates the tags onmouseout attribute
329      *
330      * @param onmouseout The value of the tags onmouseout attribute
331      */

332     public void setOnmouseout(String JavaDoc onmouseout) {
333         this.onmouseout = onmouseout;
334     }
335
336     /**
337      * Retrieves the tags onkeypress attribute
338      *
339      * @return Returns the tags onkeypress attribute
340      */

341     public String JavaDoc getOnkeypress() {
342         return onkeypress;
343     }
344
345     /**
346      * Populates the tags onkeypress attribute
347      *
348      * @param onkeypress The value of the tags onkeypress attribute
349      */

350     public void setOnkeypress(String JavaDoc onkeypress) {
351         this.onkeypress = onkeypress;
352     }
353
354     /**
355      * Retrieves the tags onkeydown attribute
356      *
357      * @return Returns the tags onkeydown attribute
358      */

359     public String JavaDoc getOnkeydown() {
360         return onkeydown;
361     }
362
363     /**
364      * Populates the tags onkeydown attribute
365      *
366      * @param onkeydown The value of the tags onkeydown attribute
367      */

368     public void setOnkeydown(String JavaDoc onkeydown) {
369         this.onkeydown = onkeydown;
370     }
371
372     /**
373      * Retrieves the tags onkeyup attribute
374      *
375      * @return Returns the tags onkeyup attribute
376      */

377     public String JavaDoc getOnkeyup() {
378         return onkeyup;
379     }
380
381     /**
382      * Populates the tags onkeyup attribute
383      *
384      * @param onkeyup The value of the tags onkeyup attribute
385      */

386     public void setOnkeyup(String JavaDoc onkeyup) {
387         this.onkeyup = onkeyup;
388     }
389
390
391     //-------------------------------------------------------------------------
392
//----------------------- Misc attributes for HTML tags -------------------
393
//-------------------------------------------------------------------------
394

395     /**
396      * Retrieves the tags alt attribute
397      *
398      * @return Returns the tags alt attribute
399      */

400     public String JavaDoc getAlt() {
401         return alt;
402     }
403
404     /**
405      * Populates the tags alt attribute
406      *
407      * @param alt The value of the tags alt attribute
408      */

409     public void setAlt(String JavaDoc alt) {
410         this.alt = alt;
411     }
412
413     /**
414      * Retrieves the tags tabindex attribute
415      *
416      * @return Returns the tags tabindex attribute
417      */

418     public String JavaDoc getTabindex() {
419         return tabindex;
420     }
421
422     /**
423      * Populates the tags tabindex attribute
424      *
425      * @param tabindex The value of the tags tabindex attribute
426      */

427     public void setTabindex(String JavaDoc tabindex) {
428         this.tabindex = tabindex;
429     }
430
431     /**
432      * Retrieves the tags accesskey attribute
433      *
434      * @return Returns the tags accesskey attribute
435      */

436     public String JavaDoc getAccesskey() {
437         return accesskey;
438     }
439
440     /**
441      * Populates the tags accesskey attribute
442      *
443      * @param accesskey The value of the tags accesskey attribute
444      */

445     public void setAccesskey(String JavaDoc accesskey) {
446         this.accesskey = accesskey;
447     }
448
449     /**
450      * Retrieves the tags accept attribute
451      *
452      * @return Returns the tags accept attribute
453      */

454     public String JavaDoc getAccept() {
455         return accept;
456     }
457
458     /**
459      * Populates the tags accept attribute
460      *
461      * @param accept The value of the tags accept attribute
462      */

463     public void setAccept(String JavaDoc accept) {
464         this.accept = accept;
465     }
466
467
468     //-------------------------------------------------------------------------
469
// Extra methods
470
//-------------------------------------------------------------------------
471

472     /**
473      * Returns true if the name property was set using the setName method (which
474      * should only be called by the container. Therefore, do not call that method
475      * in sub-classes)
476      */

477     public boolean hasName() {
478         return (getName() != null);
479     }
480
481     /**
482      * Expands any of the attributes that were set.
483      */

484     protected void initialize() throws JspException JavaDoc {
485
486         attributes.clear();
487         singleAttrs.clear();
488
489         localName = name;
490         localStyle = style;
491         localStyleclass = styleclass;
492         localTitle = title;
493         localLang = lang;
494         localDir = dir;
495         localOnclick = onclick;
496         localOndblclick = ondblclick;
497         localOnmousedown = onmousedown;
498         localOnmouseup = onmouseup;
499         localOnmouseover = onmouseover;
500         localOnmousemove = onmousemove;
501         localOnmouseout = onmouseout;
502         localOnkeypress = onkeypress;
503         localOnkeydown = onkeydown;
504         localOnkeyup = onkeyup;
505         localAlt = alt;
506         localTabindex = tabindex;
507         localAccesskey = accesskey;
508         localAccept = accept;
509
510         // Expand the attributes if not JSP 2.0+.
511
if (!JspTools.JSP_20) {
512             localStyle = (String JavaDoc) JspTools.expand("style", style, String JavaDoc.class,
513                 this, pageContext);
514             localStyleclass = (String JavaDoc) JspTools.expand("styleclass", styleclass,
515                 String JavaDoc.class, this, pageContext);
516             localTitle = (String JavaDoc) JspTools.expand("title", title, String JavaDoc.class,
517                 this, pageContext);
518             localLang = (String JavaDoc) JspTools.expand("lang", lang, String JavaDoc.class, this,
519                 pageContext);
520             localDir = (String JavaDoc) JspTools.expand("dir", dir, String JavaDoc.class, this,
521                 pageContext);
522             localOnclick = (String JavaDoc) JspTools.expand("onclick", onclick,
523                 String JavaDoc.class, this, pageContext);
524             localOndblclick = (String JavaDoc) JspTools.expand("ondblclick", ondblclick,
525                 String JavaDoc.class, this, pageContext);
526             localOnmousedown = (String JavaDoc) JspTools.expand("onmousedown", onmousedown,
527                 String JavaDoc.class, this, pageContext);
528             localOnmouseup = (String JavaDoc) JspTools.expand("onmouseup", onmouseup,
529                 String JavaDoc.class, this, pageContext);
530             localOnmouseover = (String JavaDoc) JspTools.expand("onmouseover", onmouseover,
531                 String JavaDoc.class, this, pageContext);
532             localOnmousemove = (String JavaDoc) JspTools.expand("onmousemove", onmousemove,
533                 String JavaDoc.class, this, pageContext);
534             localOnmouseout = (String JavaDoc) JspTools.expand("onmouseout", onmouseout,
535                 String JavaDoc.class, this, pageContext);
536             localOnkeypress = (String JavaDoc) JspTools.expand("onkeypress", onkeypress,
537                 String JavaDoc.class, this, pageContext);
538             localOnkeydown = (String JavaDoc) JspTools.expand("onkeydown", onkeydown,
539                 String JavaDoc.class, this, pageContext);
540             localOnkeyup = (String JavaDoc) JspTools.expand("onkeyup", onkeyup, String JavaDoc.class,
541                 this, pageContext);
542             localAlt = (String JavaDoc) JspTools.expand("alt", alt, String JavaDoc.class, this,
543                 pageContext);
544             localTabindex = (String JavaDoc) JspTools.expand("tabindex", tabindex,
545                 String JavaDoc.class, this, pageContext);
546             localAccesskey = (String JavaDoc) JspTools.expand("accesskey", accesskey,
547                 String JavaDoc.class, this, pageContext);
548             localAccept = (String JavaDoc) JspTools.expand("accept", accept, String JavaDoc.class,
549                 this, pageContext);
550         }
551
552         attributes.put(HtmlConstants.STYLE, localStyle);
553         attributes.put(HtmlConstants.STYLE_CLASS, localStyleclass);
554         attributes.put(HtmlConstants.TITLE, localTitle);
555         attributes.put(HtmlConstants.LANG, localLang);
556         attributes.put(HtmlConstants.DIR, localDir);
557         attributes.put(HtmlConstants.ON_CLICK, localOnclick);
558         attributes.put(HtmlConstants.ON_DBL_CLICK, localOndblclick);
559         attributes.put(HtmlConstants.ON_MOUSE_DOWN, localOnmousedown);
560         attributes.put(HtmlConstants.ON_MOUSE_UP, localOnmouseup);
561         attributes.put(HtmlConstants.ON_MOUSE_OVER, localOnmouseover);
562         attributes.put(HtmlConstants.ON_MOUSE_MOVE, localOnmousemove);
563         attributes.put(HtmlConstants.ON_MOUSE_OUT, localOnmouseout);
564         attributes.put(HtmlConstants.ON_KEY_PRESS, localOnkeypress);
565         attributes.put(HtmlConstants.ON_KEY_DOWN, localOnkeydown);
566         attributes.put(HtmlConstants.ON_KEY_UP, localOnkeyup);
567         attributes.put(HtmlConstants.ALT, localAlt);
568         attributes.put(HtmlConstants.TAB_INDEX, localTabindex);
569         attributes.put(HtmlConstants.ACCESS_KEY, localAccesskey);
570         attributes.put(HtmlConstants.ACCEPT, localAccept);
571     }
572
573     /**
574      * Since a single instance of the Tag may be used, we need to reset any state
575      * that is internally dependent such as the hasName boolean and the name
576      * String (done by calling setName(null)).
577      *
578      * @see javax.servlet.jsp.tagext.Tag#release()
579      */

580     public void release() {
581         setName(null);
582         setAccept(null);
583         setAccesskey(null);
584         setAlt(null);
585         setDir(null);
586         setId(null);
587         setLang(null);
588         setOnclick(null);
589         setOndblclick(null);
590         setOnkeydown(null);
591         setOnkeypress(null);
592         setOnkeyup(null);
593         setOnmousedown(null);
594         setOnmousemove(null);
595         setOnmouseout(null);
596         setOnmouseover(null);
597         setOnmouseup(null);
598         setStyle(null);
599         setStyleclass(null);
600         setTabindex(null);
601         setTitle(null);
602         attributes.clear();
603         singleAttrs.clear();
604     }
605 }
Popular Tags