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
26
27
28
29
30
31
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
120
121
122
123
124
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
132
133
134
135
136
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
146
147
148
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 }