java/cewolf-1.0/src/main/java/de/laures/cewolf/taglib/html/AbstractHTMLBaseTag.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/java/cewolf-1.0/src/main/java/de/laures/cewolf/taglib/html/AbstractHTMLBaseTag.java Sat Feb 28 21:31:02 2009 +0100
1.3 @@ -0,0 +1,307 @@
1.4 +/* ================================================================
1.5 + * Cewolf : Chart enabling Web Objects Framework
1.6 + * ================================================================
1.7 + *
1.8 + * Project Info: http://cewolf.sourceforge.net
1.9 + * Project Lead: Guido Laures (guido@laures.de);
1.10 + *
1.11 + * (C) Copyright 2002, by Guido Laures
1.12 + *
1.13 + * This library is free software; you can redistribute it and/or modify it under the terms
1.14 + * of the GNU Lesser General Public License as published by the Free Software Foundation;
1.15 + * either version 2.1 of
1.16 + * the License, or (at your option) any later version.
1.17 + *
1.18 + * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
1.19 + * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
1.20 + * See the GNU Lesser General Public License for more details.
1.21 + *
1.22 + * You should have received a copy of the GNU Lesser General Public License along with this
1.23 + * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
1.24 + * Boston, MA 02111-1307, USA.
1.25 + */
1.26 +
1.27 +package de.laures.cewolf.taglib.html;
1.28 +
1.29 +import java.io.IOException;
1.30 +import java.io.Serializable;
1.31 +import java.io.Writer;
1.32 +
1.33 +import javax.servlet.jsp.JspException;
1.34 +import javax.servlet.jsp.JspWriter;
1.35 +
1.36 +import de.laures.cewolf.taglib.tags.CewolfBodyTag;
1.37 +
1.38 +/**
1.39 + * Abstract base class which holds attribbutes common for all HTML 4.0 tags.
1.40 + * @author Guido Laures
1.41 + */
1.42 +public abstract class AbstractHTMLBaseTag extends CewolfBodyTag implements Serializable{
1.43 +
1.44 + protected static final int UNDEFINED_INT = -1;
1.45 + protected static final float UNDEFINED_FLOAT = -1.0f;
1.46 + protected static final String UNDEFINED_STR = null;
1.47 +
1.48 + /** Holds value of property ID. */
1.49 + protected String id = UNDEFINED_STR;
1.50 +
1.51 + /** Holds value of property clazz. */
1.52 + protected String clazz = UNDEFINED_STR;
1.53 +
1.54 + /** Holds value of property style. */
1.55 + protected String style = UNDEFINED_STR;
1.56 +
1.57 + /** Holds value of property title. */
1.58 + protected String title = UNDEFINED_STR;
1.59 +
1.60 + /** Holds value of property lang. */
1.61 + protected String lang = UNDEFINED_STR;
1.62 +
1.63 + /** Holds value of property dir. */
1.64 + protected String dir = UNDEFINED_STR;
1.65 +
1.66 + /** Holds value of property onclick. */
1.67 + protected String onclick = UNDEFINED_STR;
1.68 +
1.69 + /** Holds value of property ondbclick. */
1.70 + protected String ondbclick = UNDEFINED_STR;
1.71 +
1.72 + /** Holds value of property onmousedown. */
1.73 + protected String onmousedown = UNDEFINED_STR;
1.74 +
1.75 + /** Holds value of property onmouseup. */
1.76 + protected String onmouseup = UNDEFINED_STR;
1.77 +
1.78 + /** Holds value of property onmouseover. */
1.79 + protected String onmouseover = UNDEFINED_STR;
1.80 +
1.81 + /** Holds value of property onmousemove. */
1.82 + protected String onmousemove = UNDEFINED_STR;
1.83 +
1.84 + /** Holds value of property onmouseout. */
1.85 + protected String onmouseout = UNDEFINED_STR;
1.86 +
1.87 + /** Holds value of property onkeypress. */
1.88 + protected String onkeypress = UNDEFINED_STR;
1.89 +
1.90 + /** Holds value of property onkeydown. */
1.91 + protected String onkeydown = UNDEFINED_STR;
1.92 +
1.93 + /** Holds value of property onkeyup. */
1.94 + protected String onkeyup = UNDEFINED_STR;
1.95 +
1.96 + public AbstractHTMLBaseTag(){
1.97 + setId(UNDEFINED_STR);
1.98 + }
1.99 +
1.100 + protected abstract String getTagName();
1.101 +
1.102 + protected abstract boolean hasBody();
1.103 +
1.104 + protected abstract boolean wellFormed();
1.105 +
1.106 + protected void reset(){
1.107 + this.clazz = UNDEFINED_STR;
1.108 + this.dir = UNDEFINED_STR;
1.109 + this.id = UNDEFINED_STR;
1.110 + this.lang = UNDEFINED_STR;
1.111 + this.onclick = UNDEFINED_STR;
1.112 + this.ondbclick = UNDEFINED_STR;
1.113 + this.onkeydown = UNDEFINED_STR;
1.114 + this.onkeypress = UNDEFINED_STR;
1.115 + this.onkeyup = UNDEFINED_STR;
1.116 + this.onmousedown = UNDEFINED_STR;
1.117 + this.onmousemove = UNDEFINED_STR;
1.118 + this.onmouseout = UNDEFINED_STR;
1.119 + this.onmouseover = UNDEFINED_STR;
1.120 + this.onmouseup = UNDEFINED_STR;
1.121 + this.style = UNDEFINED_STR;
1.122 + this.title = UNDEFINED_STR;
1.123 + }
1.124 +
1.125 + public int doStartTag() throws JspException {
1.126 + JspWriter writer = pageContext.getOut();
1.127 + try {
1.128 + writer.write("<" + getTagName());
1.129 + writeAttributes(writer);
1.130 + if(hasBody()){
1.131 + writer.write(">");
1.132 + return EVAL_PAGE;
1.133 + } else {
1.134 + return SKIP_BODY;
1.135 + }
1.136 + } catch(IOException ioe){
1.137 + super.pageContext.getServletContext().log("",ioe);
1.138 + throw new JspException(ioe.getMessage());
1.139 + }
1.140 + }
1.141 +
1.142 + public int doEndTag() throws JspException {
1.143 + JspWriter writer = pageContext.getOut();
1.144 + try{
1.145 + if(hasBody()){
1.146 + writer.write("</" + getTagName() + ">");
1.147 + } else {
1.148 + if(wellFormed()){
1.149 + writer.write(" /");
1.150 + }
1.151 + writer.write(">");
1.152 + }
1.153 + return doAfterEndTag(EVAL_PAGE);
1.154 + } catch(IOException ioe){
1.155 + super.pageContext.getServletContext().log("",ioe);
1.156 + throw new JspException(ioe.getMessage());
1.157 + }
1.158 + }
1.159 +
1.160 + public void writeAttributes(Writer wr){
1.161 + try {
1.162 + appendAttributeDeclaration(wr, getId(), "ID");
1.163 + appendAttributeDeclaration(wr, this.clazz, "CLASS");
1.164 + appendAttributeDeclaration(wr, this.style, "STYLE");
1.165 + appendAttributeDeclaration(wr, this.onclick, "ONCLICK");
1.166 + appendAttributeDeclaration(wr, this.ondbclick, "ONDBCLICK");
1.167 + appendAttributeDeclaration(wr, this.onkeydown, "ONKEYDOWN");
1.168 + appendAttributeDeclaration(wr, this.onkeypress, "ONKEYPRESS");
1.169 + appendAttributeDeclaration(wr, this.onkeyup, "ONKEYUP");
1.170 + appendAttributeDeclaration(wr, this.onmousedown, "ONMOUSEDOWN");
1.171 + appendAttributeDeclaration(wr, this.onmousemove, "ONMOUSEMOVE");
1.172 + appendAttributeDeclaration(wr, this.onmouseout, "ONMOUSEOUT");
1.173 + appendAttributeDeclaration(wr, this.onmouseover, "ONMOUSEOVER");
1.174 + appendAttributeDeclaration(wr, this.onmouseup, "ONMOUSEUP");
1.175 + appendAttributeDeclaration(wr, this.title, "TITLE");
1.176 + appendAttributeDeclaration(wr, this.lang, "LANG");
1.177 + appendAttributeDeclaration(wr, this.dir, "DIR");
1.178 + } catch(IOException ioex){
1.179 + ioex.printStackTrace();
1.180 + }
1.181 + }
1.182 +
1.183 + protected void appendAttributeDeclaration(Writer wr, String attr, String name) throws IOException {
1.184 + if(attr != UNDEFINED_STR){
1.185 + wr.write(" " + name + "=\"" + attr + "\"");
1.186 + }
1.187 + }
1.188 +
1.189 + protected void appendAttributeDeclaration(Writer wr, int attr, String name) throws IOException {
1.190 + // does not call the according method for Strings to avoid additional
1.191 + // String instantiation
1.192 + if(attr != UNDEFINED_INT){
1.193 + wr.write(" " + name + "=\"" + attr + "\"");
1.194 + }
1.195 + }
1.196 +
1.197 + protected void appendAttributeDeclaration(Writer wr, float attr, String name) throws IOException {
1.198 + // does not call the according method for Strings to avoid additional
1.199 + // String instantiation
1.200 + if(attr != UNDEFINED_FLOAT){
1.201 + wr.write(" " + name + "=\"" + attr + "\"");
1.202 + }
1.203 + }
1.204 +
1.205 + /** Setter for property clazz.
1.206 + * @param clazz New value of property clazz.
1.207 + */
1.208 + public void setClass(String clazz) {
1.209 + this.clazz = clazz;
1.210 + }
1.211 +
1.212 + /** Setter for property style.
1.213 + * @param style New value of property style.
1.214 + */
1.215 + public void setStyle(String style) {
1.216 + this.style = style;
1.217 + }
1.218 +
1.219 + /** Setter for property title.
1.220 + * @param title New value of property title.
1.221 + */
1.222 + public void setHtmltitle(String title) {
1.223 + this.title = title;
1.224 + }
1.225 +
1.226 + /** Setter for property lang.
1.227 + * @param lang New value of property lang.
1.228 + */
1.229 + public void setLang(String lang) {
1.230 + this.lang = lang;
1.231 + }
1.232 +
1.233 + /** Setter for property dir.
1.234 + * @param dir New value of property dir.
1.235 + */
1.236 + public void setDir(String dir) {
1.237 + this.dir = dir;
1.238 + }
1.239 +
1.240 + /** Setter for property onclick.
1.241 + * @param onclick New value of property onclick.
1.242 + */
1.243 + public void setOnclick(String onclick) {
1.244 + this.onclick = onclick;
1.245 + }
1.246 +
1.247 + /** Setter for property ondbclick.
1.248 + * @param ondbclick New value of property ondbclick.
1.249 + */
1.250 + public void setOndbclick(String ondbclick) {
1.251 + this.ondbclick = ondbclick;
1.252 + }
1.253 +
1.254 + /** Setter for property onmousedown.
1.255 + * @param onmousedown New value of property onmousedown.
1.256 + */
1.257 + public void setOnmousedown(String onmousedown) {
1.258 + this.onmousedown = onmousedown;
1.259 + }
1.260 +
1.261 + /** Setter for property onmouseup.
1.262 + * @param onmouseup New value of property onmouseup.
1.263 + */
1.264 + public void setOnmouseup(String onmouseup) {
1.265 + this.onmouseup = onmouseup;
1.266 + }
1.267 +
1.268 + /** Setter for property onmouseover.
1.269 + * @param onmouseover New value of property onmouseover.
1.270 + */
1.271 + public void setOnmouseover(String onmouseover) {
1.272 + this.onmouseover = onmouseover;
1.273 + }
1.274 +
1.275 + /** Setter for property onmousemove.
1.276 + * @param onmousemove New value of property onmousemove.
1.277 + */
1.278 + public void setOnmousemove(String onmousemove) {
1.279 + this.onmousemove = onmousemove;
1.280 + }
1.281 +
1.282 + /** Setter for property onmouseout.
1.283 + * @param onmouseout New value of property onmouseout.
1.284 + */
1.285 + public void setOnmouseout(String onmouseout) {
1.286 + this.onmouseout = onmouseout;
1.287 + }
1.288 +
1.289 + /** Setter for property onkeypress.
1.290 + * @param onkeypress New value of property onkeypress.
1.291 + */
1.292 + public void setOnkeypress(String onkeypress) {
1.293 + this.onkeypress = onkeypress;
1.294 + }
1.295 +
1.296 + /** Setter for property onkeydown.
1.297 + * @param onkeydown New value of property onkeydown.
1.298 + */
1.299 + public void setOnkeydown(String onkeydown) {
1.300 + this.onkeydown = onkeydown;
1.301 + }
1.302 +
1.303 + /** Setter for property onkeyup.
1.304 + * @param onkeyup New value of property onkeyup.
1.305 + */
1.306 + public void setOnkeyup(String onkeyup) {
1.307 + this.onkeyup = onkeyup;
1.308 + }
1.309 +
1.310 +}