KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > pmd > renderers > VBHTMLRenderer


1 /**
2  * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3  */

4 package net.sourceforge.pmd.renderers;
5
6 import net.sourceforge.pmd.IRuleViolation;
7 import net.sourceforge.pmd.PMD;
8 import net.sourceforge.pmd.Report;
9
10 import java.io.IOException JavaDoc;
11 import java.io.Writer JavaDoc;
12 import java.util.Iterator JavaDoc;
13
14 /**
15  * @author Vladimir
16  * @version $Revision: 1.15 $ $Date: 2006/11/19 02:01:35 $
17  */

18 public class VBHTMLRenderer extends AbstractRenderer {
19
20     public void render(Writer JavaDoc writer, Report report) throws IOException JavaDoc {
21         if (report.isEmpty()) {
22             return;
23         }
24
25         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
26         String JavaDoc filename = null;
27         String JavaDoc lineSep = PMD.EOL;
28
29         boolean colorize = false;
30
31         writer.write(header());
32         for (Iterator JavaDoc iter = report.iterator(); iter.hasNext();) {
33             sb.setLength(0);
34             IRuleViolation rv = (IRuleViolation) iter.next();
35             if (!rv.getFilename().equals(filename)) { // New File
36
if (filename != null) {
37                     sb.append("</table></br>");
38                     colorize = false;
39                 }
40                 filename = rv.getFilename();
41                 sb.append("<table border=\"0\" width=\"80%\">");
42                 sb.append("<tr id=TableHeader><td colspan=\"2\"><font class=title>&nbsp;").append(filename).append("</font></tr>");
43                 sb.append(lineSep);
44             }
45
46             if (colorize) {
47                 sb.append("<tr id=RowColor1>");
48             } else {
49                 sb.append("<tr id=RowColor2>");
50             }
51
52             colorize = !colorize;
53             sb.append("<td width=\"50\" align=\"right\"><font class=body>" + rv.getBeginLine() + "&nbsp;&nbsp;&nbsp;</font></td>");
54             sb.append("<td><font class=body>" + rv.getDescription() + "</font></td>");
55             sb.append("</tr>");
56             sb.append(lineSep);
57             writer.write(sb.toString());
58         }
59         if (filename != null) {
60             writer.write("</table>");
61         }
62         writer.write("<br>");
63
64         // output the problems
65
Iterator JavaDoc iter = report.errors();
66         if (iter.hasNext()) {
67             sb.setLength(0);
68             sb.append("<table border=\"0\" width=\"80%\">");
69             sb.append("<tr id=TableHeader><td><font class=title>&nbsp;Problems found</font></td></tr>");
70             colorize = false;
71             while (iter.hasNext()) {
72                 if (colorize) {
73                     sb.append("<tr id=RowColor1>");
74                 } else {
75                     sb.append("<tr id=RowColor2>");
76                 }
77                 colorize = !colorize;
78                 sb.append("<td><font class=body>").append(iter.next()).append("\"</font></td></tr>");
79             }
80             sb.append("</table>");
81             writer.write(sb.toString());
82         }
83
84         writer.write(footer());
85     }
86
87     private String JavaDoc header() {
88         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
89         sb.append("<html><head><title>PMD</title></head>");
90         sb.append("<style type=\"text/css\">");
91         sb.append("<!--" + PMD.EOL);
92         sb.append("body { background-color: white; font-family:verdana, arial, helvetica, geneva; font-size: 16px; font-style: italic; color: black; }" + PMD.EOL);
93         sb.append(".title { font-family: verdana, arial, helvetica,geneva; font-size: 12px; font-weight:bold; color: white; }" + PMD.EOL);
94         sb.append(".body { font-family: verdana, arial, helvetica, geneva; font-size: 12px; font-weight:plain; color: black; }" + PMD.EOL);
95         sb.append("#TableHeader { background-color: #003366; }" + PMD.EOL);
96         sb.append("#RowColor1 { background-color: #eeeeee; }" + PMD.EOL);
97         sb.append("#RowColor2 { background-color: white; }" + PMD.EOL);
98         sb.append("-->");
99         sb.append("</style>");
100         sb.append("<body><center>");
101         return sb.toString();
102     }
103
104     private String JavaDoc footer() {
105         return "</center></body></html>";
106     }
107
108 }
Popular Tags