1 /* 2 StatCvs - CVS statistics generation 3 Copyright (C) 2002 Lukasz Pekacki <lukasz@pekacki.de> 4 http://statcvs.sf.net/ 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public 8 License as published by the Free Software Foundation; either 9 version 2.1 of the License, or (at your option) any later version. 10 11 This library is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 Lesser General Public License for more details. 15 16 You should have received a copy of the GNU Lesser General Public 17 License along with this library; if not, write to the Free Software 18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 20 $RCSfile: LocalFileCssHandler.java,v $ 21 $Date: 2008/04/02 11:22:15 $ 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 }