01: package net.sourceforge.pmd.renderers;
02:
03: import net.sourceforge.pmd.PMD;
04: import net.sourceforge.pmd.Report;
05:
06: import java.io.IOException;
07: import java.io.Writer;
08: import java.util.Map;
09:
10: public class SummaryHTMLRenderer extends AbstractRenderer {
11: private String linePrefix, linkPrefix;
12:
13: public SummaryHTMLRenderer(String linkPrefix, String linePrefix) {
14: this .linePrefix = linePrefix;
15: this .linkPrefix = linkPrefix;
16: }
17:
18: public SummaryHTMLRenderer() {
19: this (null, null);
20: }
21:
22: public void render(Writer writer, Report report) throws IOException {
23: writer.write("<html><head><title>PMD</title></head><body>"
24: + PMD.EOL);
25: renderSummary(writer, report);
26: writer.write("<h2><center>Detail</h2></center>");
27: writer
28: .write("<table align=\"center\" cellspacing=\"0\" cellpadding=\"3\"><tr>"
29: + PMD.EOL);
30: new HTMLRenderer(linkPrefix, linePrefix).renderBody(writer,
31: report);
32: writer.write("</table></body></html>");
33: }
34:
35: public void renderSummary(Writer writer, Report report)
36: throws IOException {
37: StringBuffer buf = new StringBuffer();
38: buf.append("<h2><center>Summary</h2></center>");
39: buf
40: .append("<table align=\"center\" cellspacing=\"0\" cellpadding=\"3\">");
41: buf.append("<th>Rule name</th>");
42: buf.append("<th>Number of violations</th>");
43: writer.write(buf.toString());
44: Map<String, Integer> summary = report.getSummary();
45: for (Map.Entry<String, Integer> entry : summary.entrySet()) {
46: String ruleName = entry.getKey();
47: buf.setLength(0);
48: buf.append("<tr>");
49: buf.append("<td>" + ruleName + "</td>");
50: buf.append("<td align=center>"
51: + entry.getValue().intValue() + "</td>");
52: buf.append("</tr>");
53: writer.write(buf.toString());
54: }
55: writer.write("</table>");
56: }
57: }
|