java/cewolf-1.0/src/main/java/de/laures/cewolf/taglib/html/AbstractHTMLBaseTag.java
author František Kučera <franta-hg@frantovo.cz>
Sun, 01 Mar 2009 11:06:49 +0100
changeset 4 249560bcc466
parent 1 639991d0808a
permissions -rw-r--r--
Doplnění serializovatelnosti
     1 /* ================================================================
     2  * Cewolf : Chart enabling Web Objects Framework
     3  * ================================================================
     4  *
     5  * Project Info:  http://cewolf.sourceforge.net
     6  * Project Lead:  Guido Laures (guido@laures.de);
     7  *
     8  * (C) Copyright 2002, by Guido Laures
     9  *
    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.
    14  *
    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.
    18  *
    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.
    22  */
    23 
    24 package de.laures.cewolf.taglib.html;
    25 
    26 import java.io.IOException;
    27 import java.io.Serializable;
    28 import java.io.Writer;
    29 
    30 import javax.servlet.jsp.JspException;
    31 import javax.servlet.jsp.JspWriter;
    32 
    33 import de.laures.cewolf.taglib.tags.CewolfBodyTag;
    34 
    35 /**
    36  * Abstract base class which holds attribbutes common for all HTML 4.0 tags.
    37  * @author  Guido Laures
    38  */
    39 public abstract class AbstractHTMLBaseTag extends CewolfBodyTag implements Serializable{
    40     
    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;
    44     
    45     /** Holds value of property ID. */
    46     protected String id = UNDEFINED_STR;
    47     
    48     /** Holds value of property clazz. */
    49     protected String clazz = UNDEFINED_STR;
    50     
    51     /** Holds value of property style. */
    52     protected String style = UNDEFINED_STR;
    53     
    54     /** Holds value of property title. */
    55     protected String title = UNDEFINED_STR;
    56     
    57     /** Holds value of property lang. */
    58     protected String lang = UNDEFINED_STR;
    59     
    60     /** Holds value of property dir. */
    61     protected String dir = UNDEFINED_STR;
    62     
    63     /** Holds value of property onclick. */
    64     protected String onclick = UNDEFINED_STR;
    65     
    66     /** Holds value of property ondbclick. */
    67     protected String ondbclick = UNDEFINED_STR;
    68     
    69     /** Holds value of property onmousedown. */
    70     protected String onmousedown = UNDEFINED_STR;
    71     
    72     /** Holds value of property onmouseup. */
    73     protected String onmouseup = UNDEFINED_STR;
    74     
    75     /** Holds value of property onmouseover. */
    76     protected String onmouseover = UNDEFINED_STR;
    77     
    78     /** Holds value of property onmousemove. */
    79     protected String onmousemove = UNDEFINED_STR;
    80     
    81     /** Holds value of property onmouseout. */
    82     protected String onmouseout = UNDEFINED_STR;
    83     
    84     /** Holds value of property onkeypress. */
    85     protected String onkeypress = UNDEFINED_STR;
    86     
    87     /** Holds value of property onkeydown. */
    88     protected String onkeydown = UNDEFINED_STR;
    89     
    90     /** Holds value of property onkeyup. */
    91     protected String onkeyup = UNDEFINED_STR;
    92     
    93     public AbstractHTMLBaseTag(){
    94     	setId(UNDEFINED_STR);
    95     }
    96     
    97     protected abstract String getTagName();
    98     
    99     protected abstract boolean hasBody();
   100     
   101     protected abstract boolean wellFormed();
   102     
   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;
   120     }
   121     
   122     public int doStartTag() throws JspException {
   123         JspWriter writer = pageContext.getOut();
   124         try {
   125             writer.write("<" + getTagName());
   126             writeAttributes(writer);
   127             if(hasBody()){
   128                 writer.write(">");
   129                 return EVAL_PAGE;
   130             } else {
   131                 return SKIP_BODY;
   132             }
   133         } catch(IOException ioe){
   134         	super.pageContext.getServletContext().log("",ioe);
   135             throw new JspException(ioe.getMessage());
   136         }
   137     }
   138     
   139     public int doEndTag() throws JspException {
   140         JspWriter writer = pageContext.getOut();
   141         try{
   142             if(hasBody()){
   143                 writer.write("</" + getTagName() + ">");
   144             } else {
   145                 if(wellFormed()){
   146                     writer.write(" /");
   147                 }
   148                 writer.write(">");
   149             }
   150             return doAfterEndTag(EVAL_PAGE);
   151         } catch(IOException ioe){
   152         	super.pageContext.getServletContext().log("",ioe);
   153             throw new JspException(ioe.getMessage());
   154         }
   155     }
   156     
   157     public void writeAttributes(Writer wr){
   158         try {
   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();
   177         }
   178     }
   179     
   180     protected void appendAttributeDeclaration(Writer wr, String attr, String name) throws IOException {
   181         if(attr != UNDEFINED_STR){
   182             wr.write(" " + name + "=\"" + attr + "\"");
   183         }
   184     }
   185     
   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 + "\"");
   191         }
   192     }
   193     
   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 + "\"");
   199         }
   200     }
   201     
   202     /** Setter for property clazz.
   203      * @param clazz New value of property clazz.
   204      */
   205     public void setClass(String clazz) {
   206         this.clazz = clazz;
   207     }
   208     
   209     /** Setter for property style.
   210      * @param style New value of property style.
   211      */
   212     public void setStyle(String style) {
   213         this.style = style;
   214     }
   215     
   216     /** Setter for property title.
   217      * @param title New value of property title.
   218      */
   219     public void setHtmltitle(String title) {
   220         this.title = title;
   221     }
   222     
   223     /** Setter for property lang.
   224      * @param lang New value of property lang.
   225      */
   226     public void setLang(String lang) {
   227         this.lang = lang;
   228     }
   229     
   230     /** Setter for property dir.
   231      * @param dir New value of property dir.
   232      */
   233     public void setDir(String dir) {
   234         this.dir = dir;
   235     }
   236     
   237     /** Setter for property onclick.
   238      * @param onclick New value of property onclick.
   239      */
   240     public void setOnclick(String onclick) {
   241         this.onclick = onclick;
   242     }
   243     
   244     /** Setter for property ondbclick.
   245      * @param ondbclick New value of property ondbclick.
   246      */
   247     public void setOndbclick(String ondbclick) {
   248         this.ondbclick = ondbclick;
   249     }
   250     
   251     /** Setter for property onmousedown.
   252      * @param onmousedown New value of property onmousedown.
   253      */
   254     public void setOnmousedown(String onmousedown) {
   255         this.onmousedown = onmousedown;
   256     }
   257     
   258     /** Setter for property onmouseup.
   259      * @param onmouseup New value of property onmouseup.
   260      */
   261     public void setOnmouseup(String onmouseup) {
   262         this.onmouseup = onmouseup;
   263     }
   264     
   265     /** Setter for property onmouseover.
   266      * @param onmouseover New value of property onmouseover.
   267      */
   268     public void setOnmouseover(String onmouseover) {
   269         this.onmouseover = onmouseover;
   270     }
   271     
   272     /** Setter for property onmousemove.
   273      * @param onmousemove New value of property onmousemove.
   274      */
   275     public void setOnmousemove(String onmousemove) {
   276         this.onmousemove = onmousemove;
   277     }
   278     
   279     /** Setter for property onmouseout.
   280      * @param onmouseout New value of property onmouseout.
   281      */
   282     public void setOnmouseout(String onmouseout) {
   283         this.onmouseout = onmouseout;
   284     }
   285     
   286     /** Setter for property onkeypress.
   287      * @param onkeypress New value of property onkeypress.
   288      */
   289     public void setOnkeypress(String onkeypress) {
   290         this.onkeypress = onkeypress;
   291     }
   292     
   293     /** Setter for property onkeydown.
   294      * @param onkeydown New value of property onkeydown.
   295      */
   296     public void setOnkeydown(String onkeydown) {
   297         this.onkeydown = onkeydown;
   298     }
   299     
   300     /** Setter for property onkeyup.
   301      * @param onkeyup New value of property onkeyup.
   302      */
   303     public void setOnkeyup(String onkeyup) {
   304         this.onkeyup = onkeyup;
   305     }
   306     
   307 }