Skip to content

Commit

Permalink
[FIX] The Properties is always null
Browse files Browse the repository at this point in the history
  • Loading branch information
maximesinclair committed Jan 9, 2014
1 parent 567a92f commit 20de5a0
Showing 1 changed file with 47 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,55 +30,54 @@

public class Configuration {

private static Configuration instance;
private Properties config;
private static Configuration instance;
private Properties config;

/**
* Singleton constructor
*/
private Configuration() {
Properties config = new Properties();

// Default values
config.setProperty("SHOW_SOCIAL_BUTTONS", "off");
config.setProperty("USE_GOOGLE_TRACKER", "off");
// End of default values

try {
InputStream is = Thread.currentThread().getContextClassLoader().
getResourceAsStream("config.properties");
if (is != null) {
config.load(is);
is.close();
}
} catch (IOException e) {
// Just log a warning
e.printStackTrace();
}
}
/**
* Singleton constructor
*/
private Configuration() {
config = new Properties();

/**
* Get the configuration
*
* @return the complete configuration
*/
public static Properties get() {
if (instance == null) {
instance = new Configuration();
}
return instance.config;
}

/**
* Get a boolean configuration value
*
* @return true if the value is "on"
*/
public static boolean get(String key) {
if (instance.config.getProperty(key) == null) {
return false;
}
return instance.config.getProperty(key).startsWith("on");
}
// Default values
config.setProperty("SHOW_SOCIAL_BUTTONS", "off");
config.setProperty("USE_GOOGLE_TRACKER", "off");
// End of default values

try {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties");
if (is != null) {
config.load(is);
is.close();
}
} catch (IOException e) {
// Just log a warning
e.printStackTrace();
}
}

/**
* Get the configuration
*
* @return the complete configuration
*/
public static Properties get() {
if (instance == null) {
instance = new Configuration();
}
return instance.config;
}

/**
* Get a boolean configuration value
*
* @return true if the value is "on"
*/
public static boolean get(String key) {
if (instance.config.getProperty(key) == null) {
return false;
}
return instance.config.getProperty(key).startsWith("on");
}

}

0 comments on commit 20de5a0

Please sign in to comment.