001/*
002 * Copyright 2008 The Kuali Foundation
003 * 
004 * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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 */
016package org.kuali.ole.sys.document.web.renderers;
017
018import java.io.IOException;
019
020import javax.servlet.jsp.JspException;
021import javax.servlet.jsp.JspWriter;
022import javax.servlet.jsp.PageContext;
023import javax.servlet.jsp.tagext.Tag;
024
025import org.kuali.ole.sys.document.web.AccountingLineTable;
026
027/**
028 * Renders a table
029 */
030public class TableRenderer implements Renderer {
031    AccountingLineTable table;
032
033    /**
034     * Clears out the table
035     * @see org.kuali.ole.sys.document.web.renderers.Renderer#clear()
036     */
037    public void clear() {
038        table = null;
039    }
040
041    /**
042     * 
043     * @see org.kuali.ole.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
044     */
045    public void render(PageContext pageContext, Tag parentTag) throws JspException {
046        JspWriter out = pageContext.getOut();
047        try {
048            out.write(buildBeginningTableTag());
049            table.renderChildrenRows(pageContext, parentTag);
050            out.write(buildEndingTableTag());
051        }
052        catch (IOException ioe) {
053            throw new JspException("Difficulty with rendering inner table", ioe);
054        }
055    }
056    
057    /**
058     * Builds the opening tag of the table, ie <table class="datatable">
059     * @return the String for the opening tag
060     */
061    protected String buildBeginningTableTag() {
062        return "<table class=\"datatable\">";
063    }
064    
065    /**
066     * Builds the closing tag of the table, ie </table>
067     * @return the String for the closing tag
068     */
069    protected String buildEndingTableTag() {
070        return "</table>";
071    }
072
073    /**
074     * Gets the table attribute. 
075     * @return Returns the table.
076     */
077    public AccountingLineTable getTable() {
078        return table;
079    }
080
081    /**
082     * Sets the table attribute value.
083     * @param table The table to set.
084     */
085    public void setTable(AccountingLineTable table) {
086        this.table = table;
087    }
088}