1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.testdoc.maven.export.sink;
17
18 import org.apache.maven.doxia.sink.Sink;
19
20 import de.smartics.maven.util.report.MessageHelper;
21
22
23
24
25
26
27
28 class RenderHelper
29 {
30
31
32
33
34
35
36
37
38
39
40 private final MessageHelper messages;
41
42
43
44
45 private final Sink sink;
46
47
48
49
50
51
52
53
54
55
56
57
58 public RenderHelper(final MessageHelper messages, final Sink sink)
59 {
60 this.messages = messages;
61 this.sink = sink;
62 }
63
64
65
66
67
68
69
70
71
72
73
74 void renderIndexTableStart()
75 {
76 sink.table();
77 sink.tableRow();
78 sink.tableHeaderCell(messages.getLabel("report.table.header.counter.width"));
79 final String topicLabel = messages.getLabel("report.table.header.counter");
80 sink.text(topicLabel);
81 sink.tableHeaderCell_();
82 sink.tableHeaderCell();
83 final String valueLabel = messages.getLabel("report.table.header.index");
84 sink.text(valueLabel);
85 sink.tableHeaderCell_();
86 sink.tableRow_();
87 }
88
89 void renderIndexRow(final int counter, final String label, final String id)
90 {
91 sink.tableRow();
92 sink.tableCell();
93 sink.text(String.valueOf(counter));
94 sink.tableCell_();
95 sink.tableCell();
96 renderInPageLink(label, id);
97 sink.tableCell_();
98 sink.tableRow_();
99 }
100
101 void renderIndexRow(final int counter, final String content)
102 {
103 renderIndexRow(counter, content, content);
104 }
105
106 void renderIndexTableEnd()
107 {
108 sink.table_();
109 }
110
111 void renderInPageLink(final String id)
112 {
113 final String label = messages.getLabel(id);
114 renderInPageLink(label, id);
115 }
116
117 void renderInPageLink(final String label, final String id)
118 {
119 final String link = '#' + normalizeKey(id);
120 renderLink(label, link);
121 }
122
123 void renderLink(final String label, final String link)
124 {
125 sink.link(link);
126 sink.text(label);
127 sink.link_();
128 }
129
130 void renderAnchor(final String id)
131 {
132 final String normalized = normalizeKey(id);
133 sink.anchor(normalized);
134 sink.anchor_();
135 }
136
137
138
139
140
141
142
143
144 public static String normalizeKey(final String key)
145 {
146 if (key == null || "".equals(key))
147 {
148 return key;
149 }
150
151 final char[] trimmed = key.trim().toCharArray();
152 boolean uppercase = false;
153 int currentPos = 0;
154 for (int i = 0; i < trimmed.length; i++, currentPos++)
155 {
156 final char c = trimmed[i];
157 if (Character.isWhitespace(c))
158 {
159 uppercase = true;
160 --currentPos;
161 }
162 else if (uppercase)
163 {
164 trimmed[currentPos] = Character.toUpperCase(c);
165 uppercase = false;
166 }
167 else
168 {
169 trimmed[currentPos] = c;
170 }
171 }
172
173 return new String(trimmed).substring(0, currentPos);
174 }
175
176 void renderSectionStart(final int level, final String name)
177 {
178 renderSectionStart(level);
179
180 renderAnchor(name);
181 renderSectionTitle(level, name);
182 }
183
184 private void renderSectionTitle(final int level, final String name)
185 {
186 switch (level)
187 {
188 case 1:
189 sink.sectionTitle1();
190 sink.text(name);
191 sink.sectionTitle1_();
192 break;
193 case 2:
194 sink.sectionTitle2();
195 sink.text(name);
196 sink.sectionTitle2_();
197 break;
198 case 3:
199 sink.sectionTitle3();
200 sink.text(name);
201 sink.sectionTitle3_();
202 break;
203 case 4:
204 sink.sectionTitle4();
205 sink.text(name);
206 sink.sectionTitle4_();
207 break;
208 case 5:
209 sink.sectionTitle5();
210 sink.text(name);
211 sink.sectionTitle5_();
212 break;
213 default:
214 sink.sectionTitle5();
215 sink.text(name);
216 sink.sectionTitle5_();
217 break;
218 }
219 }
220
221 private void renderSectionStart(final int level)
222 {
223 switch (level)
224 {
225 case 1:
226 sink.section1();
227 break;
228 case 2:
229 sink.section2();
230 break;
231 case 3:
232 sink.section3();
233 break;
234 case 4:
235 sink.section4();
236 break;
237 case 5:
238 sink.section5();
239 break;
240 default:
241 sink.section5();
242 break;
243 }
244 }
245
246 void renderSectionEnd(final int level)
247 {
248 switch (level)
249 {
250 case 1:
251 sink.section1_();
252 break;
253 case 2:
254 sink.section2_();
255 break;
256 case 3:
257 sink.section3_();
258 break;
259 case 4:
260 sink.section4_();
261 break;
262 case 5:
263 sink.section5_();
264 break;
265 default:
266 sink.section5_();
267 break;
268 }
269 }
270
271
272
273 }