001: /**
002: * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
003: */package net.sourceforge.pmd.renderers;
004:
005: import net.sourceforge.pmd.IRuleViolation;
006: import net.sourceforge.pmd.PMD;
007: import net.sourceforge.pmd.Report;
008:
009: import java.io.IOException;
010: import java.io.Writer;
011: import java.util.Iterator;
012:
013: /**
014: * @author Vladimir
015: * @version $Revision: 5090 $ $Date: 2007-03-30 18:57:35 -0700 (Fri, 30 Mar 2007) $
016: */
017: public class VBHTMLRenderer extends OnTheFlyRenderer {
018:
019: public void start() throws IOException {
020: getWriter().write(header());
021: }
022:
023: public void renderFileViolations(Iterator<IRuleViolation> violations)
024: throws IOException {
025: if (!violations.hasNext()) {
026: return;
027: }
028:
029: Writer writer = getWriter();
030: StringBuffer sb = new StringBuffer();
031: String filename = null;
032: String lineSep = PMD.EOL;
033:
034: boolean colorize = false;
035: while (violations.hasNext()) {
036: sb.setLength(0);
037: IRuleViolation rv = violations.next();
038: if (!rv.getFilename().equals(filename)) { // New File
039: if (filename != null) {
040: sb.append("</table></br>");
041: colorize = false;
042: }
043: filename = rv.getFilename();
044: sb.append("<table border=\"0\" width=\"80%\">");
045: sb
046: .append(
047: "<tr id=TableHeader><td colspan=\"2\"><font class=title> ")
048: .append(filename).append("</font></tr>");
049: sb.append(lineSep);
050: }
051:
052: if (colorize) {
053: sb.append("<tr id=RowColor1>");
054: } else {
055: sb.append("<tr id=RowColor2>");
056: }
057:
058: colorize = !colorize;
059: sb
060: .append("<td width=\"50\" align=\"right\"><font class=body>"
061: + rv.getBeginLine()
062: + " </font></td>");
063: sb.append("<td><font class=body>" + rv.getDescription()
064: + "</font></td>");
065: sb.append("</tr>");
066: sb.append(lineSep);
067: writer.write(sb.toString());
068: }
069: if (filename != null) {
070: writer.write("</table>");
071: }
072: }
073:
074: public void end() throws IOException {
075: Writer writer = getWriter();
076: StringBuffer sb = new StringBuffer();
077:
078: writer.write("<br>");
079:
080: // output the problems
081: if (!errors.isEmpty()) {
082: sb.setLength(0);
083: sb.append("<table border=\"0\" width=\"80%\">");
084: sb
085: .append("<tr id=TableHeader><td><font class=title> Problems found</font></td></tr>");
086: boolean colorize = false;
087: for (Report.ProcessingError error : errors) {
088: if (colorize) {
089: sb.append("<tr id=RowColor1>");
090: } else {
091: sb.append("<tr id=RowColor2>");
092: }
093: colorize = !colorize;
094: sb.append("<td><font class=body>").append(error)
095: .append("\"</font></td></tr>");
096: }
097: sb.append("</table>");
098: writer.write(sb.toString());
099: }
100:
101: writer.write(footer());
102: }
103:
104: private String header() {
105: StringBuffer sb = new StringBuffer();
106: sb.append("<html><head><title>PMD</title></head>");
107: sb.append("<style type=\"text/css\">");
108: sb.append("<!--" + PMD.EOL);
109: sb
110: .append("body { background-color: white; font-family:verdana, arial, helvetica, geneva; font-size: 16px; font-style: italic; color: black; }"
111: + PMD.EOL);
112: sb
113: .append(".title { font-family: verdana, arial, helvetica,geneva; font-size: 12px; font-weight:bold; color: white; }"
114: + PMD.EOL);
115: sb
116: .append(".body { font-family: verdana, arial, helvetica, geneva; font-size: 12px; font-weight:plain; color: black; }"
117: + PMD.EOL);
118: sb.append("#TableHeader { background-color: #003366; }"
119: + PMD.EOL);
120: sb
121: .append("#RowColor1 { background-color: #eeeeee; }"
122: + PMD.EOL);
123: sb.append("#RowColor2 { background-color: white; }" + PMD.EOL);
124: sb.append("-->");
125: sb.append("</style>");
126: sb.append("<body><center>");
127: return sb.toString();
128: }
129:
130: private String footer() {
131: return "</center></body></html>";
132: }
133:
134: }
|