| 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 | 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 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
|
| 126 | |
|
| 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 | |
|
| 134 | |
|
| 135 | |
|
| 136 | |
|
| 137 | |
|
| 138 | |
|
| 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 | |
|
| 148 | |
|
| 149 | |
|
| 150 | |
|
| 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 | |
} |