1 package net.sf.statcvs.renderer;
2
3 import net.sf.statcvs.model.Author;
4 import net.sf.statcvs.model.Directory;
5 import net.sf.statcvs.model.VersionedFile;
6 import net.sf.statcvs.output.WebRepositoryIntegration;
7 import net.sf.statcvs.pages.MarkupSyntax;
8 import net.sf.statcvs.pages.xml.XML;
9
10
11
12
13
14
15
16
17 public class XMLRenderer implements TableCellRenderer {
18 private String xml = null;
19 private MarkupSyntax output = null;
20
21
22
23
24
25 public void renderCell(final String content) {
26 xml = content;
27 }
28
29
30
31
32 public void renderEmptyCell() {
33 xml = null;
34 }
35
36
37
38
39
40 public void renderIntegerCell(final int value) {
41 xml = Integer.toString(value);
42 }
43
44
45
46
47
48
49
50 public void renderIntegerCell(final int value, final int total) {
51 xml = Integer.toString(value) + " (" + getPercentage((double) value / (double) total) + ")";
52 }
53
54
55
56
57
58 public void renderPercentageCell(final double ratio) {
59 xml = getPercentage(ratio);
60 }
61
62
63
64
65
66 public void renderAuthorCell(final Author author) {
67 xml = XML.escape(author.getName());
68 }
69
70
71
72
73
74 public void renderDirectoryCell(final Directory directory) {
75 xml = XML.getDirectoryLink(directory);
76 }
77
78
79
80
81
82
83
84 public void renderFileCell(final VersionedFile file, final boolean withIcon, final WebRepositoryIntegration webRepository) {
85
86 xml = file.getFilenameWithPath();
87
88
89
90
91
92
93
94
95
96
97
98 }
99
100
101
102
103 public void renderLinkCell(final String url, final String label) {
104 this.xml = XML.getLink(url, label);
105 }
106
107
108
109
110
111 public String getColumnHead() {
112 return getHtml();
113 }
114
115
116
117
118
119
120 public String getRowHead() {
121 return getHtml();
122 }
123
124
125
126
127
128
129 public String getTableCell() {
130 return xml;
131 }
132
133 private String getPercentage(final double ratio) {
134 if (Double.isNaN(ratio)) {
135 return "-";
136 }
137 final int percentTimes10 = (int) Math.round(ratio * 1000);
138 final double percent = percentTimes10 / 10.0;
139 return Double.toString(percent) + "%";
140 }
141
142 private String getHtml() {
143 return xml.replaceAll(" ", "");
144 }
145
146
147
148
149 public MarkupSyntax getOutput() {
150 return output;
151 }
152
153
154
155
156 public void setOutput(final MarkupSyntax output) {
157 this.output = output;
158 }
159
160 public String getOddRowFormat() {
161 return " class=\"even\"";
162 }
163
164 public String getEvenRowFormat() {
165 return " class=\"odd\"";
166 }
167
168 public void renderAuthorIdCell(final Author author) {
169 xml = XML.getAuthorIdLink(author);
170 }
171 }