View Javadoc
1   /*
2    * Copyright 2008 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.sys.document.web.renderers;
17  
18  import java.io.IOException;
19  
20  import javax.servlet.jsp.JspException;
21  import javax.servlet.jsp.JspWriter;
22  import javax.servlet.jsp.PageContext;
23  import javax.servlet.jsp.tagext.Tag;
24  
25  import org.apache.struts.taglib.bean.WriteTag;
26  import org.kuali.ole.sys.context.SpringContext;
27  import org.kuali.rice.core.api.config.property.ConfigurationService;
28  
29  /**
30   * The standard renderer of totals for an accounting line group
31   */
32  public class GroupTotalRenderer extends TotalRendererBase {
33      private String totalProperty;
34      private WriteTag writeTag = new WriteTag();
35      
36      private String totalLabelProperty = "accounting.line.group.total.label";
37      private String formName = "KualiForm";
38      
39      /**
40       * Constructs a GroupTotalRenderer, setting permanent values on the writeTag tag
41       */
42      public GroupTotalRenderer() {
43          writeTag.setName(formName);
44      }
45  
46      /**
47       * Gets the totalProperty attribute. 
48       * @return Returns the totalProperty.
49       */
50      public String getTotalProperty() {
51          return totalProperty;
52      }
53  
54      /**
55       * Sets the totalProperty attribute value.
56       * @param totalProperty The totalProperty to set.
57       */
58      public void setTotalProperty(String totalProperty) {
59          this.totalProperty = totalProperty;
60      }
61  
62      /**
63       * Gets the totalLabelProperty attribute. 
64       * @return Returns the totalLabelProperty.
65       */
66      public String getTotalLabelProperty() {
67          return totalLabelProperty;
68      }
69  
70      /**
71       * Sets the totalLabelProperty attribute value.
72       * @param totalLabelProperty The totalLabelProperty to set.
73       */
74      public void setTotalLabelProperty(String totalLabelProperty) {
75          this.totalLabelProperty = totalLabelProperty;
76      }
77  
78      /**
79       * Clears out the totalProperty
80       * @see org.kuali.ole.sys.document.web.renderers.Renderer#clear()
81       */
82      public void clear() {
83          super.clear();
84          totalProperty = null;
85          
86          writeTag.setPageContext(null);
87          writeTag.setParent(null);
88          writeTag.setProperty(null);
89      }
90  
91      /**
92       * Uses a Struts write tag to dump out the total
93       * @see org.kuali.ole.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
94       */
95      public void render(PageContext pageContext, Tag parentTag) throws JspException {
96          JspWriter out = pageContext.getOut();
97          
98          try {
99              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("\">&nbsp;</td>");
105             
106             out.write("<td class=\"total-line\" style=\"border-left: 0px;\">");
107             
108             out.write("<strong>");
109             
110             out.write(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(totalLabelProperty));
111             out.write("&nbsp;");
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("\">&nbsp;</td>");
128             }
129             
130             out.write("</tr>");
131         }
132         catch (IOException ioe) {
133             throw new JspException("Difficulty rendering group total", ioe);
134         }
135     }
136 }