View Javadoc

1   /*
2    * $Id: BaseControlTag.java 130 2004-11-28 13:00:44Z josem $
3    *
4    * Tarsis
5    * Copyright (C) 2002 Talika Open Source Group
6    *
7    * This program is free software; you can redistribute it and/or modify
8    * it under the terms of the GNU General Public License as published by
9    * the Free Software Foundation; either version 2 of the License, or
10   * (at your option) any later version.
11   *
12   * This program is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   * GNU General Public License for more details.
16   *
17   * You should have received a copy of the GNU General Public License
18   * along with this program; if not, write to the Free Software
19   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   *
21   */
22  
23  package org.talika.tarsis.taglib.form;
24  
25  /**
26   * Base implementation for all form control tags.
27   *
28   * @author  Jose M. Palomar
29   * @version $Revision: 130 $
30   */
31  public abstract class BaseControlTag extends BaseTag {
32  
33      // Fields
34      /**
35       * <code>name</code> attribute.
36       */
37      private String name;
38  
39      /**
40       * <code>value</code> attribute.
41       */
42      private String value;
43  
44      /**
45       * <code>disabled</code> attribute.
46       */
47      private boolean disabled;
48  
49      /**
50       * <code>readonly</code> attribute.
51       */
52      private boolean readonly;
53  
54      /**
55       * <code>tabindex</code> attribute.
56       */
57      private String tabindex;
58  
59      /**
60       * <code>accesskey</code> attribute.
61       */
62      private String accesskey;
63  
64      /**
65       * <code>onfocus</code> attribute.
66       */
67      private String onfocus;
68  
69      /**
70       * <code>onblur</code> attribute.
71       */
72      private String onblur;
73  
74      /**
75       * <code>onselect</code> attribute.
76       */
77      private String onselect;
78  
79      /**
80       * <code>onchange</code> attribute.
81       */
82      private String onchange;
83  
84      // Constructors
85      /**
86       * Creates a new <code>BaseControlTag</code> object.
87       */
88      protected BaseControlTag() {
89      }
90  
91      // Renderers
92      /**
93       * Renders a string with the value of name attribute.
94       *
95       * @return String a string with the value of name attribute
96       */
97      public final String controlName() {
98  
99          StringBuffer atts = new StringBuffer();
100 
101         if (name != null) {
102             atts.append(" name=\"");
103             atts.append(name);
104             atts.append("\"");
105         }
106 
107         return atts.toString();
108     }
109 
110     /**
111      * Renders a string with the value of value attribute.
112      *
113      * @return String a string with the value of value attribute
114      */
115     public final String controlValue() {
116 
117         StringBuffer atts = new StringBuffer();
118 
119         if (value != null) {
120             atts.append(" value=\"");
121             atts.append(value);
122             atts.append("\"");
123         }
124 
125         return atts.toString();
126 
127     }
128 
129     /**
130      * Renders a string with values of control attributes.<br>
131      * Control attributes are <code>disabled</code>, <code>readonly</code>,
132      * <code>accesskey</code> and <code>tabindex</code>.
133      *
134      * @return String a string with values of control attributes.
135      */
136     public final String controlAttributes() {
137 
138         StringBuffer atts = new StringBuffer();
139 
140         if (disabled) {
141             atts.append(" disabled");
142         }
143 
144         if (readonly) {
145             atts.append(" readonly");
146         }
147 
148         if (accesskey != null) {
149             atts.append(" accesskey=\"");
150             atts.append(accesskey);
151             atts.append("\"");
152         }
153 
154         if (tabindex != null) {
155             atts.append(" tabindex=\"");
156             atts.append(tabindex);
157             atts.append("\"");
158         }
159 
160         return atts.toString();
161 
162     }
163 
164     /**
165      * Renders a string with values of control events attributes.<br>
166      * Control events attributes are <code>onblur</code>, <code>onchange</code>,
167      * <code>onfocus</code> and <code>onselect</code>.
168      *
169      * @return String a string with values of control events attributes.
170      */
171     public final String controlEvents() {
172 
173         StringBuffer events = new StringBuffer();
174 
175         if (onblur != null) {
176             events.append(" onblur=\"");
177             events.append(onblur);
178             events.append("\"");
179         }
180 
181         if (onchange != null) {
182             events.append(" onchange=\"");
183             events.append(onchange);
184             events.append("\"");
185         }
186 
187         if (onfocus != null) {
188             events.append(" onfocus=\"");
189             events.append(onfocus);
190             events.append("\"");
191         }
192 
193         if (onselect != null) {
194             events.append(" onselect=\"");
195             events.append(onselect);
196             events.append("\"");
197         }
198 
199         return events.toString();
200 
201     }
202 
203     // Attributes
204     /**
205      * Sets <code>name</code> attribute value.
206      *
207      * @param name String <code>name</code> attribute value.
208      */
209     public final void setName(String name) {
210         this.name = name;
211     }
212 
213     /**
214      * Sets <code>value</code> attribute value.
215      *
216      * @param value String <code>value</code> attribute value.
217      */
218     public final void setValue(String value) {
219         this.value = value;
220     }
221 
222     /**
223      * Sets <code>disabled</code> attribute value.
224      *
225      * @param disabled String <code>disabled</code> attribute value.
226      */
227     public final void setDisabled(String disabled) {
228         this.disabled = disabled.equalsIgnoreCase("true");
229     }
230 
231     /**
232      * Sets <code>readonly</code> attribute value.
233      *
234      * @param readonly String <code>readonly</code> attribute value.
235      */
236     public final void setReadonly(String readonly) {
237         this.readonly = readonly.equalsIgnoreCase("true");
238     }
239 
240     /**
241      * Sets <code>accesskey</code> attribute value.
242      *
243      * @param accesskey String <code>accesskey</code> attribute value.
244      */
245     public final void setAccesskey(String accesskey) {
246         this.accesskey = accesskey;
247     }
248 
249     /**
250      * Sets <code>tabindex</code> attribute value.
251      *
252      * @param tabindex String <code>tabindex</code> attribute value.
253      */
254     public final void setTabindex(String tabindex) {
255         this.tabindex = tabindex;
256     }
257 
258     /**
259      * Sets <code>onblur</code> attribute value.
260      *
261      * @param onblur String <code>onblur</code> attribute value.
262      */
263     public final void setOnblur(String onblur) {
264         this.onblur = onblur;
265     }
266 
267     /**
268      * Sets <code>onchange</code> attribute value.
269      *
270      * @param onchange String <code>onchange</code> attribute value.
271      */
272     public final void setOnchange(String onchange) {
273         this.onchange = onchange;
274     }
275 
276     /**
277      * Sets <code>onfocus</code> attribute value.
278      *
279      * @param onfocus String <code>onfocus</code> attribute value.
280      */
281     public final void setOnfocus(String onfocus) {
282         this.onfocus = onfocus;
283     }
284 
285     /**
286      * Sets <code>onselect</code> attribute value.
287      *
288      * @param onselect String <code>onselect</code> attribute value.
289      */
290     public final void setOnselect(String onselect) {
291         this.onselect = onselect;
292     }
293 
294     /**
295      * Called on a Tag handler to release state.
296      *
297      * @see javax.servlet.jsp.tagext.Tag#release()
298      */
299     public void release() {
300 
301         super.release();
302 
303         this.name = null;
304         this.value = null;
305         this.disabled = false;
306         this.readonly = false;
307         this.accesskey = null;
308         this.tabindex = null;
309 
310         this.onblur = null;
311         this.onchange = null;
312         this.onfocus = null;
313         this.onselect = null;
314 
315     }
316 
317 }