KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > renderers > SummaryHTMLRenderer


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 JavaDoc;
7 import java.io.Writer JavaDoc;
8 import java.util.Iterator JavaDoc;
9 import java.util.Map JavaDoc;
10
11 public class SummaryHTMLRenderer extends AbstractRenderer {
12     private String JavaDoc linePrefix,linkPrefix;
13     public SummaryHTMLRenderer(String JavaDoc linkPrefix, String JavaDoc 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 JavaDoc writer, Report report) throws IOException JavaDoc {
23         writer.write("<html><head><title>PMD</title></head><body>" + PMD.EOL);
24         renderSummary(writer, report);
25         writer.write("<h2><center>Detail</h2></center>");
26         writer.write("<table align=\"center\" cellspacing=\"0\" cellpadding=\"3\"><tr>" + PMD.EOL + "<th>#</th><th>File</th><th>Line</th><th>Problem</th></tr>" + PMD.EOL);
27         new HTMLRenderer(linkPrefix,linePrefix).renderBody(writer, report);
28         writer.write("</table></body></html>");
29     }
30
31     public void renderSummary(Writer JavaDoc writer, Report report) throws IOException JavaDoc {
32         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
33         buf.append("<h2><center>Summary</h2></center>");
34         buf.append("<table align=\"center\" cellspacing=\"0\" cellpadding=\"3\">");
35         buf.append("<th>Rule name</th>");
36         buf.append("<th>Number of violations</th>");
37         writer.write(buf.toString());
38         Map JavaDoc summary = report.getSummary();
39         for (Iterator JavaDoc i = summary.entrySet().iterator(); i.hasNext();) {
40             Map.Entry JavaDoc entry = (Map.Entry JavaDoc) i.next();
41             String JavaDoc ruleName = (String JavaDoc) entry.getKey();
42             buf.setLength(0);
43             buf.append("<tr>");
44             buf.append("<td>" + ruleName + "</td>");
45             buf.append("<td align=center>" + ((Integer JavaDoc) entry.getValue()).intValue() + "</td>");
46             buf.append("</tr>");
47             writer.write(buf.toString());
48         }
49         writer.write("</table>");
50     }
51 }
52
Popular Tags