Coverage Report - net.sf.statcvs.output.ReportConfig
 
Classes in this File Line Coverage Branch Coverage Complexity
ReportConfig
0%
0/87
0%
0/10
1.35
 
 1  
 package net.sf.statcvs.output;
 2  
 
 3  
 import java.awt.Dimension;
 4  
 import java.io.File;
 5  
 import java.io.IOException;
 6  
 import java.io.InputStream;
 7  
 import java.net.URL;
 8  
 import java.util.Collection;
 9  
 import java.util.Collections;
 10  
 
 11  
 import net.sf.statcvs.charts.ChartImage;
 12  
 import net.sf.statcvs.model.Author;
 13  
 import net.sf.statcvs.model.Repository;
 14  
 import net.sf.statcvs.pages.MarkupHTML;
 15  
 import net.sf.statcvs.pages.MarkupSyntax;
 16  
 import net.sf.statcvs.pages.MarkupXDoc;
 17  
 import net.sf.statcvs.pages.Page;
 18  
 import net.sf.statcvs.pages.xml.MarkupXML;
 19  
 import net.sf.statcvs.util.FileUtils;
 20  
 import net.sf.statcvs.weblinks.bugs.BugTracker;
 21  
 
 22  
 import org.jfree.chart.JFreeChart;
 23  
 
 24  
 /**
 25  
  * A configuration object that controls several aspects of 
 26  
  * report creation, such as the output directory and chart
 27  
  * sizes. A single instance is passed around to all objects
 28  
  * involved in report creation.
 29  
  *
 30  
  * @author Richard Cyganiak (richard@cyganiak.de)
 31  
  * @version $Id: ReportConfig.java,v 1.12 2009/06/02 13:28:53 benoitx Exp $
 32  
  */
 33  
 public class ReportConfig {
 34  0
     public static final MarkupSyntax XDOC = MarkupXDoc.getInstance();
 35  0
     public static final MarkupSyntax HTML = MarkupHTML.getInstance();
 36  0
     public static final MarkupSyntax XML = MarkupXML.getInstance();
 37  0
     private static final Dimension SMALL_CHART_SIZE = new Dimension(512, 320);
 38  0
     private static final Dimension LARGE_CHART_SIZE = new Dimension(800, 500);
 39  
 
 40  
     private final Repository repository;
 41  
     private final String projectName;
 42  
     private final String rootDirectory;
 43  
     private final MarkupSyntax markup;
 44  
     private final CssHandler cssHandler;
 45  
     private Dimension smallChartSize;
 46  
     private Dimension largeChartSize;
 47  0
     private WebRepositoryIntegration webRepository = null;
 48  0
     private BugTracker webBugtracker = null;
 49  0
     private Collection nonDeveloperLogins = Collections.EMPTY_LIST;
 50  
     private final String charSet;
 51  
 
 52  0
     public ReportConfig(final Repository repository, final String projectName, final String rootDirectory, final MarkupSyntax syntax,
 53  0
             final CssHandler cssHandler, final String charSet) {
 54  0
         this.repository = repository;
 55  0
         this.projectName = projectName;
 56  0
         this.rootDirectory = rootDirectory;
 57  0
         this.markup = syntax;
 58  0
         this.cssHandler = cssHandler;
 59  0
         this.smallChartSize = SMALL_CHART_SIZE;
 60  0
         this.largeChartSize = LARGE_CHART_SIZE;
 61  0
         this.charSet = charSet;
 62  0
     }
 63  0
 
 64  0
     public void setSmallChartSize(final Dimension newSize) {
 65  0
         this.smallChartSize = newSize;
 66  0
     }
 67  0
 
 68  0
     public void setLargeChartSize(final Dimension newSize) {
 69  0
         this.largeChartSize = newSize;
 70  0
     }
 71  0
 
 72  0
     public void setWebRepository(final WebRepositoryIntegration webRepository) {
 73  0
         this.webRepository = webRepository;
 74  0
     }
 75  0
 
 76  0
     public void setWebBugtracker(final BugTracker webBugtracker) {
 77  0
         this.webBugtracker = webBugtracker;
 78  0
     }
 79  0
 
 80  0
     public void setNonDeveloperLogins(final Collection names) {
 81  0
         this.nonDeveloperLogins = names;
 82  0
     }
 83  0
 
 84  
     public String getRootDirectory() {
 85  0
         return this.rootDirectory;
 86  
     }
 87  0
 
 88  
     public Repository getRepository() {
 89  0
         return this.repository;
 90  
     }
 91  0
 
 92  
     public String getProjectName() {
 93  0
         return this.projectName;
 94  
     }
 95  0
 
 96  
     public Dimension getSmallChartSize() {
 97  0
         return this.smallChartSize;
 98  
     }
 99  0
 
 100  
     public Dimension getLargeChartSize() {
 101  0
         return this.largeChartSize;
 102  
     }
 103  0
 
 104  
     public MarkupSyntax getMarkup() {
 105  0
         return this.markup;
 106  
     }
 107  0
 
 108  
     public CssHandler getCssHandler() {
 109  0
         return this.cssHandler;
 110  
     }
 111  0
 
 112  
     public WebRepositoryIntegration getWebRepository() {
 113  0
         return this.webRepository;
 114  
     }
 115  0
 
 116  
     public BugTracker getWebBugtracker() {
 117  0
         return this.webBugtracker;
 118  
     }
 119  
 
 120  
     /**
 121  
      * Creates an empty report page.
 122  
      * @param fileName The page's file name, relative to the root, 
 123  
      *                 <em>without</em> file extension
 124  
      * @param shortTitle A short title for use in navigation links
 125  
      * @param fullTitle The full title for the headline
 126  
      * @return An empty page according to the specifications
 127  0
      */
 128  
     public Page createPage(final String fileName, final String shortTitle, final String fullTitle) {
 129  0
         return new Page(this, fileName, shortTitle, fullTitle);
 130  
     }
 131  
 
 132  
     /**
 133  
      * Writes a chart image file.
 134  
      * @param fileName The file's name, relative to the root.
 135  
      * @param title The chart's title
 136  
      * @param chart The JFreeChart representation
 137  
      * @param size Width and height in pixels
 138  
      * @return An object representing the file
 139  0
      */
 140  0
     public ChartImage createChartImage(final String fileName, final String title, final JFreeChart chart, final Dimension size) {
 141  0
         final ChartImage img = new ChartImage(this.rootDirectory, fileName, title, chart, size);
 142  0
         img.write();
 143  0
         return img;
 144  
     }
 145  
 
 146  
     /**
 147  
      * Copies a file from a URL into the report.
 148  
      * @param source The source file
 149  
      * @param destinationFilename The destination, relative to the 
 150  
      *                 report root, without initial slash.
 151  0
      */
 152  0
     public void copyFileIntoReport(final URL source, final String destinationFilename) {
 153  0
         if (source == null) {
 154  0
             throw new NullPointerException("Source was null");
 155  0
         }
 156  0
         InputStream stream = null;
 157  0
         try {
 158  0
             stream = source.openStream();
 159  0
             FileUtils.copyFile(stream, new File(this.rootDirectory + destinationFilename));
 160  0
             stream.close();
 161  0
         } catch (final IOException ex) {
 162  0
             throw new RuntimeException(ex);
 163  0
         } finally {
 164  0
             if (stream != null) {
 165  
                 try {
 166  0
                     stream.close();
 167  0
                 } catch (IOException e) {
 168  0
                     throw new RuntimeException(e);
 169  0
                 }
 170  0
             }
 171  0
         }
 172  0
     }
 173  
 
 174  
     public boolean isDeveloper(final Author author) {
 175  0
         return !this.nonDeveloperLogins.contains(author.getName());
 176  
     }
 177  
 
 178  
     public String getCharSet() {
 179  0
         return charSet;
 180  
     }
 181  
 }