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.Iterator ; 9 import java.util.Map ; 10 11 public class SummaryHTMLRenderer extends AbstractRenderer { 12 private String linePrefix,linkPrefix; 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>" + 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 writer, Report report) throws IOException { 32 StringBuffer buf = new StringBuffer (); 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 summary = report.getSummary(); 39 for (Iterator i = summary.entrySet().iterator(); i.hasNext();) { 40 Map.Entry entry = (Map.Entry ) i.next(); 41 String ruleName = (String ) entry.getKey(); 42 buf.setLength(0); 43 buf.append("<tr>"); 44 buf.append("<td>" + ruleName + "</td>"); 45 buf.append("<td align=center>" + ((Integer ) entry.getValue()).intValue() + "</td>"); 46 buf.append("</tr>"); 47 writer.write(buf.toString()); 48 } 49 writer.write("</table>"); 50 } 51 } 52 | Popular Tags |