[FIX] The Properties is always null

This commit is contained in:
Maxime Sinclair
2014-01-09 16:53:35 +01:00
parent 567a92f158
commit 20de5a0d5d

View File

@@ -30,55 +30,54 @@ import java.util.Properties;
public class Configuration { public class Configuration {
private static Configuration instance; private static Configuration instance;
private Properties config; private Properties config;
/** /**
* Singleton constructor * Singleton constructor
*/ */
private Configuration() { private Configuration() {
Properties config = new Properties(); config = new Properties();
// Default values // Default values
config.setProperty("SHOW_SOCIAL_BUTTONS", "off"); config.setProperty("SHOW_SOCIAL_BUTTONS", "off");
config.setProperty("USE_GOOGLE_TRACKER", "off"); config.setProperty("USE_GOOGLE_TRACKER", "off");
// End of default values // End of default values
try { try {
InputStream is = Thread.currentThread().getContextClassLoader(). InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties");
getResourceAsStream("config.properties"); if (is != null) {
if (is != null) { config.load(is);
config.load(is); is.close();
is.close(); }
} } catch (IOException e) {
} catch (IOException e) { // Just log a warning
// Just log a warning e.printStackTrace();
e.printStackTrace(); }
} }
}
/** /**
* Get the configuration * Get the configuration
* *
* @return the complete configuration * @return the complete configuration
*/ */
public static Properties get() { public static Properties get() {
if (instance == null) { if (instance == null) {
instance = new Configuration(); instance = new Configuration();
} }
return instance.config; return instance.config;
} }
/** /**
* Get a boolean configuration value * Get a boolean configuration value
* *
* @return true if the value is "on" * @return true if the value is "on"
*/ */
public static boolean get(String key) { public static boolean get(String key) {
if (instance.config.getProperty(key) == null) { if (instance.config.getProperty(key) == null) {
return false; return false;
} }
return instance.config.getProperty(key).startsWith("on"); return instance.config.getProperty(key).startsWith("on");
} }
} }