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  public class DebitCreditTotalRenderer extends TotalRendererBase {
30      private String debitTotalProperty;
31      private String creditTotalProperty;
32      private String representedProperty;
33      
34      private String debitTotalLabelProperty = "accounting.line.group.debitTotal.label";
35      private String creditTotalLabelProperty = "accounting.line.group.creditTotal.label";
36      
37      private String formName = "KualiForm";   
38      
39      private WriteTag debitWriteTag = new WriteTag();
40      private WriteTag creditWriteTag = new WriteTag();
41      
42      /**
43       * Constructs a GroupTotalRenderer, setting permanent values on the writeTag tag
44       */
45      public DebitCreditTotalRenderer() {
46          debitWriteTag.setName(formName);
47          creditWriteTag.setName(formName);
48      }
49  
50      /**
51       * Clears out the totalProperty
52       * @see org.kuali.ole.sys.document.web.renderers.Renderer#clear()
53       */
54      public void clear() {
55          super.clear();
56          debitTotalProperty = null;
57          creditTotalProperty = null;
58          representedProperty = null;
59          
60          debitWriteTag.setPageContext(null);
61          debitWriteTag.setParent(null);
62          debitWriteTag.setProperty(null);
63          
64          creditWriteTag.setPageContext(null);
65          creditWriteTag.setParent(null);
66          creditWriteTag.setProperty(null);
67      }
68  
69      /**
70       * Uses a Struts write tag to dump out the total
71       * @see org.kuali.ole.sys.document.web.renderers.Renderer#render(javax.servlet.jsp.PageContext, javax.servlet.jsp.tagext.Tag)
72       */
73      public void render(PageContext pageContext, Tag parentTag) throws JspException {
74          JspWriter out = pageContext.getOut();
75          
76          try {
77              out.write("<tr>");
78              
79              final int emptyCellSpanBefore = this.getColumnNumberOfRepresentedCell() - 1;
80              out.write("<td  class=\"total-line\" colspan=\"");
81              out.write(Integer.toString(emptyCellSpanBefore));
82              out.write("\">&nbsp;</td>");
83              
84              out.write("<td class=\"total-line\" style=\"border-left: 0px; white-space:nowrap;\">");            
85              out.write("<strong>");
86              
87              out.write(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(debitTotalLabelProperty));
88              out.write("&nbsp;");
89              
90              debitWriteTag.setPageContext(pageContext);
91              debitWriteTag.setParent(parentTag);
92              debitWriteTag.setProperty(debitTotalProperty);
93              debitWriteTag.doStartTag();
94              debitWriteTag.doEndTag();
95              
96              out.write("</strong>");            
97              out.write("</td>");
98              
99              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("&nbsp;");
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("\">&nbsp;</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 }