franta-hg@1: /* ================================================================ franta-hg@1: * Cewolf : Chart enabling Web Objects Framework franta-hg@1: * ================================================================ franta-hg@1: * franta-hg@1: * Project Info: http://cewolf.sourceforge.net franta-hg@1: * Project Lead: Guido Laures (guido@laures.de); franta-hg@1: * franta-hg@1: * (C) Copyright 2002, by Guido Laures franta-hg@1: * franta-hg@1: * This library is free software; you can redistribute it and/or modify it under the terms franta-hg@1: * of the GNU Lesser General Public License as published by the Free Software Foundation; franta-hg@1: * either version 2.1 of franta-hg@1: * the License, or (at your option) any later version. franta-hg@1: * franta-hg@1: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; franta-hg@1: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. franta-hg@1: * See the GNU Lesser General Public License for more details. franta-hg@1: * franta-hg@1: * You should have received a copy of the GNU Lesser General Public License along with this franta-hg@1: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, franta-hg@1: * Boston, MA 02111-1307, USA. franta-hg@1: */ franta-hg@1: franta-hg@1: package de.laures.cewolf.taglib.html; franta-hg@1: franta-hg@1: import java.io.IOException; franta-hg@1: import java.io.Serializable; franta-hg@1: import java.io.Writer; franta-hg@1: franta-hg@1: import javax.servlet.jsp.JspException; franta-hg@1: import javax.servlet.jsp.JspWriter; franta-hg@1: franta-hg@1: import de.laures.cewolf.taglib.tags.CewolfBodyTag; franta-hg@1: franta-hg@1: /** franta-hg@1: * Abstract base class which holds attribbutes common for all HTML 4.0 tags. franta-hg@1: * @author Guido Laures franta-hg@1: */ franta-hg@1: public abstract class AbstractHTMLBaseTag extends CewolfBodyTag implements Serializable{ franta-hg@1: franta-hg@1: protected static final int UNDEFINED_INT = -1; franta-hg@1: protected static final float UNDEFINED_FLOAT = -1.0f; franta-hg@1: protected static final String UNDEFINED_STR = null; franta-hg@1: franta-hg@1: /** Holds value of property ID. */ franta-hg@1: protected String id = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property clazz. */ franta-hg@1: protected String clazz = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property style. */ franta-hg@1: protected String style = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property title. */ franta-hg@1: protected String title = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property lang. */ franta-hg@1: protected String lang = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property dir. */ franta-hg@1: protected String dir = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property onclick. */ franta-hg@1: protected String onclick = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property ondbclick. */ franta-hg@1: protected String ondbclick = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property onmousedown. */ franta-hg@1: protected String onmousedown = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property onmouseup. */ franta-hg@1: protected String onmouseup = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property onmouseover. */ franta-hg@1: protected String onmouseover = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property onmousemove. */ franta-hg@1: protected String onmousemove = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property onmouseout. */ franta-hg@1: protected String onmouseout = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property onkeypress. */ franta-hg@1: protected String onkeypress = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property onkeydown. */ franta-hg@1: protected String onkeydown = UNDEFINED_STR; franta-hg@1: franta-hg@1: /** Holds value of property onkeyup. */ franta-hg@1: protected String onkeyup = UNDEFINED_STR; franta-hg@1: franta-hg@1: public AbstractHTMLBaseTag(){ franta-hg@1: setId(UNDEFINED_STR); franta-hg@1: } franta-hg@1: franta-hg@1: protected abstract String getTagName(); franta-hg@1: franta-hg@1: protected abstract boolean hasBody(); franta-hg@1: franta-hg@1: protected abstract boolean wellFormed(); franta-hg@1: franta-hg@1: protected void reset(){ franta-hg@1: this.clazz = UNDEFINED_STR; franta-hg@1: this.dir = UNDEFINED_STR; franta-hg@1: this.id = UNDEFINED_STR; franta-hg@1: this.lang = UNDEFINED_STR; franta-hg@1: this.onclick = UNDEFINED_STR; franta-hg@1: this.ondbclick = UNDEFINED_STR; franta-hg@1: this.onkeydown = UNDEFINED_STR; franta-hg@1: this.onkeypress = UNDEFINED_STR; franta-hg@1: this.onkeyup = UNDEFINED_STR; franta-hg@1: this.onmousedown = UNDEFINED_STR; franta-hg@1: this.onmousemove = UNDEFINED_STR; franta-hg@1: this.onmouseout = UNDEFINED_STR; franta-hg@1: this.onmouseover = UNDEFINED_STR; franta-hg@1: this.onmouseup = UNDEFINED_STR; franta-hg@1: this.style = UNDEFINED_STR; franta-hg@1: this.title = UNDEFINED_STR; franta-hg@1: } franta-hg@1: franta-hg@1: public int doStartTag() throws JspException { franta-hg@1: JspWriter writer = pageContext.getOut(); franta-hg@1: try { franta-hg@1: writer.write("<" + getTagName()); franta-hg@1: writeAttributes(writer); franta-hg@1: if(hasBody()){ franta-hg@1: writer.write(">"); franta-hg@1: return EVAL_PAGE; franta-hg@1: } else { franta-hg@1: return SKIP_BODY; franta-hg@1: } franta-hg@1: } catch(IOException ioe){ franta-hg@1: super.pageContext.getServletContext().log("",ioe); franta-hg@1: throw new JspException(ioe.getMessage()); franta-hg@1: } franta-hg@1: } franta-hg@1: franta-hg@1: public int doEndTag() throws JspException { franta-hg@1: JspWriter writer = pageContext.getOut(); franta-hg@1: try{ franta-hg@1: if(hasBody()){ franta-hg@1: writer.write(""); franta-hg@1: } else { franta-hg@1: if(wellFormed()){ franta-hg@1: writer.write(" /"); franta-hg@1: } franta-hg@1: writer.write(">"); franta-hg@1: } franta-hg@1: return doAfterEndTag(EVAL_PAGE); franta-hg@1: } catch(IOException ioe){ franta-hg@1: super.pageContext.getServletContext().log("",ioe); franta-hg@1: throw new JspException(ioe.getMessage()); franta-hg@1: } franta-hg@1: } franta-hg@1: franta-hg@1: public void writeAttributes(Writer wr){ franta-hg@1: try { franta-hg@1: appendAttributeDeclaration(wr, getId(), "ID"); franta-hg@1: appendAttributeDeclaration(wr, this.clazz, "CLASS"); franta-hg@1: appendAttributeDeclaration(wr, this.style, "STYLE"); franta-hg@1: appendAttributeDeclaration(wr, this.onclick, "ONCLICK"); franta-hg@1: appendAttributeDeclaration(wr, this.ondbclick, "ONDBCLICK"); franta-hg@1: appendAttributeDeclaration(wr, this.onkeydown, "ONKEYDOWN"); franta-hg@1: appendAttributeDeclaration(wr, this.onkeypress, "ONKEYPRESS"); franta-hg@1: appendAttributeDeclaration(wr, this.onkeyup, "ONKEYUP"); franta-hg@1: appendAttributeDeclaration(wr, this.onmousedown, "ONMOUSEDOWN"); franta-hg@1: appendAttributeDeclaration(wr, this.onmousemove, "ONMOUSEMOVE"); franta-hg@1: appendAttributeDeclaration(wr, this.onmouseout, "ONMOUSEOUT"); franta-hg@1: appendAttributeDeclaration(wr, this.onmouseover, "ONMOUSEOVER"); franta-hg@1: appendAttributeDeclaration(wr, this.onmouseup, "ONMOUSEUP"); franta-hg@1: appendAttributeDeclaration(wr, this.title, "TITLE"); franta-hg@1: appendAttributeDeclaration(wr, this.lang, "LANG"); franta-hg@1: appendAttributeDeclaration(wr, this.dir, "DIR"); franta-hg@1: } catch(IOException ioex){ franta-hg@1: ioex.printStackTrace(); franta-hg@1: } franta-hg@1: } franta-hg@1: franta-hg@1: protected void appendAttributeDeclaration(Writer wr, String attr, String name) throws IOException { franta-hg@1: if(attr != UNDEFINED_STR){ franta-hg@1: wr.write(" " + name + "=\"" + attr + "\""); franta-hg@1: } franta-hg@1: } franta-hg@1: franta-hg@1: protected void appendAttributeDeclaration(Writer wr, int attr, String name) throws IOException { franta-hg@1: // does not call the according method for Strings to avoid additional franta-hg@1: // String instantiation franta-hg@1: if(attr != UNDEFINED_INT){ franta-hg@1: wr.write(" " + name + "=\"" + attr + "\""); franta-hg@1: } franta-hg@1: } franta-hg@1: franta-hg@1: protected void appendAttributeDeclaration(Writer wr, float attr, String name) throws IOException { franta-hg@1: // does not call the according method for Strings to avoid additional franta-hg@1: // String instantiation franta-hg@1: if(attr != UNDEFINED_FLOAT){ franta-hg@1: wr.write(" " + name + "=\"" + attr + "\""); franta-hg@1: } franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property clazz. franta-hg@1: * @param clazz New value of property clazz. franta-hg@1: */ franta-hg@1: public void setClass(String clazz) { franta-hg@1: this.clazz = clazz; franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property style. franta-hg@1: * @param style New value of property style. franta-hg@1: */ franta-hg@1: public void setStyle(String style) { franta-hg@1: this.style = style; franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property title. franta-hg@1: * @param title New value of property title. franta-hg@1: */ franta-hg@1: public void setHtmltitle(String title) { franta-hg@1: this.title = title; franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property lang. franta-hg@1: * @param lang New value of property lang. franta-hg@1: */ franta-hg@1: public void setLang(String lang) { franta-hg@1: this.lang = lang; franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property dir. franta-hg@1: * @param dir New value of property dir. franta-hg@1: */ franta-hg@1: public void setDir(String dir) { franta-hg@1: this.dir = dir; franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property onclick. franta-hg@1: * @param onclick New value of property onclick. franta-hg@1: */ franta-hg@1: public void setOnclick(String onclick) { franta-hg@1: this.onclick = onclick; franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property ondbclick. franta-hg@1: * @param ondbclick New value of property ondbclick. franta-hg@1: */ franta-hg@1: public void setOndbclick(String ondbclick) { franta-hg@1: this.ondbclick = ondbclick; franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property onmousedown. franta-hg@1: * @param onmousedown New value of property onmousedown. franta-hg@1: */ franta-hg@1: public void setOnmousedown(String onmousedown) { franta-hg@1: this.onmousedown = onmousedown; franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property onmouseup. franta-hg@1: * @param onmouseup New value of property onmouseup. franta-hg@1: */ franta-hg@1: public void setOnmouseup(String onmouseup) { franta-hg@1: this.onmouseup = onmouseup; franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property onmouseover. franta-hg@1: * @param onmouseover New value of property onmouseover. franta-hg@1: */ franta-hg@1: public void setOnmouseover(String onmouseover) { franta-hg@1: this.onmouseover = onmouseover; franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property onmousemove. franta-hg@1: * @param onmousemove New value of property onmousemove. franta-hg@1: */ franta-hg@1: public void setOnmousemove(String onmousemove) { franta-hg@1: this.onmousemove = onmousemove; franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property onmouseout. franta-hg@1: * @param onmouseout New value of property onmouseout. franta-hg@1: */ franta-hg@1: public void setOnmouseout(String onmouseout) { franta-hg@1: this.onmouseout = onmouseout; franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property onkeypress. franta-hg@1: * @param onkeypress New value of property onkeypress. franta-hg@1: */ franta-hg@1: public void setOnkeypress(String onkeypress) { franta-hg@1: this.onkeypress = onkeypress; franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property onkeydown. franta-hg@1: * @param onkeydown New value of property onkeydown. franta-hg@1: */ franta-hg@1: public void setOnkeydown(String onkeydown) { franta-hg@1: this.onkeydown = onkeydown; franta-hg@1: } franta-hg@1: franta-hg@1: /** Setter for property onkeyup. franta-hg@1: * @param onkeyup New value of property onkeyup. franta-hg@1: */ franta-hg@1: public void setOnkeyup(String onkeyup) { franta-hg@1: this.onkeyup = onkeyup; franta-hg@1: } franta-hg@1: franta-hg@1: }