View Javadoc

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