001 /* 002 * Copyright 2011 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 */ 016 package org.kuali.kfs.sys.document.web.renderers; 017 018 import java.io.IOException; 019 020 import javax.servlet.jsp.JspException; 021 import javax.servlet.jsp.JspWriter; 022 import javax.servlet.jsp.PageContext; 023 import javax.servlet.jsp.tagext.Tag; 024 025 import org.kuali.kfs.sys.document.web.AccountingLineTableRow; 026 027 /** 028 * Renders a row within a table 029 */ 030 public class TableRowRenderer implements Renderer { 031 private AccountingLineTableRow row; 032 033 /** 034 * Resets the table row. 035 * @see org.kuali.kfs.sys.document.web.renderers.Renderer#clear() 036 */ 037 public void clear() { 038 row = null; 039 } 040 041 /** 042 * 043 * @see org.kuali.kfs.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 if (row.getChildCellCount() > 0) { 049 out.write(buildBeginningRowTag()); 050 row.renderChildrenCells(pageContext, parentTag); 051 out.write(buildEndingRowTag()); 052 } 053 } 054 catch (IOException ioe) { 055 throw new JspException("Could not render table row", ioe); 056 } 057 } 058 059 /** 060 * 061 * @return 062 */ 063 protected String buildBeginningRowTag() { 064 return "<tr>"; 065 } 066 067 /** 068 * 069 * @return 070 */ 071 protected String buildEndingRowTag() { 072 return "</tr>"; 073 } 074 075 /** 076 * Gets the row attribute. 077 * @return Returns the row. 078 */ 079 public AccountingLineTableRow getRow() { 080 return row; 081 } 082 083 /** 084 * Sets the row attribute value. 085 * @param row The row to set. 086 */ 087 public void setRow(AccountingLineTableRow row) { 088 this.row = row; 089 } 090 }