1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
package net.sf.tlc.core.impl; |
7 |
|
|
8 |
|
import java.io.File; |
9 |
|
import java.io.FileInputStream; |
10 |
|
import java.io.FileNotFoundException; |
11 |
|
import java.io.IOException; |
12 |
|
import java.util.Properties; |
13 |
|
import java.util.logging.Level; |
14 |
|
import java.util.logging.Logger; |
15 |
|
|
16 |
|
import net.sf.tlc.core.PropertyManager; |
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
3 |
public final class DefaultPropertyManager implements PropertyManager { |
24 |
|
|
25 |
57 |
private static final Logger logger = Logger.getLogger(DefaultPropertyManager.class.getName()); |
26 |
|
|
27 |
|
private final Properties properties; |
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
40 |
public DefaultPropertyManager(final File file) { |
34 |
40 |
properties = new Properties(); |
35 |
|
try { |
36 |
40 |
properties.load(new FileInputStream(file)); |
37 |
0 |
} catch (FileNotFoundException e) { |
38 |
0 |
logger.log(Level.WARNING, "File not found: \"" + file.getName() + "\"", e); |
39 |
0 |
} catch (IOException e) { |
40 |
0 |
logger.log(Level.SEVERE, "IOException", e); |
41 |
36 |
} |
42 |
40 |
} |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
|
48 |
|
public DefaultPropertyManager(final String propertyFile) { |
49 |
40 |
this(new File(propertyFile)); |
50 |
40 |
} |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
public Properties getProperties() { |
58 |
10 |
return this.properties; |
59 |
|
} |
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
public String getProperty(final String key) { |
67 |
40 |
return this.properties.getProperty(key); |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
public String getProperty(final String key, class="keyword">final String defaultValue) { |
75 |
30 |
String result = getProperty(key); |
76 |
30 |
if (null == result) { |
77 |
30 |
result = defaultValue; |
78 |
|
} |
79 |
30 |
return result; |
80 |
|
} |
81 |
|
|
82 |
|
} |