View Javadoc

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.7 2008/04/02 11:22:15 benoitx Exp $
32   */
33  public class ReportConfig {
34      public static final MarkupSyntax XDOC = MarkupXDoc.getInstance();
35      public static final MarkupSyntax HTML = MarkupHTML.getInstance();
36      public static final MarkupSyntax XML = MarkupXML.getInstance();
37      private static final Dimension SMALL_CHART_SIZE = new Dimension(512, 320);
38      private static final Dimension LARGE_CHART_SIZE = new Dimension(720, 450);
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      private WebRepositoryIntegration webRepository = null;
48      private BugTracker webBugtracker = null;
49      private Collection nonDeveloperLogins = Collections.EMPTY_LIST;
50  
51      public ReportConfig(final Repository repository, final String projectName, final String rootDirectory, final MarkupSyntax syntax,
52              final CssHandler cssHandler) {
53          this.repository = repository;
54          this.projectName = projectName;
55          this.rootDirectory = rootDirectory;
56          this.markup = syntax;
57          this.cssHandler = cssHandler;
58          this.smallChartSize = SMALL_CHART_SIZE;
59          this.largeChartSize = LARGE_CHART_SIZE;
60      }
61  
62      public void setSmallChartSize(final Dimension newSize) {
63          this.smallChartSize = newSize;
64      }
65  
66      public void setLargeChartSize(final Dimension newSize) {
67          this.largeChartSize = newSize;
68      }
69  
70      public void setWebRepository(final WebRepositoryIntegration webRepository) {
71          this.webRepository = webRepository;
72      }
73  
74      public void setWebBugtracker(final BugTracker webBugtracker) {
75          this.webBugtracker = webBugtracker;
76      }
77  
78      public void setNonDeveloperLogins(final Collection names) {
79          this.nonDeveloperLogins = names;
80      }
81  
82      public String getRootDirectory() {
83          return this.rootDirectory;
84      }
85  
86      public Repository getRepository() {
87          return this.repository;
88      }
89  
90      public String getProjectName() {
91          return this.projectName;
92      }
93  
94      public Dimension getSmallChartSize() {
95          return this.smallChartSize;
96      }
97  
98      public Dimension getLargeChartSize() {
99          return this.largeChartSize;
100     }
101 
102     public MarkupSyntax getMarkup() {
103         return this.markup;
104     }
105 
106     public CssHandler getCssHandler() {
107         return this.cssHandler;
108     }
109 
110     public WebRepositoryIntegration getWebRepository() {
111         return this.webRepository;
112     }
113 
114     public BugTracker getWebBugtracker() {
115         return this.webBugtracker;
116     }
117 
118     /**
119      * Creates an empty report page.
120      * @param fileName The page's file name, relative to the root, 
121      * 		<em>without</em> file extension
122      * @param shortTitle A short title for use in navigation links
123      * @param fullTitle The full title for the headline
124      * @return An empty page according to the specifications
125      */
126     public Page createPage(final String fileName, final String shortTitle, final String fullTitle) {
127         return new Page(this, fileName, shortTitle, fullTitle);
128     }
129 
130     /**
131      * Writes a chart image file.
132      * @param fileName The file's name, relative to the root.
133      * @param title The chart's title
134      * @param chart The JFreeChart representation
135      * @param size Width and heigth in pixels
136      * @return An object representing the file
137      */
138     public ChartImage createChartImage(final String fileName, final String title, final JFreeChart chart, final Dimension size) {
139         final ChartImage img = new ChartImage(this.rootDirectory, fileName, title, chart, size);
140         img.write();
141         return img;
142     }
143 
144     /**
145      * Copies a file from a URL into the report.
146      * @param source The source file
147      * @param destinationFilename The destionation, relative to the 
148      * 		report root, without initial slash.
149      */
150     public void copyFileIntoReport(final URL source, final String destinationFilename) {
151         if (source == null) {
152             throw new NullPointerException("Source was null");
153         }
154         try {
155             final InputStream stream = source.openStream();
156             FileUtils.copyFile(stream, new File(this.rootDirectory + destinationFilename));
157             stream.close();
158         } catch (final IOException ex) {
159             throw new RuntimeException(ex);
160         }
161     }
162 
163     public boolean isDeveloper(final Author author) {
164         return !this.nonDeveloperLogins.contains(author.getName());
165     }
166 }