001: /* ================================================================
002: * Cewolf : Chart enabling Web Objects Framework
003: * ================================================================
004: *
005: * Project Info: http://cewolf.sourceforge.net
006: * Project Lead: Guido Laures (guido@laures.de);
007: *
008: * (C) Copyright 2002, by Guido Laures
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of
013: * the License, or (at your option) any later version.
014: *
015: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
016: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
017: * See the GNU Lesser General Public License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public License along with this
020: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
021: * Boston, MA 02111-1307, USA.
022: */
023:
024: package de.laures.cewolf.taglib.html;
025:
026: import java.io.IOException;
027: import java.io.Serializable;
028: import java.io.Writer;
029:
030: import javax.servlet.jsp.JspException;
031: import javax.servlet.jsp.JspWriter;
032:
033: import de.laures.cewolf.taglib.tags.CewolfBodyTag;
034:
035: /**
036: * Abstract base class which holds attribbutes common for all HTML 4.0 tags.
037: * @author Guido Laures
038: */
039: public abstract class AbstractHTMLBaseTag extends CewolfBodyTag
040: implements Serializable {
041:
042: protected static final int UNDEFINED_INT = -1;
043: protected static final float UNDEFINED_FLOAT = -1.0f;
044: protected static final String UNDEFINED_STR = null;
045:
046: /** Holds value of property ID. */
047: protected String id = UNDEFINED_STR;
048:
049: /** Holds value of property clazz. */
050: protected String clazz = UNDEFINED_STR;
051:
052: /** Holds value of property style. */
053: protected String style = UNDEFINED_STR;
054:
055: /** Holds value of property title. */
056: protected String title = UNDEFINED_STR;
057:
058: /** Holds value of property lang. */
059: protected String lang = UNDEFINED_STR;
060:
061: /** Holds value of property dir. */
062: protected String dir = UNDEFINED_STR;
063:
064: /** Holds value of property onclick. */
065: protected String onclick = UNDEFINED_STR;
066:
067: /** Holds value of property ondbclick. */
068: protected String ondbclick = UNDEFINED_STR;
069:
070: /** Holds value of property onmousedown. */
071: protected String onmousedown = UNDEFINED_STR;
072:
073: /** Holds value of property onmouseup. */
074: protected String onmouseup = UNDEFINED_STR;
075:
076: /** Holds value of property onmouseover. */
077: protected String onmouseover = UNDEFINED_STR;
078:
079: /** Holds value of property onmousemove. */
080: protected String onmousemove = UNDEFINED_STR;
081:
082: /** Holds value of property onmouseout. */
083: protected String onmouseout = UNDEFINED_STR;
084:
085: /** Holds value of property onkeypress. */
086: protected String onkeypress = UNDEFINED_STR;
087:
088: /** Holds value of property onkeydown. */
089: protected String onkeydown = UNDEFINED_STR;
090:
091: /** Holds value of property onkeyup. */
092: protected String onkeyup = UNDEFINED_STR;
093:
094: public AbstractHTMLBaseTag() {
095: setId(UNDEFINED_STR);
096: }
097:
098: protected abstract String getTagName();
099:
100: protected abstract boolean hasBody();
101:
102: protected abstract boolean wellFormed();
103:
104: protected void reset() {
105: this .clazz = UNDEFINED_STR;
106: this .dir = UNDEFINED_STR;
107: this .id = UNDEFINED_STR;
108: this .lang = UNDEFINED_STR;
109: this .onclick = UNDEFINED_STR;
110: this .ondbclick = UNDEFINED_STR;
111: this .onkeydown = UNDEFINED_STR;
112: this .onkeypress = UNDEFINED_STR;
113: this .onkeyup = UNDEFINED_STR;
114: this .onmousedown = UNDEFINED_STR;
115: this .onmousemove = UNDEFINED_STR;
116: this .onmouseout = UNDEFINED_STR;
117: this .onmouseover = UNDEFINED_STR;
118: this .onmouseup = UNDEFINED_STR;
119: this .style = UNDEFINED_STR;
120: this .title = UNDEFINED_STR;
121: }
122:
123: public int doStartTag() throws JspException {
124: JspWriter writer = pageContext.getOut();
125: try {
126: writer.write("<" + getTagName());
127: writeAttributes(writer);
128: if (hasBody()) {
129: writer.write(">");
130: return EVAL_PAGE;
131: } else {
132: return SKIP_BODY;
133: }
134: } catch (IOException ioe) {
135: super .pageContext.getServletContext().log("", ioe);
136: throw new JspException(ioe.getMessage());
137: }
138: }
139:
140: public int doEndTag() throws JspException {
141: JspWriter writer = pageContext.getOut();
142: try {
143: if (hasBody()) {
144: writer.write("</" + getTagName() + ">");
145: } else {
146: if (wellFormed()) {
147: writer.write(" /");
148: }
149: writer.write(">");
150: }
151: return doAfterEndTag(EVAL_PAGE);
152: } catch (IOException ioe) {
153: super .pageContext.getServletContext().log("", ioe);
154: throw new JspException(ioe.getMessage());
155: }
156: }
157:
158: public void writeAttributes(Writer wr) {
159: try {
160: appendAttributeDeclaration(wr, getId(), "ID");
161: appendAttributeDeclaration(wr, this .clazz, "CLASS");
162: appendAttributeDeclaration(wr, this .style, "STYLE");
163: appendAttributeDeclaration(wr, this .onclick, "ONCLICK");
164: appendAttributeDeclaration(wr, this .ondbclick, "ONDBCLICK");
165: appendAttributeDeclaration(wr, this .onkeydown, "ONKEYDOWN");
166: appendAttributeDeclaration(wr, this .onkeypress,
167: "ONKEYPRESS");
168: appendAttributeDeclaration(wr, this .onkeyup, "ONKEYUP");
169: appendAttributeDeclaration(wr, this .onmousedown,
170: "ONMOUSEDOWN");
171: appendAttributeDeclaration(wr, this .onmousemove,
172: "ONMOUSEMOVE");
173: appendAttributeDeclaration(wr, this .onmouseout,
174: "ONMOUSEOUT");
175: appendAttributeDeclaration(wr, this .onmouseover,
176: "ONMOUSEOVER");
177: appendAttributeDeclaration(wr, this .onmouseup, "ONMOUSEUP");
178: appendAttributeDeclaration(wr, this .title, "TITLE");
179: appendAttributeDeclaration(wr, this .lang, "LANG");
180: appendAttributeDeclaration(wr, this .dir, "DIR");
181: } catch (IOException ioex) {
182: ioex.printStackTrace();
183: }
184: }
185:
186: protected void appendAttributeDeclaration(Writer wr, String attr,
187: String name) throws IOException {
188: if (attr != UNDEFINED_STR) {
189: wr.write(" " + name + "=\"" + attr + "\"");
190: }
191: }
192:
193: protected void appendAttributeDeclaration(Writer wr, int attr,
194: String name) throws IOException {
195: // does not call the according method for Strings to avoid additional
196: // String instantiation
197: if (attr != UNDEFINED_INT) {
198: wr.write(" " + name + "=\"" + attr + "\"");
199: }
200: }
201:
202: protected void appendAttributeDeclaration(Writer wr, float attr,
203: String name) throws IOException {
204: // does not call the according method for Strings to avoid additional
205: // String instantiation
206: if (attr != UNDEFINED_FLOAT) {
207: wr.write(" " + name + "=\"" + attr + "\"");
208: }
209: }
210:
211: /** Setter for property clazz.
212: * @param clazz New value of property clazz.
213: */
214: public void setClass(String clazz) {
215: this .clazz = clazz;
216: }
217:
218: /** Setter for property style.
219: * @param style New value of property style.
220: */
221: public void setStyle(String style) {
222: this .style = style;
223: }
224:
225: /** Setter for property title.
226: * @param title New value of property title.
227: */
228: public void setHtmltitle(String title) {
229: this .title = title;
230: }
231:
232: /** Setter for property lang.
233: * @param lang New value of property lang.
234: */
235: public void setLang(String lang) {
236: this .lang = lang;
237: }
238:
239: /** Setter for property dir.
240: * @param dir New value of property dir.
241: */
242: public void setDir(String dir) {
243: this .dir = dir;
244: }
245:
246: /** Setter for property onclick.
247: * @param onclick New value of property onclick.
248: */
249: public void setOnclick(String onclick) {
250: this .onclick = onclick;
251: }
252:
253: /** Setter for property ondbclick.
254: * @param ondbclick New value of property ondbclick.
255: */
256: public void setOndbclick(String ondbclick) {
257: this .ondbclick = ondbclick;
258: }
259:
260: /** Setter for property onmousedown.
261: * @param onmousedown New value of property onmousedown.
262: */
263: public void setOnmousedown(String onmousedown) {
264: this .onmousedown = onmousedown;
265: }
266:
267: /** Setter for property onmouseup.
268: * @param onmouseup New value of property onmouseup.
269: */
270: public void setOnmouseup(String onmouseup) {
271: this .onmouseup = onmouseup;
272: }
273:
274: /** Setter for property onmouseover.
275: * @param onmouseover New value of property onmouseover.
276: */
277: public void setOnmouseover(String onmouseover) {
278: this .onmouseover = onmouseover;
279: }
280:
281: /** Setter for property onmousemove.
282: * @param onmousemove New value of property onmousemove.
283: */
284: public void setOnmousemove(String onmousemove) {
285: this .onmousemove = onmousemove;
286: }
287:
288: /** Setter for property onmouseout.
289: * @param onmouseout New value of property onmouseout.
290: */
291: public void setOnmouseout(String onmouseout) {
292: this .onmouseout = onmouseout;
293: }
294:
295: /** Setter for property onkeypress.
296: * @param onkeypress New value of property onkeypress.
297: */
298: public void setOnkeypress(String onkeypress) {
299: this .onkeypress = onkeypress;
300: }
301:
302: /** Setter for property onkeydown.
303: * @param onkeydown New value of property onkeydown.
304: */
305: public void setOnkeydown(String onkeydown) {
306: this .onkeydown = onkeydown;
307: }
308:
309: /** Setter for property onkeyup.
310: * @param onkeyup New value of property onkeyup.
311: */
312: public void setOnkeyup(String onkeyup) {
313: this.onkeyup = onkeyup;
314: }
315:
316: }
|