mirror of
https://github.com/octoleo/plantuml-server.git
synced 2024-12-22 08:48:54 +00:00
[FIX] The Properties is always null
This commit is contained in:
parent
567a92f158
commit
20de5a0d5d
@ -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
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Default values
|
||||||
* Get the configuration
|
config.setProperty("SHOW_SOCIAL_BUTTONS", "off");
|
||||||
*
|
config.setProperty("USE_GOOGLE_TRACKER", "off");
|
||||||
* @return the complete configuration
|
// End of default values
|
||||||
*/
|
|
||||||
public static Properties get() {
|
try {
|
||||||
if (instance == null) {
|
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("config.properties");
|
||||||
instance = new Configuration();
|
if (is != null) {
|
||||||
}
|
config.load(is);
|
||||||
return instance.config;
|
is.close();
|
||||||
}
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
/**
|
// Just log a warning
|
||||||
* Get a boolean configuration value
|
e.printStackTrace();
|
||||||
*
|
}
|
||||||
* @return true if the value is "on"
|
}
|
||||||
*/
|
|
||||||
public static boolean get(String key) {
|
/**
|
||||||
if (instance.config.getProperty(key) == null) {
|
* Get the configuration
|
||||||
return false;
|
*
|
||||||
}
|
* @return the complete configuration
|
||||||
return instance.config.getProperty(key).startsWith("on");
|
*/
|
||||||
}
|
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");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user