Clover coverage report -
Coverage timestamp: Do Okt 21 2004 12:21:23 CEST
file stats: LOC: 80   Methods: 5
NCLOC: 47   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ConfigurationUtils.java 50% 95,2% 80% 82,4%
coverage coverage
 1    /*
 2    * ConfigurationUtils.java
 3    *
 4    * Created on 3. Februar 2003, 21:55
 5    */
 6   
 7    package org.jconfig.utils;
 8   
 9    import java.io.File;
 10    import java.io.IOException;
 11    import java.net.URL;
 12    import java.io.InputStream;
 13    import java.util.Properties;
 14    /**
 15    *
 16    * @author Andreas Mecky
 17    * @author Terry Dye
 18    *
 19    * This class contains some helper methods.
 20    *
 21    */
 22    public class ConfigurationUtils {
 23   
 24  0 private ConfigurationUtils() {
 25    }
 26   
 27    /** This method tries to get the file for a given fileName
 28    * by trying to find it in the classpath.
 29    *
 30    * @param fileName The name of the file
 31    * @return a file or NULL
 32    */
 33  62 public static File getFileFromInputStream(String fileName) {
 34  62 ClassLoader cl = Thread.currentThread().getContextClassLoader();
 35  62 URL url = cl.getResource(fileName);
 36  62 if (url != null) {
 37  62 File file = new File(url.getFile());
 38  62 return file;
 39    }
 40    else {
 41  0 return null;
 42    }
 43    }
 44   
 45    /**
 46    * Method getFile.
 47    * @param filename
 48    * @return File
 49    * @throws IOException
 50    */
 51  1 public static File getFile( String filename ) throws IOException {
 52  1 ResourceLocator locator = new ResourceLocator( filename );
 53  1 return locator.getFile();
 54    }
 55   
 56  2 public static String getConfigProperty(String name) {
 57  2 return getConfigProperty(name,null);
 58    }
 59   
 60  39 public static String getConfigProperty(String name,String defaultValue) {
 61  39 String val = System.getProperty(name);
 62  39 if ( val == null ) {
 63  39 try {
 64  39 ResourceLocator locator = new ResourceLocator("jconfig.properties");
 65  39 InputStream is = locator.getInputStream();
 66    // it is possible that the jconfig.properties does not exist, we get null
 67  39 if ( is != null ) {
 68  39 Properties jcfProperties = new Properties();
 69  39 jcfProperties.load( is );
 70  39 val = jcfProperties.getProperty(name);
 71    }
 72    } catch (IOException e) {
 73    }
 74    }
 75  39 if ( val == null ) {
 76  39 val = defaultValue;
 77    }
 78  39 return val;
 79    }
 80    }