KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > blandware > atleap > webapp > taglib > core > BaseHandlerTag


1 /*
2  * Copyright 2004 Blandware (http://www.blandware.com)
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 /*
17  * Copyright 2004 Blandware (http://www.blandware.com)
18  *
19  * Licensed under the Apache License, Version 2.0 (the "License");
20  * you may not use this file except in compliance with the License.
21  * You may obtain a copy of the License at
22  *
23  * http://www.apache.org/licenses/LICENSE-2.0
24  *
25  * Unless required by applicable law or agreed to in writing, software
26  * distributed under the License is distributed on an "AS IS" BASIS,
27  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28  * See the License for the specific language governing permissions and
29  * limitations under the License.
30  */

31 package com.blandware.atleap.webapp.taglib.core;
32
33 import javax.servlet.jsp.tagext.SimpleTagSupport JavaDoc;
34
35
36 /**
37  * <p>Base class for tags that render to links capable of including JavaScript
38  * event handlers and/or CSS Style attributes. This class does not implement
39  * the doTag() method. Subclasses should provide appropriate implementation of this.
40  * </p>
41  * <p>
42  * Allowed attributes are:
43  * <ul>
44  * <li>
45  * <b>disabled</b> - whether this element is disabled or not. For example, this
46  * can be used for buttons to make them not to respond to clicks. Can be
47  * <code>&quot;true&quot;</code> or <code>&quot;false&quot;</code>, default is
48  * <code>&quot;false&quot;</code>
49  * </li>
50  * <li>
51  * <b>style</b> - CSS styles that will be applied to this resulting element. For
52  * example, <code>&quot;visibility: visible; z-index: 10;&quot;</code>
53  * </li>
54  * <li>
55  * <b>styleClass</b> - class that will be assigned to resulting element with
56  * HTML <code>'class'</code> attribute
57  * </li>
58  * <li>
59  * <b>tagId</b> - id that will be assigned to resulting element with HTML
60  * <code>'id'</code> attribute
61  * </li>
62  * <li>
63  * <b>alt</b> - alternate text for generated element
64  * </li>
65  * <li>
66  * <b>title</b> - advisory title for generated element
67  * </li>
68  * <li>
69  * <b>onchange</b> - javascript handler -- code, that is called when element
70  * contents changes
71  * </li>
72  * <li>
73  * <b>onfocus</b> - javascript handler -- code, that is called when element
74  * gains input focus
75  * </li>
76  * <li>
77  * <b>onblur</b> - javascript handler -- code, that is called when element
78  * loses input focus
79  * </li>
80  * <li>
81  * <b>onclick</b> - javascript handler -- code, that is called when element
82  * is clicked
83  * </li>
84  * <li>
85  * <b>ondblclick</b> - javascript handler -- code, that is called when
86  * element is double-clicked
87  * </li>
88  * <li>
89  * <b>onkeydown</b> - javascript handler -- code, that is called when
90  * keyboard key is pressed
91  * </li>
92  * <li>
93  * <b>onkeyup</b> - javascript handler -- code, that is called when
94  * keyboard key is released
95  * </li>
96  * <li>
97  * <b>onkeypressed</b> - javascript handler -- code, that is called when
98  * keyboard key is pressed and released
99  * </li>
100  * <li>
101  * <b>onmousedown</b> - javascript handler -- code, that is called when
102  * mouse button is pressed
103  * </li>
104  * <li>
105  * <b>onmouseup</b> - javascript handler -- code, that is called when
106  * mouse button is released
107  * </li>
108  * <li>
109  * <b>onmousemove</b> - javascript handler -- code, that is called when
110  * mouse is moved over element
111  * </li>
112  * <li>
113  * <b>onmouseover</b> - javascript handler -- code, that is called when
114  * mouse enters element
115  * </li>
116  * <li>
117  * <b>onmouseout</b> - javascript handler -- code, that is called when
118  * mouse leaves element
119  * </li>
120  * <li>
121  * <b>accesskey</b> - key (accelerator) that will be used to immediately access
122  * element
123  * </li>
124  * <li>
125  * <b>tabindex</b> - index that influences the order in which controls are
126  * selected with tab key
127  * </li>
128  * </ul>
129  * </p>
130  * <p><a HREF="BaseHandlerTag.java.htm"><i>View Source</i></a></p>
131  *
132  * @author Sergey Zubtcovskii <a HREF="mailto:sergey.zubtcovskii@blandware.com">&lt;sergey.zubtcovskii@blandware.com&gt;</a>
133  * @version $Revision: 1.11 $ $Date: 2005/10/12 13:34:52 $
134  * @see org.apache.struts.taglib.html.BaseHandlerTag
135  */

136 public class BaseHandlerTag extends SimpleTagSupport JavaDoc {
137
138     // ~ Instance variables
139

140     // ~ Common attributes
141

142     /**
143      * Whether or not this element is disabled (cannot be pressed, for example)
144      */

145     protected Boolean JavaDoc disabled = Boolean.FALSE;
146
147     /**
148      * CSS styles to be applied to this HTML element.
149      */

150     protected String JavaDoc style = new String JavaDoc();
151
152     /**
153      * CSS stylesheet class to be applied to this HTML element (renders a "class" attribute).
154      */

155     protected String JavaDoc styleClass = new String JavaDoc();
156
157     /**
158      * The ID of the generated tag
159      */

160     protected String JavaDoc tagId = new String JavaDoc();
161
162     /**
163      * The alternate text of this element.
164      */

165     private String JavaDoc alt = null;
166
167     /**
168      * The advisory title of this element.
169      */

170     private String JavaDoc title = null;
171
172     // ~ JavaScript events properties
173

174     /**
175      * JavaScript event handler that is executed when this element's content changes.
176      */

177     protected String JavaDoc onchange;
178
179     /**
180      * JavaScript event handler that is executed when this element loses input focus.
181      */

182     protected String JavaDoc onblur;
183
184     /**
185      * JavaScript event handler that is executed when this element receives a mouse click.
186      */

187     protected String JavaDoc onclick;
188
189     /**
190      * JavaScript event handler that is executed when this element receives a mouse double click.
191      */

192     protected String JavaDoc ondblclick;
193
194     /**
195      * JavaScript event handler that is executed when this element receives input focus.
196      */

197     protected String JavaDoc onfocus;
198
199     /**
200      * JavaScript event handler that is executed when this element receives a key down event.
201      */

202     protected String JavaDoc onkeydown;
203
204     /**
205      * JavaScript event handler that is executed when this element receives a key press event.
206      */

207     protected String JavaDoc onkeypress;
208
209     /**
210      * JavaScript event handler that is executed when this element receives a key up event.
211      */

212     protected String JavaDoc onkeyup;
213
214     /**
215      * JavaScript event handler that is executed when this element receives a mouse down event.
216      */

217     protected String JavaDoc onmousedown;
218
219     /**
220      * JavaScript event handler that is executed when this element receives a mouse move event.
221      */

222     protected String JavaDoc onmousemove;
223
224     /**
225      * JavaScript event handler that is executed when this element receives a mouse out event.
226      */

227     protected String JavaDoc onmouseout;
228
229     /**
230      * JavaScript event handler that is executed when this element receives a mouse over event.
231      */

232     protected String JavaDoc onmouseover;
233
234     /**
235      * JavaScript event handler that is executed when this element receives a mouse up event.
236      */

237     protected String JavaDoc onmouseup;
238
239     // Navigation Management
240

241     /**
242      * Access key character.
243      */

244     protected String JavaDoc accesskey;
245
246     /**
247      * Tab index value.
248      */

249     protected String JavaDoc tabindex;
250
251     /**
252      * Gets whether or not this element is disabled
253      *
254      * @return <code>Boolean.TRUE</code> if this element is disabled
255      * @jsp.attribute required="false"
256      * rtexprvalue="true"
257      * type="java.lang.Boolean"
258      * description="Whether or not this element is disabled"
259      */

260     public Boolean JavaDoc getDisabled() {
261         return disabled;
262     }
263
264     /**
265      * Sets whether or not this element is disabled
266      *
267      * @param disabled whether this element is disabled
268      */

269     public void setDisabled(Boolean JavaDoc disabled) {
270         this.disabled = disabled;
271     }
272
273     /**
274      * Returns CSS style assigned to this element
275      *
276      * @return CSS style
277      * @jsp.attribute required="false"
278      * rtexprvalue="true"
279      * type="java.lang.String"
280      * description="CSS styles to be applied to this HTML element"
281      */

282     public String JavaDoc getStyle() {
283         return style;
284     }
285
286     /**
287      * Sets CSS style assigned to this element
288      *
289      * @param style CSS style to set
290      */

291     public void setStyle(String JavaDoc style) {
292         this.style = style;
293     }
294
295     /**
296      * Returns style class assigned to this element
297      *
298      * @return style class
299      * @jsp.attribute required="false"
300      * rtexprvalue="true"
301      * type="java.lang.String"
302      * description="CSS stylesheet class to be applied to this HTML element (renders a "class" attribute). "
303      */

304     public String JavaDoc getStyleClass() {
305         return styleClass;
306     }
307
308     /**
309      * Sets style class assigned to this element
310      *
311      * @param styleClass style class to set
312      */

313     public void setStyleClass(String JavaDoc styleClass) {
314         this.styleClass = styleClass;
315     }
316
317     /**
318      * Gets ID for the generated tag
319      *
320      * @return ID of tag
321      * @jsp.attribute required="false"
322      * rtexprvalue="true"
323      * type="java.lang.String"
324      * description="The ID for the generated tag"
325      */

326     public String JavaDoc getTagId() {
327         return tagId;
328     }
329
330     /**
331      * Sets ID for the generated tag
332      *
333      * @param tagId ID of tag
334      */

335     public void setTagId(String JavaDoc tagId) {
336         this.tagId = tagId;
337     }
338
339     /**
340      * Returns alt value
341      *
342      * @return alt value
343      * @jsp.attribute required="false"
344      * rtexprvalue="true"
345      * type="java.lang.String"
346      * description="The alternate text of this element"
347      */

348     public String JavaDoc getAlt() {
349         return alt;
350     }
351
352     /**
353      * Sets alt value
354      *
355      * @param alt alt value to set
356      */

357     public void setAlt(String JavaDoc alt) {
358         this.alt = alt;
359     }
360
361     /**
362      * Returns title
363      *
364      * @return title
365      * @jsp.attribute required="false"
366      * rtexprvalue="true"
367      * type="java.lang.String"
368      * description="The advisory title of this element"
369      */

370     public String JavaDoc getTitle() {
371         return title;
372     }
373
374     /**
375      * Sets title
376      *
377      * @param title title to set
378      */

379     public void setTitle(String JavaDoc title) {
380         this.title = title;
381     }
382
383     // JavaScript events getters/setters
384

385     /**
386      * Gets JS code that is executed when this element's content is being changed
387      *
388      * @return the JS onchange handler
389      * @jsp.attribute required="false"
390      * rtexprvalue="true"
391      * type="java.lang.String"
392      * description="JavaScript event handler that is executed when this element's content changes."
393      */

394     public String JavaDoc getOnchange() {
395         return onchange;
396     }
397
398     /**
399      * Sets JS code that is executed when this element's content is being changed
400      *
401      * @param onchange the JS onchange handler
402      */

403     public void setOnchange(String JavaDoc onchange) {
404         this.onchange = onchange;
405     }
406
407     /**
408      * Returns JS code that is executed when this element loses focus
409      *
410      * @return the JS onblur handler
411      * @jsp.attribute required="false"
412      * rtexprvalue="true"
413      * type="java.lang.String"
414      * description="JavaScript event handler that is executed when this element loses input focus."
415      */

416     public String JavaDoc getOnblur() {
417         return onblur;
418     }
419
420     /**
421      * Sets JS code that is executed when this element loses focus
422      *
423      * @param onblur the JS onblur handler
424      */

425     public void setOnblur(String JavaDoc onblur) {
426         this.onblur = onblur;
427     }
428
429     /**
430      * Returns JS code that is executed when this element is clicked
431      *
432      * @return the JS onclick handler
433      * @jsp.attribute required="false"
434      * rtexprvalue="true"
435      * type="java.lang.String"
436      * description="JavaScript event handler that is executed when this element receives a mouse click."
437      */

438     public String JavaDoc getOnclick() {
439         return onclick;
440     }
441
442     /**
443      * Sets JS code that is executed when this element is clicked
444      *
445      * @param onclick the JS onclick handler
446      */

447     public void setOnclick(String JavaDoc onclick) {
448         this.onclick = onclick;
449     }
450
451     /**
452      * Returns JS code that is executed when this element is double-clicked
453      *
454      * @return the JS ondblclick handler
455      * @jsp.attribute required="false"
456      * rtexprvalue="true"
457      * type="java.lang.String"
458      * description="JavaScript event handler that is executed when this element receives mouse double click"
459      */

460     public String JavaDoc getOndblclick() {
461         return ondblclick;
462     }
463
464     /**
465      * Sets JS code that is executed when this element is double-clicked
466      *
467      * @param ondblclick the JS ondblclick handler
468      */

469     public void setOndblclick(String JavaDoc ondblclick) {
470         this.ondblclick = ondblclick;
471     }
472
473     /**
474      * Returns JS code that is executed when this element gets focus
475      *
476      * @return the JS onfocus handler
477      * @jsp.attribute required="false"
478      * rtexprvalue="true"
479      * type="java.lang.String"
480      * description="JavaScript event handler that is executed when this element receives input focus"
481      */

482     public String JavaDoc getOnfocus() {
483         return onfocus;
484     }
485
486     /**
487      * Sets JS code that is executed when this element gets focus
488      *
489      * @param onfocus the JS onfocus handler
490      */

491     public void setOnfocus(String JavaDoc onfocus) {
492         this.onfocus = onfocus;
493     }
494
495     /**
496      * Returns JS code that is executed when a key is pressed
497      *
498      * @return the JS onkeydown handler
499      * @jsp.attribute required="false"
500      * rtexprvalue="true"
501      * type="java.lang.String"
502      * description="JavaScript event handler that is executed when this element receives a key down event"
503      */

504     public String JavaDoc getOnkeydown() {
505         return onkeydown;
506     }
507
508     /**
509      * Sets JS code that is executed when a key is pressed
510      *
511      * @param onkeydown the JS onkeydown handler
512      */

513     public void setOnkeydown(String JavaDoc onkeydown) {
514         this.onkeydown = onkeydown;
515     }
516
517     /**
518      * Returns JS code that is executed when a key is pressed and released
519      *
520      * @return the JS onkeypress handler
521      * @jsp.attribute required="false"
522      * rtexprvalue="true"
523      * type="java.lang.String"
524      * description="JavaScript event handler that is executed when this element receives a key press event"
525      */

526     public String JavaDoc getOnkeypress() {
527         return onkeypress;
528     }
529
530     /**
531      * Sets JS code that is executed when a key is pressed and released
532      *
533      * @param onkeypress the JS onkeypress handler
534      */

535     public void setOnkeypress(String JavaDoc onkeypress) {
536         this.onkeypress = onkeypress;
537     }
538
539     /**
540      * Returns JS code that is executed when a key is released
541      *
542      * @return the JS onkeyup handler
543      * @jsp.attribute required="false"
544      * rtexprvalue="true"
545      * type="java.lang.String"
546      * description="JavaScript event handler that is executed when this element receives a key up event"
547      */

548     public String JavaDoc getOnkeyup() {
549         return onkeyup;
550     }
551
552     /**
553      * Gets JS code that is executed when a key is released
554      *
555      * @param onkeyup the JS onkeyup handler
556      */

557     public void setOnkeyup(String JavaDoc onkeyup) {
558         this.onkeyup = onkeyup;
559     }
560
561     /**
562      * Returns JS code that is executed when a mouse button is pressed
563      *
564      * @return the JS onmousedown handler
565      * @jsp.attribute required="false"
566      * rtexprvalue="true"
567      * type="java.lang.String"
568      * description="JavaScript event handler that is executed when this element receives a mouse down event"
569      */

570     public String JavaDoc getOnmousedown() {
571         return onmousedown;
572     }
573
574     /**
575      * Gets JS code that is executed when a mouse button is pressed
576      *
577      * @param onmousedown the JS onmousedown handler
578      */

579     public void setOnmousedown(String JavaDoc onmousedown) {
580         this.onmousedown = onmousedown;
581     }
582
583     /**
584      * Returns JS code that is executed when a mouse is moved
585      *
586      * @return the JS onmousemove handler
587      * @jsp.attribute required="false"
588      * rtexprvalue="true"
589      * type="java.lang.String"
590      * description="JavaScript event handler that is executed when this element receives a mouse move event"
591      */

592     public String JavaDoc getOnmousemove() {
593         return onmousemove;
594     }
595
596     /**
597      * Sets JS code that is executed when a mouse is moved
598      *
599      * @param onmousemove the JS onmousemove handler
600      */

601     public void setOnmousemove(String JavaDoc onmousemove) {
602         this.onmousemove = onmousemove;
603     }
604
605     /**
606      * Returns JS code that is executed when a mouse leaves this element
607      *
608      * @return the JS onmouseout handler
609      * @jsp.attribute required="false"
610      * rtexprvalue="true"
611      * type="java.lang.String"
612      * description="JavaScript event handler that is executed when this element receives a mouse out event"
613      */

614     public String JavaDoc getOnmouseout() {
615         return onmouseout;
616     }
617
618     /**
619      * Sets JS code that is executed when a mouse leaves this element
620      *
621      * @param onmouseout the JS onmouseout handler
622      */

623     public void setOnmouseout(String JavaDoc onmouseout) {
624         this.onmouseout = onmouseout;
625     }
626
627     /**
628      * Returns JS code that is executed when a mouse enters this element
629      *
630      * @return the JS onmouseover handler
631      * @jsp.attribute required="false"
632      * rtexprvalue="true"
633      * type="java.lang.String"
634      * description="JavaScript event handler that is executed when this element receives a mouse over event"
635      */

636     public String JavaDoc getOnmouseover() {
637         return onmouseover;
638     }
639
640     /**
641      * Sets JS code that is executed when a mouse leaves this element
642      *
643      * @param onmouseover the JS onmouseover handler
644      */

645     public void setOnmouseover(String JavaDoc onmouseover) {
646         this.onmouseover = onmouseover;
647     }
648
649     /**
650      * Returns JS code that is executed when a mouse button is released
651      *
652      * @return the JS onmouseup handler
653      * @jsp.attribute required="false"
654      * rtexprvalue="true"
655      * type="java.lang.String"
656      * description="JavaScript event handler that is executed when this element receives a mouse up event"
657      */

658     public String JavaDoc getOnmouseup() {
659         return onmouseup;
660     }
661
662     /**
663      * Sets JS code that is executed when a mouse button is released
664      *
665      * @param onmouseup the JS onmouseup handler
666      */

667     public void setOnmouseup(String JavaDoc onmouseup) {
668         this.onmouseup = onmouseup;
669     }
670
671     /**
672      * Returns access key that's used to quickly select this element
673      *
674      * @return access key
675      * @jsp.attribute required="false"
676      * rtexprvalue="true"
677      * type="java.lang.String"
678      * description="Keyboard character used to immediately select this element"
679      */

680     public String JavaDoc getAccesskey() {
681         return accesskey;
682     }
683
684     /**
685      * Sets access key that's used to quickly select this element
686      *
687      * @param accesskey access key
688      */

689     public void setAccesskey(String JavaDoc accesskey) {
690         this.accesskey = accesskey;
691     }
692
693     /**
694      * Returns tab index of this element
695      *
696      * @return tab index
697      * @jsp.attribute required="false"
698      * rtexprvalue="true"
699      * type="java.lang.String"
700      * description="Tab index"
701      */

702     public String JavaDoc getTabindex() {
703         return tabindex;
704     }
705
706     /**
707      * Sets tab index of this element
708      *
709      * @param tabindex tab index to set
710      */

711     public void setTabindex(String JavaDoc tabindex) {
712         this.tabindex = tabindex;
713     }
714
715     /**
716      * Concatenates all attributes which were set into string buffer
717      *
718      * @return all set attributes with their values
719      */

720     protected StringBuffer JavaDoc prepareAttributes() {
721         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
722
723         if (disabled == null) {
724             disabled = Boolean.FALSE;
725         }
726         if ( disabled.booleanValue() ) {
727             result.append(" disabled=\"true\"");
728         }
729
730         if ( style != null && style.length() != 0 ) {
731             result.append(" style=\"" + style + "\"");
732         }
733
734         if ( styleClass != null && styleClass.length() != 0 ) {
735             result.append(" class=\"" + styleClass + "\"");
736         }
737
738         if ( tagId != null && tagId.length() != 0 ) {
739             result.append(" id=\"" + tagId + "\"");
740         }
741
742         if ( alt != null && alt.length() != 0 ) {
743             result.append(" alt=\"" + alt + "\"");
744         }
745
746         if ( title != null && title.length() != 0 ) {
747             result.append(" title=\"" + title + "\"");
748         }
749
750         if ( onchange != null && onchange.length() != 0 ) {
751             result.append(" onchange=\"" + onchange + "\"");
752         }
753
754         if ( onblur != null && onblur.length() != 0 ) {
755             result.append(" onblur=\"" + onblur + "\"");
756         }
757
758         if ( onclick != null && onclick.length() != 0 ) {
759             result.append(" onclick=\"" + onclick + "\"");
760         }
761
762         if ( ondblclick != null && ondblclick.length() != 0 ) {
763             result.append(" ondblclick=\"" + ondblclick + "\"");
764         }
765
766         if ( onfocus != null && onfocus.length() != 0 ) {
767             result.append(" onfocus=\"" + onfocus + "\"");
768         }
769
770         if ( onkeydown != null && onkeydown.length() != 0 ) {
771             result.append(" onkeydown=\"" + onkeydown + "\"");
772         }
773
774         if ( onkeypress != null && onkeypress.length() != 0 ) {
775             result.append(" onkeypress=\"" + onkeypress + "\"");
776         }
777
778         if ( onkeyup != null && onkeyup.length() != 0 ) {
779             result.append(" onkeyup=\"" + onkeyup + "\"");
780         }
781
782         if ( onmousedown != null && onmousedown.length() != 0 ) {
783             result.append(" onmousedown=\"" + onmousedown + "\"");
784         }
785
786         if ( onmousemove != null && onmousemove.length() != 0 ) {
787             result.append(" onmousemove=\"" + onmousemove + "\"");
788         }
789
790         if ( onmouseout != null && onmouseout.length() != 0 ) {
791             result.append(" onmouseout=\"" + onmouseout + "\"");
792         }
793
794         if ( onmouseover != null && onmouseover.length() != 0 ) {
795             result.append(" onmouseover=\"" + onmouseover + "\"");
796         }
797
798         if ( onmouseup != null && onmouseup.length() != 0 ) {
799             result.append(" onmouseup=\"" + onmouseup + "\"");
800         }
801
802         if ( accesskey != null && accesskey.length() != 0 ) {
803             result.append(" accesskey=\"" + accesskey + "\"");
804         }
805
806         if ( tabindex != null && tabindex.length() != 0 ) {
807             result.append(" tabindex=\"" + tabindex + "\"");
808         }
809
810         return result;
811     }
812
813 }
814
Popular Tags