Code formating and whitespace cleanup
[jpim.git] / src / de / j32 / pimstuff / conduit / Config.java
1 package de.j32.pimstuff.conduit;
2
3 import java.io.FileInputStream;
4 import java.io.FileNotFoundException;
5 import java.io.IOException;
6 import java.util.InvalidPropertiesFormatException;
7 import java.util.Properties;
8
9 public class Config
10 {
11     static Config instance;
12     Properties config = new Properties();
13
14     public static String get(String key, String defaultValue)
15     {
16         load();
17
18         if (instance == null) return defaultValue;
19         else {
20             String rv = instance.config.getProperty(key);
21             if (rv == null) return defaultValue;
22             return rv;
23         }
24     }
25
26     public static String get(String key)
27     {
28         String rv = get(key, null);
29         if (rv == null) throw new ConfigurationException(
30                 "missing configuration parameter: " + key);
31         return rv;
32     }
33
34     static void load()
35     {
36         if (instance == null) try {
37             instance = new Config();
38         }
39         catch (InvalidPropertiesFormatException e) {}
40         catch (FileNotFoundException e) {}
41         catch (IOException e) {}
42     }
43
44     Config() throws InvalidPropertiesFormatException, FileNotFoundException,
45             IOException
46     {
47         config.loadFromXML(new FileInputStream("config.xml"));
48     }
49
50 }