java/cewolf-1.0/src/main/java/de/laures/cewolf/taglib/html/AbstractHTMLBaseTag.java
1 /* ================================================================
2 * Cewolf : Chart enabling Web Objects Framework
3 * ================================================================
5 * Project Info: http://cewolf.sourceforge.net
6 * Project Lead: Guido Laures (guido@laures.de);
8 * (C) Copyright 2002, by Guido Laures
10 * This library is free software; you can redistribute it and/or modify it under the terms
11 * of the GNU Lesser General Public License as published by the Free Software Foundation;
12 * either version 2.1 of
13 * the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
16 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17 * See the GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License along with this
20 * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
21 * Boston, MA 02111-1307, USA.
24 package de.laures.cewolf.taglib.html;
26 import java.io.IOException;
27 import java.io.Serializable;
28 import java.io.Writer;
30 import javax.servlet.jsp.JspException;
31 import javax.servlet.jsp.JspWriter;
33 import de.laures.cewolf.taglib.tags.CewolfBodyTag;
36 * Abstract base class which holds attribbutes common for all HTML 4.0 tags.
37 * @author Guido Laures
39 public abstract class AbstractHTMLBaseTag extends CewolfBodyTag implements Serializable{
41 protected static final int UNDEFINED_INT = -1;
42 protected static final float UNDEFINED_FLOAT = -1.0f;
43 protected static final String UNDEFINED_STR = null;
45 /** Holds value of property ID. */
46 protected String id = UNDEFINED_STR;
48 /** Holds value of property clazz. */
49 protected String clazz = UNDEFINED_STR;
51 /** Holds value of property style. */
52 protected String style = UNDEFINED_STR;
54 /** Holds value of property title. */
55 protected String title = UNDEFINED_STR;
57 /** Holds value of property lang. */
58 protected String lang = UNDEFINED_STR;
60 /** Holds value of property dir. */
61 protected String dir = UNDEFINED_STR;
63 /** Holds value of property onclick. */
64 protected String onclick = UNDEFINED_STR;
66 /** Holds value of property ondbclick. */
67 protected String ondbclick = UNDEFINED_STR;
69 /** Holds value of property onmousedown. */
70 protected String onmousedown = UNDEFINED_STR;
72 /** Holds value of property onmouseup. */
73 protected String onmouseup = UNDEFINED_STR;
75 /** Holds value of property onmouseover. */
76 protected String onmouseover = UNDEFINED_STR;
78 /** Holds value of property onmousemove. */
79 protected String onmousemove = UNDEFINED_STR;
81 /** Holds value of property onmouseout. */
82 protected String onmouseout = UNDEFINED_STR;
84 /** Holds value of property onkeypress. */
85 protected String onkeypress = UNDEFINED_STR;
87 /** Holds value of property onkeydown. */
88 protected String onkeydown = UNDEFINED_STR;
90 /** Holds value of property onkeyup. */
91 protected String onkeyup = UNDEFINED_STR;
93 public AbstractHTMLBaseTag(){
97 protected abstract String getTagName();
99 protected abstract boolean hasBody();
101 protected abstract boolean wellFormed();
103 protected void reset(){
104 this.clazz = UNDEFINED_STR;
105 this.dir = UNDEFINED_STR;
106 this.id = UNDEFINED_STR;
107 this.lang = UNDEFINED_STR;
108 this.onclick = UNDEFINED_STR;
109 this.ondbclick = UNDEFINED_STR;
110 this.onkeydown = UNDEFINED_STR;
111 this.onkeypress = UNDEFINED_STR;
112 this.onkeyup = UNDEFINED_STR;
113 this.onmousedown = UNDEFINED_STR;
114 this.onmousemove = UNDEFINED_STR;
115 this.onmouseout = UNDEFINED_STR;
116 this.onmouseover = UNDEFINED_STR;
117 this.onmouseup = UNDEFINED_STR;
118 this.style = UNDEFINED_STR;
119 this.title = UNDEFINED_STR;
122 public int doStartTag() throws JspException {
123 JspWriter writer = pageContext.getOut();
125 writer.write("<" + getTagName());
126 writeAttributes(writer);
133 } catch(IOException ioe){
134 super.pageContext.getServletContext().log("",ioe);
135 throw new JspException(ioe.getMessage());
139 public int doEndTag() throws JspException {
140 JspWriter writer = pageContext.getOut();
143 writer.write("</" + getTagName() + ">");
150 return doAfterEndTag(EVAL_PAGE);
151 } catch(IOException ioe){
152 super.pageContext.getServletContext().log("",ioe);
153 throw new JspException(ioe.getMessage());
157 public void writeAttributes(Writer wr){
159 appendAttributeDeclaration(wr, getId(), "ID");
160 appendAttributeDeclaration(wr, this.clazz, "CLASS");
161 appendAttributeDeclaration(wr, this.style, "STYLE");
162 appendAttributeDeclaration(wr, this.onclick, "ONCLICK");
163 appendAttributeDeclaration(wr, this.ondbclick, "ONDBCLICK");
164 appendAttributeDeclaration(wr, this.onkeydown, "ONKEYDOWN");
165 appendAttributeDeclaration(wr, this.onkeypress, "ONKEYPRESS");
166 appendAttributeDeclaration(wr, this.onkeyup, "ONKEYUP");
167 appendAttributeDeclaration(wr, this.onmousedown, "ONMOUSEDOWN");
168 appendAttributeDeclaration(wr, this.onmousemove, "ONMOUSEMOVE");
169 appendAttributeDeclaration(wr, this.onmouseout, "ONMOUSEOUT");
170 appendAttributeDeclaration(wr, this.onmouseover, "ONMOUSEOVER");
171 appendAttributeDeclaration(wr, this.onmouseup, "ONMOUSEUP");
172 appendAttributeDeclaration(wr, this.title, "TITLE");
173 appendAttributeDeclaration(wr, this.lang, "LANG");
174 appendAttributeDeclaration(wr, this.dir, "DIR");
175 } catch(IOException ioex){
176 ioex.printStackTrace();
180 protected void appendAttributeDeclaration(Writer wr, String attr, String name) throws IOException {
181 if(attr != UNDEFINED_STR){
182 wr.write(" " + name + "=\"" + attr + "\"");
186 protected void appendAttributeDeclaration(Writer wr, int attr, String name) throws IOException {
187 // does not call the according method for Strings to avoid additional
188 // String instantiation
189 if(attr != UNDEFINED_INT){
190 wr.write(" " + name + "=\"" + attr + "\"");
194 protected void appendAttributeDeclaration(Writer wr, float attr, String name) throws IOException {
195 // does not call the according method for Strings to avoid additional
196 // String instantiation
197 if(attr != UNDEFINED_FLOAT){
198 wr.write(" " + name + "=\"" + attr + "\"");
202 /** Setter for property clazz.
203 * @param clazz New value of property clazz.
205 public void setClass(String clazz) {
209 /** Setter for property style.
210 * @param style New value of property style.
212 public void setStyle(String style) {
216 /** Setter for property title.
217 * @param title New value of property title.
219 public void setHtmltitle(String title) {
223 /** Setter for property lang.
224 * @param lang New value of property lang.
226 public void setLang(String lang) {
230 /** Setter for property dir.
231 * @param dir New value of property dir.
233 public void setDir(String dir) {
237 /** Setter for property onclick.
238 * @param onclick New value of property onclick.
240 public void setOnclick(String onclick) {
241 this.onclick = onclick;
244 /** Setter for property ondbclick.
245 * @param ondbclick New value of property ondbclick.
247 public void setOndbclick(String ondbclick) {
248 this.ondbclick = ondbclick;
251 /** Setter for property onmousedown.
252 * @param onmousedown New value of property onmousedown.
254 public void setOnmousedown(String onmousedown) {
255 this.onmousedown = onmousedown;
258 /** Setter for property onmouseup.
259 * @param onmouseup New value of property onmouseup.
261 public void setOnmouseup(String onmouseup) {
262 this.onmouseup = onmouseup;
265 /** Setter for property onmouseover.
266 * @param onmouseover New value of property onmouseover.
268 public void setOnmouseover(String onmouseover) {
269 this.onmouseover = onmouseover;
272 /** Setter for property onmousemove.
273 * @param onmousemove New value of property onmousemove.
275 public void setOnmousemove(String onmousemove) {
276 this.onmousemove = onmousemove;
279 /** Setter for property onmouseout.
280 * @param onmouseout New value of property onmouseout.
282 public void setOnmouseout(String onmouseout) {
283 this.onmouseout = onmouseout;
286 /** Setter for property onkeypress.
287 * @param onkeypress New value of property onkeypress.
289 public void setOnkeypress(String onkeypress) {
290 this.onkeypress = onkeypress;
293 /** Setter for property onkeydown.
294 * @param onkeydown New value of property onkeydown.
296 public void setOnkeydown(String onkeydown) {
297 this.onkeydown = onkeydown;
300 /** Setter for property onkeyup.
301 * @param onkeyup New value of property onkeyup.
303 public void setOnkeyup(String onkeyup) {
304 this.onkeyup = onkeyup;