01: package org.acm.seguin.pmd.renderers;
02:
03: import org.acm.seguin.pmd.PMD;
04: import org.acm.seguin.pmd.Report;
05: import org.acm.seguin.pmd.RuleViolation;
06: import org.acm.seguin.pmd.util.StringUtil;
07:
08: import java.util.Iterator;
09:
10: public class HTMLRenderer implements Renderer {
11: public String render(Report report) {
12: StringBuffer buf = new StringBuffer(
13: "<html><head><title>PMD</title></head><body>"
14: + PMD.EOL
15: + "<table align=\"center\" cellspacing=\"0\" cellpadding=\"3\"><tr>"
16: + PMD.EOL
17: + "<th>#</th><th>File</th><th>Line</th><th>Problem</th></tr>"
18: + PMD.EOL);
19: boolean colorize = true;
20: int violationCount = 1;
21: for (Iterator i = report.iterator(); i.hasNext();) {
22: RuleViolation rv = (RuleViolation) i.next();
23: buf.append("<tr");
24: if (colorize) {
25: buf.append(" bgcolor=\"lightgrey\"");
26: colorize = false;
27: } else {
28: colorize = true;
29: }
30: buf.append("> " + PMD.EOL);
31: buf.append("<td align=\"center\">" + violationCount
32: + "</td>" + PMD.EOL);
33: buf.append("<td width=\"*%\">" + rv.getFilename() + "</td>"
34: + PMD.EOL);
35: buf.append("<td align=\"center\" width=\"5%\">"
36: + Integer.toString(rv.getLine()) + "</td>"
37: + PMD.EOL);
38:
39: String d = rv.getDescription();
40: d = StringUtil.replaceString(d, '&', "&");
41: d = StringUtil.replaceString(d, '<', "<");
42: d = StringUtil.replaceString(d, '>', ">");
43: buf.append("<td width=\"*\">" + d + "</td>" + PMD.EOL);
44:
45: buf.append("</tr>" + PMD.EOL);
46:
47: violationCount++;
48: }
49: buf.append("</table></body></html>");
50: return buf.toString();
51: }
52: }
|