1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.commons.lang.StringUtils;
26 import org.kuali.ole.sys.document.web.AccountingLineTableCell;
27
28
29
30
31 public class TableCellRenderer implements Renderer {
32 private AccountingLineTableCell cell;
33
34
35
36
37
38 public void clear() {
39 this.cell = null;
40 }
41
42
43
44
45
46 public void render(PageContext pageContext, Tag parentTag) throws JspException {
47 JspWriter out = pageContext.getOut();
48 try {
49 out.write(buildBeginningTag());
50 if (cell.hasChildElements()) {
51 cell.renderChildrenElements(pageContext, parentTag);
52 } else {
53 out.write(" ");
54 }
55 out.write(buildEndingTag());
56 }
57 catch (IOException ioe) {
58 throw new JspException("Difficulty rendering table cell", ioe);
59 }
60 }
61
62
63
64
65
66 protected String buildBeginningTag() {
67 StringBuilder builder = new StringBuilder();
68 builder.append("<");
69 builder.append(getTagName());
70 if (cell.getColSpan() > 1) {
71 builder.append(" colspan=\"");
72 builder.append(cell.getColSpan());
73 builder.append('"');
74 }
75 if (cell.getRowSpan() > 1) {
76 builder.append(" rowspan=\"");
77 builder.append(cell.getRowSpan());
78 builder.append('"');
79 }
80 if (verticallyAlignTowardsTop()) {
81 builder.append(" valign=\"top\"");
82 }
83 if (!StringUtils.isBlank(cell.getExtraStyle())) {
84 builder.append(" style=\"");
85 builder.append(cell.getExtraStyle());
86 builder.append("\"");
87 } else {
88 builder.append(" class=\""+getStyleClass()+"\"");
89 }
90 builder.append(">\n");
91 return builder.toString();
92 }
93
94
95
96
97
98 protected String getStyleClass() {
99 return !StringUtils.isBlank(cell.getStyleClassOverride()) ? cell.getStyleClassOverride() : "infoline";
100 }
101
102
103
104
105
106 protected String buildEndingTag() {
107 StringBuilder builder = new StringBuilder();
108 builder.append("</");
109 builder.append(getTagName());
110 builder.append(">");
111 return builder.toString();
112 }
113
114
115
116
117
118 protected String getTagName() {
119 return "td";
120 }
121
122
123
124
125
126 public AccountingLineTableCell getCell() {
127 return cell;
128 }
129
130
131
132
133
134 public void setCell(AccountingLineTableCell cell) {
135 this.cell = cell;
136 }
137
138
139
140
141
142 protected boolean verticallyAlignTowardsTop() {
143 return true;
144 }
145 }