aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2016-10-27 16:42:05 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2016-10-27 16:42:05 +1300
commit0177128690d52c65d46b56411ff96da62e5388a2 (patch)
treefc1c8761d7fac7a854749e09cb8edc2bc830de88 /src/org/traccar
parentb0eac0c99ea3d8e7eb6e5d95d03629460be06927 (diff)
downloadtrackermap-server-0177128690d52c65d46b56411ff96da62e5388a2.tar.gz
trackermap-server-0177128690d52c65d46b56411ff96da62e5388a2.tar.bz2
trackermap-server-0177128690d52c65d46b56411ff96da62e5388a2.zip
Implement default config (fix #2484)
Diffstat (limited to 'src/org/traccar')
-rw-r--r--src/org/traccar/Config.java55
1 files changed, 34 insertions, 21 deletions
diff --git a/src/org/traccar/Config.java b/src/org/traccar/Config.java
index 7fd725734..e63444f1f 100644
--- a/src/org/traccar/Config.java
+++ b/src/org/traccar/Config.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2015 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,19 +23,44 @@ import java.util.Properties;
public class Config {
private final Properties properties = new Properties();
+ private Properties defaultProperties;
public void load(String file) throws IOException {
try (InputStream inputStream = new FileInputStream(file)) {
properties.loadFromXML(inputStream);
}
+
+ String defaultConfigFile = properties.getProperty("config.default");
+ if (defaultConfigFile != null) {
+ try (InputStream inputStream = new FileInputStream(defaultConfigFile)) {
+ defaultProperties = new Properties();
+ defaultProperties.loadFromXML(inputStream);
+ }
+ }
}
public boolean hasKey(String key) {
- return properties.containsKey(key);
+ return properties.containsKey(key) || (defaultProperties != null && defaultProperties.containsKey(key));
+ }
+
+ public String getString(String key) {
+ if (properties.containsKey(key) || defaultProperties == null) {
+ return properties.getProperty(key);
+ } else {
+ return defaultProperties.getProperty(key);
+ }
+ }
+
+ public String getString(String key, String defaultValue) {
+ if (hasKey(key)) {
+ return getString(key);
+ } else {
+ return defaultValue;
+ }
}
public boolean getBoolean(String key) {
- return Boolean.parseBoolean(properties.getProperty(key));
+ return Boolean.parseBoolean(getString(key));
}
public int getInteger(String key) {
@@ -43,8 +68,8 @@ public class Config {
}
public int getInteger(String key, int defaultValue) {
- if (properties.containsKey(key)) {
- return Integer.parseInt(properties.getProperty(key));
+ if (hasKey(key)) {
+ return Integer.parseInt(getString(key));
} else {
return defaultValue;
}
@@ -55,20 +80,8 @@ public class Config {
}
public long getLong(String key, long defaultValue) {
- if (properties.containsKey(key)) {
- return Long.parseLong(properties.getProperty(key));
- } else {
- return defaultValue;
- }
- }
-
- public String getString(String key) {
- return properties.getProperty(key);
- }
-
- public String getString(String key, String defaultValue) {
- if (properties.containsKey(key)) {
- return properties.getProperty(key);
+ if (hasKey(key)) {
+ return Long.parseLong(getString(key));
} else {
return defaultValue;
}
@@ -79,8 +92,8 @@ public class Config {
}
public double getDouble(String key, double defaultValue) {
- if (properties.containsKey(key)) {
- return Double.parseDouble(properties.getProperty(key));
+ if (hasKey(key)) {
+ return Double.parseDouble(getString(key));
} else {
return defaultValue;
}