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.apache.struts.taglib.bean.WriteTag; 026import org.kuali.ole.sys.context.SpringContext; 027import org.kuali.rice.core.api.config.property.ConfigurationService; 028 029public class DebitCreditTotalRenderer extends TotalRendererBase { 030 private String debitTotalProperty; 031 private String creditTotalProperty; 032 private String representedProperty; 033 034 private String debitTotalLabelProperty = "accounting.line.group.debitTotal.label"; 035 private String creditTotalLabelProperty = "accounting.line.group.creditTotal.label"; 036 037 private String formName = "KualiForm"; 038 039 private WriteTag debitWriteTag = new WriteTag(); 040 private WriteTag creditWriteTag = new WriteTag(); 041 042 /** 043 * Constructs a GroupTotalRenderer, setting permanent values on the writeTag tag 044 */ 045 public DebitCreditTotalRenderer() { 046 debitWriteTag.setName(formName); 047 creditWriteTag.setName(formName); 048 } 049 050 /** 051 * Clears out the totalProperty 052 * @see org.kuali.ole.sys.document.web.renderers.Renderer#clear() 053 */ 054 public void clear() { 055 super.clear(); 056 debitTotalProperty = null; 057 creditTotalProperty = null; 058 representedProperty = null; 059 060 debitWriteTag.setPageContext(null); 061 debitWriteTag.setParent(null); 062 debitWriteTag.setProperty(null); 063 064 creditWriteTag.setPageContext(null); 065 creditWriteTag.setParent(null); 066 creditWriteTag.setProperty(null); 067 } 068 069 /** 070 * Uses a Struts write tag to dump out the total 071 * @see org.kuali.ole.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag) 072 */ 073 public void render(PageContext pageContext, Tag parentTag) throws JspException { 074 JspWriter out = pageContext.getOut(); 075 076 try { 077 out.write("<tr>"); 078 079 final int emptyCellSpanBefore = this.getColumnNumberOfRepresentedCell() - 1; 080 out.write("<td class=\"total-line\" colspan=\""); 081 out.write(Integer.toString(emptyCellSpanBefore)); 082 out.write("\"> </td>"); 083 084 out.write("<td class=\"total-line\" style=\"border-left: 0px; white-space:nowrap;\">"); 085 out.write("<strong>"); 086 087 out.write(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(debitTotalLabelProperty)); 088 out.write(" "); 089 090 debitWriteTag.setPageContext(pageContext); 091 debitWriteTag.setParent(parentTag); 092 debitWriteTag.setProperty(debitTotalProperty); 093 debitWriteTag.doStartTag(); 094 debitWriteTag.doEndTag(); 095 096 out.write("</strong>"); 097 out.write("</td>"); 098 099 out.write("<td class=\"total-line\" style=\"border-left: 0px; white-space:nowrap;\">"); 100 out.write("<strong>"); 101 102 out.write(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(creditTotalLabelProperty)); 103 out.write(" "); 104 105 creditWriteTag.setPageContext(pageContext); 106 creditWriteTag.setParent(parentTag); 107 creditWriteTag.setProperty(creditTotalProperty); 108 creditWriteTag.doStartTag(); 109 creditWriteTag.doEndTag(); 110 111 out.write("</strong>"); 112 out.write("</td>"); 113 114 final int emptyCellSpanAfter = this.getCellCount() - this.getColumnNumberOfRepresentedCell() - 1; 115 if(emptyCellSpanAfter > 0) { 116 out.write("<td class=\"total-line\" style=\"border-left: 0px;\" colspan=\""); 117 out.write(Integer.toString(emptyCellSpanAfter)); 118 out.write("\"> </td>"); 119 } 120 121 out.write("</tr>"); 122 } 123 catch (IOException ioe) { 124 throw new JspException("Difficulty rendering debit credit totals", ioe); 125 } 126 } 127 128 /** 129 * Gets the debitTotalProperty attribute. 130 * @return Returns the debitTotalProperty. 131 */ 132 public String getDebitTotalProperty() { 133 return debitTotalProperty; 134 } 135 136 /** 137 * Sets the debitTotalProperty attribute value. 138 * @param debitTotalProperty The debitTotalProperty to set. 139 */ 140 public void setDebitTotalProperty(String debitTotalProperty) { 141 this.debitTotalProperty = debitTotalProperty; 142 } 143 144 /** 145 * Gets the creditTotalProperty attribute. 146 * @return Returns the creditTotalProperty. 147 */ 148 public String getCreditTotalProperty() { 149 return creditTotalProperty; 150 } 151 152 /** 153 * Sets the creditTotalProperty attribute value. 154 * @param creditTotalProperty The creditTotalProperty to set. 155 */ 156 public void setCreditTotalProperty(String creditTotalProperty) { 157 this.creditTotalProperty = creditTotalProperty; 158 } 159 160 /** 161 * Gets the debitTotalLabelProperty attribute. 162 * @return Returns the debitTotalLabelProperty. 163 */ 164 public String getDebitTotalLabelProperty() { 165 return debitTotalLabelProperty; 166 } 167 168 /** 169 * Sets the debitTotalLabelProperty attribute value. 170 * @param debitTotalLabelProperty The debitTotalLabelProperty to set. 171 */ 172 public void setDebitTotalLabelProperty(String debitTotalLabelProperty) { 173 this.debitTotalLabelProperty = debitTotalLabelProperty; 174 } 175 176 /** 177 * Gets the creditTotalLabelProperty attribute. 178 * @return Returns the creditTotalLabelProperty. 179 */ 180 public String getCreditTotalLabelProperty() { 181 return creditTotalLabelProperty; 182 } 183 184 /** 185 * Sets the creditTotalLabelProperty attribute value. 186 * @param creditTotalLabelProperty The creditTotalLabelProperty to set. 187 */ 188 public void setCreditTotalLabelProperty(String creditTotalLabelProperty) { 189 this.creditTotalLabelProperty = creditTotalLabelProperty; 190 } 191}