/** * BSD-style license; for more info see http://pmd.sourceforge.net/license.html */ package net.sourceforge.pmd.renderers; import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.Report; import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.util.StringUtil; import java.util.Iterator; public class HTMLRenderer implements Renderer { public String render(Report report) { StringBuffer buf = new StringBuffer("<html><head><title>PMD</title></head><body>" + PMD.EOL + "<table align=\"center\" cellspacing=\"0\" cellpadding=\"3\"><tr>" + PMD.EOL + "<th>#</th><th>File</th><th>Line</th><th>Problem</th></tr>" + PMD.EOL); buf.append(renderBody(report)); buf.append("</table></body></html>"); return buf.toString(); } public String renderBody(Report report) { boolean colorize = true; int violationCount = 1; StringBuffer buf = new StringBuffer(); for (Iterator i = report.iterator(); i.hasNext();) { RuleViolation rv = (RuleViolation) i.next(); buf.append("<tr"); if (colorize) { buf.append(" bgcolor=\"lightgrey\""); colorize = false; } else { colorize = true; } buf.append("> " + PMD.EOL); buf.append("<td align=\"center\">" + violationCount + "</td>" + PMD.EOL); buf.append("<td width=\"*%\">" + rv.getFilename() + "</td>" + PMD.EOL); buf.append("<td align=\"center\" width=\"5%\">" + Integer.toString(rv.getLine()) + "</td>" + PMD.EOL); String d = rv.getDescription(); d = StringUtil.replaceString(d, '&', "&"); d = StringUtil.replaceString(d, '<', "<"); d = StringUtil.replaceString(d, '>', ">"); buf.append("<td width=\"*\">" + d + "</td>" + PMD.EOL); buf.append("</tr>" + PMD.EOL); violationCount++; } return buf.toString(); } }