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 CSVRenderer implements Renderer {
11: public String render(Report report) {
12: StringBuffer buf = new StringBuffer(quoteAndCommify("Problem"));
13: buf.append(quoteAndCommify("File"));
14: buf.append(quoteAndCommify("Line"));
15: buf.append(quote("Description"));
16: buf.append(PMD.EOL);
17:
18: int violationCount = 1;
19: for (Iterator i = report.iterator(); i.hasNext();) {
20: RuleViolation rv = (RuleViolation) i.next();
21: buf
22: .append(quoteAndCommify(Integer
23: .toString(violationCount)));
24: buf.append(quoteAndCommify(rv.getFilename()));
25: buf.append(quoteAndCommify(Integer.toString(rv.getLine())));
26: buf.append(quote(StringUtil.replaceString(rv
27: .getDescription(), '\"', "'")));
28: buf.append(PMD.EOL);
29: violationCount++;
30: }
31: return buf.toString();
32: }
33:
34: private String quote(String d) {
35: return "\"" + d + "\"";
36: }
37:
38: private String quoteAndCommify(String d) {
39: return quote(d) + ",";
40: }
41:
42: }
|