1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.maven.exceptions;
17
18 import java.util.ResourceBundle;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.apache.maven.doxia.sink.Sink;
22
23 import com.sun.javadoc.ClassDoc;
24 import com.sun.javadoc.FieldDoc;
25
26 import de.smartics.analysis.javadoc.render.JavadocRenderer;
27 import de.smartics.analysis.javadoc.render.html.HtmlRendererFactory;
28 import de.smartics.analysis.javadoc.runtime.RuntimeUtils;
29 import de.smartics.exceptions.core.Code;
30 import de.smartics.exceptions.report.generator.StringFunction;
31 import de.smartics.report.conf.ProjectConfiguration;
32 import de.smartics.report.conf.ReportData;
33 import de.smartics.report.generator.AbstractOutputReportGenerator;
34
35
36
37
38
39
40
41 public abstract class AbstractSinkReportGenerator extends
42 AbstractOutputReportGenerator
43 {
44
45
46
47
48
49
50
51
52
53
54
55
56
57 protected AbstractSinkReportGenerator()
58 {
59 super(new JavadocRenderer(new HtmlRendererFactory()));
60 }
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76 protected Sink toSink(final Object sink)
77 {
78 return (Sink) sink;
79 }
80
81
82
83
84
85
86 protected void writeReportElementInfo(
87 final Object output,
88 final ProjectConfiguration config,
89 final FieldDoc fieldDoc) throws Exception
90 {
91 final Sink sink = toSink(output);
92
93 sink.tableRow();
94
95
96
97 final Code instance =
98 (Code) RuntimeUtils.loadInstance(config.getProjectClassLoader(),
99 fieldDoc);
100
101 sink.tableCell();
102 sink.text(String.valueOf(String.valueOf(instance)));
103 sink.tableCell_();
104
105 sink.tableCell();
106 sink.text(fieldDoc.name());
107 sink.tableCell_();
108
109 sink.tableCell();
110
111 final String javadoc = this.renderer.render(fieldDoc);
112 if (StringUtils.isNotBlank(javadoc))
113 {
114 sink.rawText(javadoc);
115 }
116 else
117 {
118 sink.rawText(" ");
119 }
120 sink.tableCell_();
121
122 sink.tableRow_();
123 }
124
125
126
127
128 protected void writeContent(
129 final Object output,
130 final ProjectConfiguration config,
131 final ReportData reportData) throws Exception
132 {
133 final Sink sink = toSink(output);
134
135 final ResourceBundle bundle = config.getBundle();
136 final String title = bundle.getString("report.name");
137 sink.head();
138 sink.title();
139 sink.text(title);
140 sink.title_();
141 sink.head_();
142
143 sink.body();
144 sink.section1();
145
146 sink.sectionTitle1();
147 sink.text(title);
148 sink.sectionTitle1_();
149
150 sink.text(bundle.getString("report.description"));
151 sink.lineBreak();
152
153 if (!reportData.isEmpty())
154 {
155 write(output, config, reportData);
156 }
157 else
158 {
159 sink.lineBreak();
160 sink.lineBreak();
161 sink.text(bundle.getString("report.noElementsFound"));
162 }
163
164 sink.section1_();
165 sink.body_();
166 sink.flush();
167 sink.close();
168 }
169
170
171
172
173 protected void writeInfoFooter(
174 final Object output,
175 final ProjectConfiguration config) throws Exception
176 {
177 final Sink sink = toSink(output);
178 sink.section2_();
179 }
180
181 protected void writeInfoSubFooter(
182 final Object output,
183 final ProjectConfiguration config) throws Exception
184 {
185 final Sink sink = toSink(output);
186 sink.table_();
187 sink.section3_();
188 }
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205 protected void writeInfoHeader(
206 final Object output,
207 final ProjectConfiguration config,
208 final String headLine,
209 final ClassDoc classDoc) throws Exception
210 {
211 final Sink sink = toSink(output);
212
213 sink.section2();
214 sink.sectionTitle2();
215 if (headLine != null)
216 {
217 sink.text(headLine);
218 }
219 else
220 {
221 final String className = classDoc.qualifiedName();
222 sink.text(className);
223 }
224
225 final String classComment = classDoc.commentText();
226 sink.sectionTitle2_();
227
228 if (classComment != null)
229 {
230 sink.rawText(classComment);
231 }
232 }
233
234
235
236
237 protected void writeInfoSubHeader(
238 final Object output,
239 final ProjectConfiguration config,
240 final String subHeader)
241 {
242 final Sink sink = toSink(output);
243
244 sink.section3();
245 sink.sectionTitle3();
246 sink.text(subHeader);
247 sink.sectionTitle3_();
248 }
249
250
251
252
253
254
255
256 protected void writeTableHeader(
257 final Object output,
258 final ProjectConfiguration config)
259 {
260 final Sink sink = toSink(output);
261 sink.table();
262 sink.tableRow();
263
264 final ResourceBundle bundle = config.getBundle();
265 sink.tableHeaderCell("100");
266 final String codeLabel =
267 StringFunction.getMessage(bundle,
268 "report.exceptioncodes.item.reportElement", "Code");
269 sink.text(codeLabel);
270 sink.tableHeaderCell_();
271
272 sink.tableHeaderCell("150");
273 final String propertyNameLabel =
274 StringFunction.getMessage(bundle,
275 "report.exceptioncodes.item.propertyName", "Property Name");
276 sink.text(propertyNameLabel);
277 sink.tableHeaderCell_();
278
279 sink.tableHeaderCell();
280 final String descriptionLabel =
281 StringFunction.getMessage(bundle,
282 "report.exceptioncodes.item.description", "Description");
283 sink.text(descriptionLabel);
284 sink.tableHeaderCell_();
285
286 sink.tableRow_();
287 }
288
289
290
291
292 protected void writeFooter(
293 final Object output,
294 final ProjectConfiguration config)
295 {
296 }
297
298
299
300 }