001: package org.acm.seguin.pmd.renderers;
002:
003: import java.util.Iterator;
004:
005: import org.acm.seguin.pmd.PMD;
006: import org.acm.seguin.pmd.Report;
007: import org.acm.seguin.pmd.RuleViolation;
008: import org.acm.seguin.pmd.renderers.Renderer;
009:
010: /**
011: * @version $Revision: 1.2 $ $Date: 2003/09/11 15:59:05 $
012: * @author Vladimir
013: */
014: public class VBHTMLRenderer implements Renderer {
015:
016: public String render(Report report) {
017: if (report.isEmpty()) {
018: return "";
019: }
020:
021: StringBuffer sb = new StringBuffer(header());
022: String filename = null;
023: String lineSep = PMD.EOL;
024:
025: boolean colorize = false;
026:
027: for (Iterator iter = report.iterator(); iter.hasNext();) {
028: RuleViolation rv = (RuleViolation) iter.next();
029: if (!rv.getFilename().equals(filename)) { // New File
030: if (filename != null) {
031: sb.append("</table></br>");
032: colorize = false;
033: }
034: filename = rv.getFilename();
035: sb.append("<table border=\"0\" width=\"80%\">");
036: sb
037: .append(
038: "<tr id=TableHeader><td colspan=\"2\"><font class=title> ")
039: .append(filename).append("</font></tr>");
040: sb.append(lineSep);
041: }
042:
043: if (colorize) {
044: sb.append("<tr id=RowColor1>");
045: } else {
046: sb.append("<tr id=RowColor2>");
047: }
048:
049: colorize = !colorize;
050: sb
051: .append("<td width=\"50\" align=\"right\"><font class=body>"
052: + rv.getLine()
053: + " </font></td>");
054: sb.append("<td><font class=body>" + rv.getDescription()
055: + "</font></td>");
056: sb.append("</tr>");
057: sb.append(lineSep);
058: }
059: if (filename != null) {
060: sb.append("</table>");
061: }
062: sb.append("<br>");
063:
064: // output the problems
065: Iterator iter = report.errors();
066: if (iter.hasNext()) {
067: sb.append("<table border=\"0\" width=\"80%\">");
068: sb
069: .append("<tr id=TableHeader><td><font class=title> Problems found</font></td></tr>");
070: colorize = false;
071: while (iter.hasNext()) {
072: if (colorize) {
073: sb.append("<tr id=RowColor1>");
074: } else {
075: sb.append("<tr id=RowColor2>");
076: }
077: colorize = !colorize;
078: sb.append("<td><font class=body>").append(iter.next())
079: .append("\"</font></td></tr>");
080: }
081: sb.append("</table>");
082: }
083:
084: sb.append(footer());
085:
086: return sb.toString();
087: }
088:
089: private String header() {
090: StringBuffer sb = new StringBuffer();
091: sb.append("<html><head><title>PMD</title></head>");
092: sb.append("<style type=\"text/css\">");
093: sb.append("<!--" + PMD.EOL);
094: sb
095: .append("body { background-color: white; font-family:verdana, arial, helvetica, geneva; font-size: 16px; font-style: italic; color: black; }"
096: + PMD.EOL);
097: sb
098: .append(".title { font-family: verdana, arial, helvetica,geneva; font-size: 12px; font-weight:bold; color: white; }"
099: + PMD.EOL);
100: sb
101: .append(".body { font-family: verdana, arial, helvetica, geneva; font-size: 12px; font-weight:plain; color: black; }"
102: + PMD.EOL);
103: sb.append("#TableHeader { background-color: #003366; }"
104: + PMD.EOL);
105: sb
106: .append("#RowColor1 { background-color: #eeeeee; }"
107: + PMD.EOL);
108: sb.append("#RowColor2 { background-color: white; }" + PMD.EOL);
109: sb.append("-->");
110: sb.append("</style>");
111: sb.append("<body><center>");
112: return sb.toString();
113: }
114:
115: private String footer() {
116: return "</center></body></html>";
117: }
118:
119: }
|