1 package net.sf.cantina.application;
2
3 import net.sf.cantina.util.Loader;
4 import org.apache.log4j.Logger;
5
6 import java.net.URL;
7 import java.util.Hashtable;
8 import java.util.Properties;
9
10 /***
11 * cantina.properties configuration.
12 * @author Stephane JAIS
13 */
14
15 public class Config
16 extends Hashtable
17 {
18 private static final String CONFIG_FILENAME = "cantina.properties";
19
20 /***
21 * This setting determines which datasource will be used by the system,
22 * Valid values are a class name that implements DataSource
23 */
24
25 public static final String DS_TYPE = "datasource.type";
26
27 private static final Logger logger = Logger.getLogger(Config.class);
28
29 protected static Properties properties = loadProperties(
30 Loader.getResource(CONFIG_FILENAME));
31
32 /***
33 * Loads properties stored in a file.
34 * @param url The url to the file
35 * @return The Properties object.
36 */
37
38 protected static Properties loadProperties(URL url)
39 {
40 Properties result = new Properties();
41 logger.debug("Reading configuration from URL " + url);
42 try
43 {
44 result.load(url.openStream());
45 } catch (java.io.IOException e)
46 {
47 logger.error("Could not read configuration file from URL [" + url + "].", e);
48 }
49 return result;
50 }
51
52 /***
53 * Get a config setting
54 * @param paramName The setting's name
55 * @return The value
56 */
57 protected static String getString(String paramName)
58 {
59 return properties.getProperty(paramName);
60 }
61
62 /***
63 * Helper method that returns true for
64 * "true" and "yes"
65 */
66
67 protected static boolean getBoolean(String paramName)
68 {
69 String paramValue = getString(paramName);
70 if (paramValue == null)
71 return false;
72
73 if (paramValue.equals("true")
74 || paramValue.equals("yes"))
75 return true;
76
77 return false;
78 }
79 }
80