KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > workflow > taglib > ElementTag


1 /* ===============================================================================
2 *
3 * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4 *
5 * ===============================================================================
6 *
7 * Copyright (C)
8 *
9 * This program is free software; you can redistribute it and/or modify it under
10 * the terms of the GNU General Public License version 2, as published by the
11 * Free Software Foundation. See the file LICENSE.html for more information.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19 * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20 *
21 * ===============================================================================
22 */

23 package org.infoglue.cms.workflow.taglib;
24
25 import javax.servlet.jsp.JspException JavaDoc;
26
27 /**
28  * Base class for all workflow related tags writing to the output stream.
29  *
30  * An <code>Element</code> is used for constructing the output.
31  */

32 public abstract class ElementTag extends WorkflowTag
33 {
34     /**
35      * The element used for constructing the output.
36      */

37     private Element element;
38     
39     /**
40      * Default constructor.
41      */

42     ElementTag()
43     {
44         super();
45     }
46     
47     /**
48      * Process the end tag. Writes the element to the output stream.
49      *
50      * @return indication of whether to continue evaluating the JSP page.
51      * @throws JspException if an I/O error occurs when writing to the output stream.
52      */

53     public int doEndTag() throws JspException JavaDoc
54     {
55         if(getElement() != null)
56         {
57             write(getElement().toString());
58         }
59         element = null;
60         return EVAL_PAGE;
61     }
62     
63     /**
64      * Returns the element used for constructing the output.
65      *
66      * @return the element used for constructing the output.
67      */

68     protected final Element getElement()
69     {
70         if(element == null)
71         {
72             element = createElement();
73         }
74         return element;
75     }
76     
77     /**
78      * Creates the element used for constructing the output.
79      *
80      * @return the element used for constructing the output.
81      */

82     protected abstract Element createElement();
83
84     // -------------------------------------------------------------------------
85
// --- core html attributes ------------------------------------------------
86
// -------------------------------------------------------------------------
87

88     /**
89      * Sets the id attribute of the html element.
90      *
91      * @param id the id to use.
92      * @throws JspException if an error occurs while evaluating the attribute.
93      */

94     public void setIdAttr(final String JavaDoc id) throws JspException JavaDoc
95     {
96         getElement().addAttribute("id", evaluateString("element", "idAttr", id));
97     }
98
99     /**
100      * Sets the class attribute of the html element.
101      *
102      * @param cssClass the class to use.
103      * @throws JspException if an error occurs while evaluating the attribute.
104      */

105     public void setCssClass(final String JavaDoc cssClass) throws JspException JavaDoc
106     {
107         getElement().addAttribute("class", evaluateString("element", "cssClass", cssClass));
108     }
109
110     /**
111      * Sets the title attribute of the html element.
112      *
113      * @param title the title to use.
114      * @throws JspException if an error occurs while evaluating the attribute.
115      */

116     public void setTitle(final String JavaDoc title) throws JspException JavaDoc
117     {
118         getElement().addAttribute("title", evaluateString("element", "title", title));
119     }
120
121     /**
122      * Sets the style attribute of the html element.
123      *
124      * @param style the style to use.
125      * @throws JspException if an error occurs while evaluating the attribute.
126      */

127     public void setStyle(final String JavaDoc style) throws JspException JavaDoc
128     {
129         getElement().addAttribute("style", evaluateString("element", "style", style));
130     }
131 }
132
Popular Tags