001: /**
002: * Copyright 2006 Webmedia Group Ltd.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: **/package org.araneaframework.jsp.tag.layout;
016:
017: import java.io.Writer;
018: import javax.servlet.jsp.JspException;
019: import org.araneaframework.jsp.util.JspUtil;
020:
021: /**
022: * Aranea's cell tag, represents one cell in a layout row.
023: * In HTML this tag corresponds to column inside table row -- <td> with <code>class</code>, <code>colspan</code> and <code>rowspan</code> attributes.
024: *
025: * @jsp.tag
026: * name = "cell"
027: * body-content = "JSP"
028: * description = "Represents a cell in layout."
029: *
030: * @author Taimo Peelo (taimo@araneaframework.org)
031: */
032: public class LayoutCellHtmlTag extends BaseLayoutCellTag {
033: protected String cellTag = "td";
034: protected String colspan;
035: protected String rowspan;
036: protected String width;
037: protected String height;
038:
039: protected int doStartTag(Writer out) throws Exception {
040: super .doStartTag(out);
041:
042: JspUtil.writeOpenStartTag(out, cellTag);
043: writeCellAttributes(out);
044: JspUtil.writeCloseStartTag(out);
045:
046: return EVAL_BODY_INCLUDE;
047: }
048:
049: /** Overwrite if other attributes besides <code>styleclass</code> are needed for HTML table cell. */
050: protected void writeCellAttributes(Writer out) throws Exception {
051: addAttribute("id", id);
052: addAttribute("class", getStyleClass());
053: addAttribute("style", getStyle());
054: addAttribute("colspan", colspan);
055: addAttribute("rowspan", rowspan);
056: addAttribute("width", width);
057: addAttribute("height", height);
058: JspUtil.writeAttributes(out, attributes);
059: }
060:
061: protected int doEndTag(Writer out) throws Exception {
062: JspUtil.writeEndTag(out, cellTag);
063: return super .doEndTag(out);
064: }
065:
066: /* ***********************************************************************************
067: * Tag attributes
068: * ***********************************************************************************/
069: /**
070: * @jsp.attribute
071: * type = "java.lang.String"
072: * required = "false"
073: * description = "Colspan for this cell. Same as in HTML."
074: */
075: public void setColspan(String colspan) throws JspException {
076: this .colspan = (String) evaluate("colspan", colspan,
077: String.class);
078: }
079:
080: /**
081: * @jsp.attribute
082: * type = "java.lang.String"
083: * required = "false"
084: * description = "Rowspan for this cell. Same as in HTML."
085: */
086: public void setRowspan(String rowspan) throws JspException {
087: this .rowspan = (String) evaluate("rowspan", rowspan,
088: String.class);
089: }
090:
091: /**
092: * @jsp.attribute
093: * type = "java.lang.String"
094: * required = "false"
095: * description = "Width for this cell. Same as in HTML, deprecated."
096: */
097: public void setWidth(String width) throws JspException {
098: this .width = (String) evaluate("width", width, String.class);
099: }
100:
101: /**
102: * @jsp.attribute
103: * type = "java.lang.String"
104: * required = "false"
105: * description = "Height for this cell. Same as in HTML, deprecated."
106: */
107: public void setHeight(String height) throws JspException {
108: this .height = (String) evaluate("height", height, String.class);
109: }
110:
111: /**
112: * @jsp.attribute
113: * type = "java.lang.String"
114: * required = "false"
115: * description = "Whether this cell is header cell, defaults to false. In HTML, tag is rendered with <th> or <tr>."
116: */
117: public void setHeaderCell(String headerCell) throws JspException {
118: boolean isHeaderCell = ((Boolean) evaluate("headerCell",
119: headerCell, Boolean.class)).booleanValue();
120: this .cellTag = isHeaderCell ? "th" : "td";
121: }
122: }
|