01: package net.sourceforge.pmd.renderers;
02:
03: import java.io.IOException;
04: import java.io.StringWriter;
05: import java.io.Writer;
06:
07: import net.sourceforge.pmd.DataSource;
08: import net.sourceforge.pmd.Report;
09:
10: public abstract class AbstractRenderer implements Renderer {
11:
12: protected boolean showSuppressedViolations = true;
13: private Writer writer;
14: private Report mainReport;
15:
16: public void showSuppressedViolations(boolean show) {
17: this .showSuppressedViolations = show;
18: }
19:
20: public String render(Report report) {
21: StringWriter w = new StringWriter();
22: try {
23: render(w, report);
24: } catch (IOException e) {
25: throw new Error("StringWriter doesn't throw IOException", e);
26: }
27: return w.toString();
28: }
29:
30: public void setWriter(Writer writer) {
31: this .writer = writer;
32: }
33:
34: public Writer getWriter() {
35: return writer;
36: }
37:
38: public void start() throws IOException {
39: // default (and backward compatible) behavior is to build a full report.
40: // Optimized rendering is done in OnTheFlyRenderer and descendants
41: mainReport = new Report();
42: }
43:
44: public void startFileAnalysis(DataSource dataSource) {
45: }
46:
47: public void renderFileReport(Report report) throws IOException {
48: // default (and backward compatible) behavior is to build a full report.
49: // Optimized rendering is done in OnTheFlyRenderer and descendants
50: mainReport.merge(report);
51: }
52:
53: public void end() throws IOException {
54: // default (and backward compatible) behavior is to build a full report.
55: // Optimized rendering is done in OnTheFlyRenderer and descendants
56: render(writer, mainReport);
57: }
58: }
|