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.apache.struts.taglib.bean.WriteTag;
026 import org.kuali.kfs.sys.context.SpringContext;
027 import org.kuali.rice.kns.service.KualiConfigurationService;
028
029 /**
030 * The standard renderer of totals for an accounting line group
031 */
032 public class GroupTotalRenderer extends TotalRendererBase {
033 private String totalProperty;
034 private WriteTag writeTag = new WriteTag();
035
036 private String totalLabelProperty = "accounting.line.group.total.label";
037 private String formName = "KualiForm";
038
039 /**
040 * Constructs a GroupTotalRenderer, setting permanent values on the writeTag tag
041 */
042 public GroupTotalRenderer() {
043 writeTag.setName(formName);
044 }
045
046 /**
047 * Gets the totalProperty attribute.
048 * @return Returns the totalProperty.
049 */
050 public String getTotalProperty() {
051 return totalProperty;
052 }
053
054 /**
055 * Sets the totalProperty attribute value.
056 * @param totalProperty The totalProperty to set.
057 */
058 public void setTotalProperty(String totalProperty) {
059 this.totalProperty = totalProperty;
060 }
061
062 /**
063 * Gets the totalLabelProperty attribute.
064 * @return Returns the totalLabelProperty.
065 */
066 public String getTotalLabelProperty() {
067 return totalLabelProperty;
068 }
069
070 /**
071 * Sets the totalLabelProperty attribute value.
072 * @param totalLabelProperty The totalLabelProperty to set.
073 */
074 public void setTotalLabelProperty(String totalLabelProperty) {
075 this.totalLabelProperty = totalLabelProperty;
076 }
077
078 /**
079 * Clears out the totalProperty
080 * @see org.kuali.kfs.sys.document.web.renderers.Renderer#clear()
081 */
082 public void clear() {
083 super.clear();
084 totalProperty = null;
085
086 writeTag.setPageContext(null);
087 writeTag.setParent(null);
088 writeTag.setProperty(null);
089 }
090
091 /**
092 * Uses a Struts write tag to dump out the total
093 * @see org.kuali.kfs.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
094 */
095 public void render(PageContext pageContext, Tag parentTag) throws JspException {
096 JspWriter out = pageContext.getOut();
097
098 try {
099 out.write("<tr>");
100
101 final int emptyCellSpanBefore = this.getColumnNumberOfRepresentedCell() - 1;
102 out.write("<td class=\"total-line\" colspan=\"");
103 out.write(Integer.toString(emptyCellSpanBefore));
104 out.write("\"> </td>");
105
106 out.write("<td class=\"total-line\" style=\"border-left: 0px;\">");
107
108 out.write("<strong>");
109
110 out.write(SpringContext.getBean(KualiConfigurationService.class).getPropertyString(totalLabelProperty));
111 out.write(" ");
112
113 writeTag.setPageContext(pageContext);
114 writeTag.setParent(parentTag);
115 writeTag.setProperty(getTotalProperty());
116 writeTag.doStartTag();
117 writeTag.doEndTag();
118
119 out.write("</strong>");
120
121 out.write("</td>");
122
123 final int emptyCellSpanAfter = this.getCellCount() - this.getColumnNumberOfRepresentedCell();
124 if(emptyCellSpanAfter > 0) {
125 out.write("<td class=\"total-line\" style=\"border-left: 0px;\" colspan=\"");
126 out.write(Integer.toString(emptyCellSpanAfter));
127 out.write("\"> </td>");
128 }
129
130 out.write("</tr>");
131 }
132 catch (IOException ioe) {
133 throw new JspException("Difficulty rendering group total", ioe);
134 }
135 }
136 }