View Javadoc

    1   package net.sourceforge.pmd.renderers;
    2
    3   import java.io.IOException;
    4   import java.io.StringWriter;
    5   import java.io.Writer;
    6
    7   import net.sourceforge.pmd.DataSource;
    8   import net.sourceforge.pmd.Report;
    9
    10  public abstract class AbstractRenderer implements Renderer {
    11
    12      protected boolean showSuppressedViolations = true;
    13      private Writer writer;
    14      private Report mainReport;
    15
    16      public void showSuppressedViolations(boolean show) {
    17          this.showSuppressedViolations = show;
    18      }
    19
    20      public String render(Report report) {
    21          StringWriter w = new StringWriter();
    22          try {
    23              render(w, report);
    24          } catch (IOException e) {
    25              throw new Error("StringWriter doesn't throw IOException", e);
    26          }
    27          return w.toString();
    28      }
    29
    30
    31      public void setWriter(Writer writer) {
    32          this.writer = writer;
    33      }
    34
    35      public Writer getWriter() {
    36          return writer;
    37      }
    38
    39      public void start() throws IOException {
    40          // default (and backward compatible) behavior is to build a full report.
    41          // Optimized rendering is done in OnTheFlyRenderer and descendants
    42          mainReport = new Report();
    43      }
    44
    45      public void startFileAnalysis(DataSource dataSource) {}
    46
    47      public void renderFileReport(Report report) throws IOException {
    48          // default (and backward compatible) behavior is to build a full report.
    49          // Optimized rendering is done in OnTheFlyRenderer and descendants
    50          mainReport.merge(report);
    51      }
    52
    53      public void end() throws IOException {
    54          // default (and backward compatible) behavior is to build a full report.
    55          // Optimized rendering is done in OnTheFlyRenderer and descendants
    56          render(writer, mainReport);
    57      }
    58  }