1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.sf.statcvs.output;
24
25 import java.io.File;
26 import java.io.IOException;
27 import java.util.logging.Logger;
28
29 import net.sf.statcvs.util.FileUtils;
30
31 /**
32 * CSS handler for a local CSS file which will be copied to the output dir.
33 *
34 * @author Richard Cyganiak
35 */
36 public class LocalFileCssHandler implements CssHandler {
37
38 private static Logger logger = Logger.getLogger("net.sf.statcvs.output.CssHandler");
39
40 private final String filename;
41
42 /**
43 * Creates a new LocalFileCssHandler for a given CSS file.
44 * The filename can be absoulte or relative.
45 * @param filename Name of the CSS file
46 */
47 public LocalFileCssHandler(final String filename) {
48 this.filename = filename;
49 }
50
51 /**
52 * @see net.sf.statcvs.output.CssHandler#getLink()
53 */
54 public String getLink() {
55 return FileUtils.getFilenameWithoutPath(filename);
56 }
57
58 /**
59 * Checks if the local CSS file exists
60 * @see net.sf.statcvs.output.CssHandler#checkForMissingResources()
61 * @throws ConfigurationException if the file is not found
62 */
63 public void checkForMissingResources() throws ConfigurationException {
64 logger.finer("Checking if CSS file exists: '" + filename + "'");
65 final File f = new File(filename);
66 if (!f.exists()) {
67 throw new ConfigurationException("CSS file not found: " + filename);
68 }
69 }
70
71 /**
72 * Copies the local CSS file to the output directory
73 * @see net.sf.statcvs.output.CssHandler#createOutputFiles()
74 */
75 public void createOutputFiles() throws IOException {
76 final String destination = ConfigurationOptions.getOutputDir() + getLink();
77 logger.info("Copying CSS file to '" + destination + "'");
78 FileUtils.copyFile(filename, destination);
79 }
80
81 /**
82 * toString
83 * @return string
84 */
85 public String toString() {
86 return "local CSS file (" + filename + ")";
87 }
88 }