1 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 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 46 protected String id = UNDEFINED_STR; 47 48 49 protected String clazz = UNDEFINED_STR; 50 51 52 protected String style = UNDEFINED_STR; 53 54 55 protected String title = UNDEFINED_STR; 56 57 58 protected String lang = UNDEFINED_STR; 59 60 61 protected String dir = UNDEFINED_STR; 62 63 64 protected String onclick = UNDEFINED_STR; 65 66 67 protected String ondbclick = UNDEFINED_STR; 68 69 70 protected String onmousedown = UNDEFINED_STR; 71 72 73 protected String onmouseup = UNDEFINED_STR; 74 75 76 protected String onmouseover = UNDEFINED_STR; 77 78 79 protected String onmousemove = UNDEFINED_STR; 80 81 82 protected String onmouseout = UNDEFINED_STR; 83 84 85 protected String onkeypress = UNDEFINED_STR; 86 87 88 protected String onkeydown = UNDEFINED_STR; 89 90 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 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 if(attr != UNDEFINED_FLOAT){ 198 wr.write(" " + name + "=\"" + attr + "\""); 199 } 200 } 201 202 205 public void setClass(String clazz) { 206 this.clazz = clazz; 207 } 208 209 212 public void setStyle(String style) { 213 this.style = style; 214 } 215 216 219 public void setHtmltitle(String title) { 220 this.title = title; 221 } 222 223 226 public void setLang(String lang) { 227 this.lang = lang; 228 } 229 230 233 public void setDir(String dir) { 234 this.dir = dir; 235 } 236 237 240 public void setOnclick(String onclick) { 241 this.onclick = onclick; 242 } 243 244 247 public void setOndbclick(String ondbclick) { 248 this.ondbclick = ondbclick; 249 } 250 251 254 public void setOnmousedown(String onmousedown) { 255 this.onmousedown = onmousedown; 256 } 257 258 261 public void setOnmouseup(String onmouseup) { 262 this.onmouseup = onmouseup; 263 } 264 265 268 public void setOnmouseover(String onmouseover) { 269 this.onmouseover = onmouseover; 270 } 271 272 275 public void setOnmousemove(String onmousemove) { 276 this.onmousemove = onmousemove; 277 } 278 279 282 public void setOnmouseout(String onmouseout) { 283 this.onmouseout = onmouseout; 284 } 285 286 289 public void setOnkeypress(String onkeypress) { 290 this.onkeypress = onkeypress; 291 } 292 293 296 public void setOnkeydown(String onkeydown) { 297 this.onkeydown = onkeydown; 298 } 299 300 303 public void setOnkeyup(String onkeyup) { 304 this.onkeyup = onkeyup; 305 } 306 307 } 308 | Popular Tags |