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.util.Iterator;
    7   import java.util.Map;
    8
    9   public class SummaryHTMLRenderer extends AbstractRenderer implements Renderer {
    10      public String render(Report report) {
    11          StringBuffer buf = new StringBuffer("<html><head><title>PMD</title></head><body>" + PMD.EOL);
    12          buf.append(renderSummary(report));
    13          buf.append("<h2><center>Detail</h2></center>");
    14          buf.append("<table align=\"center\" cellspacing=\"0\" cellpadding=\"3\"><tr>" + PMD.EOL + "<th>#</th><th>File</th><th>Line</th><th>Problem</th></tr>" + PMD.EOL);
    15          buf.append(new HTMLRenderer().renderBody(report));
    16          buf.append("</table></body></html>");
    17          return buf.toString();
    18      }
    19
    20      public String renderSummary(Report report) {
    21          StringBuffer buf = new StringBuffer();
    22          buf.append("<h2><center>Summary</h2></center>");
    23          buf.append("<table align=\"center\" cellspacing=\"0\" cellpadding=\"3\">");
    24          buf.append("<th>Rule name</th>");
    25          buf.append("<th>Number of violations</th>");
    26          Map summary = report.getSummary();
    27          for (Iterator i = summary.keySet().iterator(); i.hasNext();) {
    28              String ruleName = (String) i.next();
    29              buf.append("<tr>");
    30              buf.append("<td>" + ruleName + "</td>");
    31              buf.append("<td align=center>" + String.valueOf(((Integer) summary.get(ruleName)).intValue()) + "</td>");
    32              buf.append("</tr>");
    33          }
    34          buf.append("</table>");
    35          return buf.toString();
    36      }
    37  }