View Javadoc

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