From 0177128690d52c65d46b56411ff96da62e5388a2 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Thu, 27 Oct 2016 16:42:05 +1300 Subject: Implement default config (fix #2484) --- debug.xml | 469 +++----------------------------------------- setup/default.xml | 442 +++++++++++++++++++++++++++++++++++++++++ setup/traccar.xml | 386 +----------------------------------- src/org/traccar/Config.java | 55 ++++-- 4 files changed, 505 insertions(+), 847 deletions(-) create mode 100644 setup/default.xml diff --git a/debug.xml b/debug.xml index 755508aa6..31f38c356 100644 --- a/debug.xml +++ b/debug.xml @@ -4,19 +4,22 @@ + ./setup/default.xml + true - 8082 - - traccar-web/web + ./traccar-web/web true true - 30000 - true + + + false nominatim http://nominatim.openstreetmap.org/reverse @@ -25,8 +28,6 @@ 260 2 - true - - false + - false - power ignition battery - - true - true - true - true - true - true - true - true + + Authorization: Basic QWxhZGRpbjpPcGVuU2VzYW1l--> + + + + + + + org.h2.Driver jdbc:h2:./target/database sa true - - - false - - false - true ./schema/changelog-master.xml - 7 - - - SELECT * FROM server - - - - UPDATE server SET - registration = :registration, - readonly = :readonly, - map = :map, - bingKey = :bingKey, - mapUrl = :mapUrl, - distanceUnit = :distanceUnit, - speedUnit = :speedUnit, - latitude = :latitude, - longitude = :longitude, - zoom = :zoom, - twelveHourFormat = :twelveHourFormat, - attributes = :attributes - WHERE id = :id - - - - SELECT * FROM users - WHERE email = :email - - - - SELECT * FROM users - - - - INSERT INTO users (name, email, hashedPassword, salt, admin, map, distanceUnit, speedUnit, latitude, longitude, zoom, twelveHourFormat, attributes) - VALUES (:name, :email, :hashedPassword, :salt, :admin, :map, :distanceUnit, :speedUnit, :latitude, :longitude, :zoom, :twelveHourFormat, :attributes) - - - - UPDATE users SET - name = :name, - email = :email, - admin = :admin, - map = :map, - distanceUnit = :distanceUnit, - speedUnit = :speedUnit, - latitude = :latitude, - longitude = :longitude, - zoom = :zoom, - twelveHourFormat = :twelveHourFormat, - attributes = :attributes - WHERE id = :id - - - - UPDATE users SET hashedPassword = :hashedPassword, salt = :salt WHERE id = :id - - - - DELETE FROM users WHERE id = :id - - - - SELECT userId, deviceId FROM user_device - - - - SELECT userId, groupId FROM user_group - - - - SELECT * FROM devices - - - - INSERT INTO devices (name, uniqueId, groupId, attributes, phone, model, contact, category) - VALUES (:name, :uniqueId, :groupId, :attributes, :phone, :model, :contact, :category) - - - - UPDATE devices SET - name = :name, - uniqueId = :uniqueId, - groupId = :groupId, - attributes = :attributes, - phone = :phone, - model = :model, - contact = :contact, - category = :category - WHERE id = :id - - - - UPDATE devices SET lastUpdate = :lastUpdate WHERE id = :id - - - - DELETE FROM devices WHERE id = :id - - - - INSERT INTO user_device (userId, deviceId) VALUES (:userId, :deviceId) - - - - DELETE FROM user_device WHERE userId = :userId AND deviceId = :deviceId - - - - SELECT * FROM groups - - - - INSERT INTO groups (name, groupId, attributes) VALUES (:name, :groupId, :attributes) - - - - UPDATE groups SET name = :name, groupId = :groupId, attributes = :attributes WHERE id = :id - - - - DELETE FROM groups WHERE id = :id - - - - INSERT INTO user_group (userId, groupId) VALUES (:userId, :groupId) - - - - DELETE FROM user_group WHERE userId = :userId AND groupId = :groupId - - - - SELECT * FROM positions WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to ORDER BY fixTime - - - - INSERT INTO positions (deviceId, protocol, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, address, attributes) - VALUES (:deviceId, :protocol, :now, :deviceTime, :fixTime, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :attributes) - - - - SELECT * FROM positions WHERE id IN (SELECT positionId FROM devices) - - - - UPDATE devices SET positionId = :id WHERE id = :deviceId - - - - SELECT * FROM events WHERE id = :id - - - - INSERT INTO events (type, serverTime, deviceId, positionId, geofenceId, attributes) - VALUES (:type, :serverTime, :deviceId, :positionId, :geofenceId, :attributes) - - - - SELECT * FROM events WHERE deviceId = :deviceId AND serverTime BETWEEN :from AND :to ORDER BY serverTime - - - - SELECT * FROM geofences - - - - INSERT INTO geofences (name, description, area, attributes) - VALUES (:name, :description, :area, :attributes) - - - - UPDATE geofences SET - name = :name, - description = :description, - area = :area, - attributes = :attributes - WHERE id = :id - - - - DELETE FROM geofences WHERE id = :id - - - - SELECT userId, geofenceId FROM user_geofence - - - - INSERT INTO user_geofence (userId, geofenceId) VALUES (:userId, :geofenceId) - - - - DELETE FROM user_geofence WHERE userId = :userId AND geofenceId = :geofenceId - - - - SELECT groupId, geofenceId FROM group_geofence - - - - INSERT INTO group_geofence (groupId, geofenceId) VALUES (:groupId, :geofenceId) - - - - DELETE FROM group_geofence WHERE groupId = :groupId AND geofenceId = :geofenceId - - - - SELECT deviceId, geofenceId FROM device_geofence - - - - INSERT INTO device_geofence (deviceId, geofenceId) VALUES (:deviceId, :geofenceId) - - - - DELETE FROM device_geofence WHERE deviceId = :deviceId AND geofenceId = :geofenceId - - - - SELECT * FROM notifications - - - - INSERT INTO notifications (userId, type, attributes) - VALUES (:userId, :type, :attributes) - - - - UPDATE notifications SET - userId = :userId, - type = :type, - attributes = :attributes - WHERE id = :id - - - - DELETE FROM notifications WHERE id = :id - - - - DELETE FROM positions WHERE serverTime < :serverTime AND id NOT IN (SELECT positionId FROM devices) - - - - SELECT * FROM attribute_aliases - - - - INSERT INTO attribute_aliases (deviceId, attribute, alias) - VALUES (:deviceId, :attribute, :alias) - - - - UPDATE attribute_aliases SET - deviceId = :deviceId, - attribute = :attribute, - alias = :alias - WHERE id = :id - - - - DELETE FROM attribute_aliases WHERE id = :id - - - - SELECT * FROM statistics WHERE captureTime BETWEEN :from AND :to ORDER BY captureTime - - - - INSERT INTO statistics (captureTime, activeUsers, activeDevices, requests, messagesReceived, messagesStored, attributes) - VALUES (:captureTime, :activeUsers, :activeDevices, :requests, :messagesReceived, :messagesStored, :attributes) - + - 5001 - 5002 - 5003 - 5004 - 5005 - 5006 - false - 5007 - 5008 - 5009 - 5010 - 5011 - 5012 - 5013 - 5014 - 5015 - 5016 - 5017 - 5018 - 5019 - 5020 - 5021 - 5022 - 5023 - 5024 - 5025 - 5026 - 5027 - 5028 - 5029 - 5030 - 5031 - 5032 - 5033 - 5034 - 5035 - 5036 - - 5038 - 5039 - 5040 - 5041 - 5042 - 5043 - 5044 - 5045 - 5046 - 5047 - 5048 - 5049 - 5050 - 5051 - 5052 - 5053 - 5054 - 5055 - 5056 - 5057 - 5058 - 5059 - 5060 - 5061 - 5062 - 5063 - 5064 - 5065 - 5066 - 5067 - 5068 - 5069 - 5070 - 5071 - 5072 - 5073 - 5074 - 5075 - 5076 - 5077 - 5078 - 5079 - 5080 - 5081 - 5082 - 5083 - 5084 - 5085 - 5086 - 5087 - 5088 - 5089 - 5090 - 5091 - 5092 - 5093 - 5094 - 5095 - 5096 - 5097 - 5098 - 5099 - 5100 - 5101 - 5102 - 5103 - 5104 - 5105 - 5106 - 5107 - 5108 - 5109 - 5110 - 5111 - 5112 - 5113 - 5114 - 5115 - 5116 - 5117 - 5118 - 5119 - 5120 - 5121 - 5122 - 5123 - 5124 - 5125 - 5126 - 5127 + 6037 diff --git a/setup/default.xml b/setup/default.xml new file mode 100644 index 000000000..8b1cfaeba --- /dev/null +++ b/setup/default.xml @@ -0,0 +1,442 @@ + + + + + + + + + true + 8082 + ./web + + true + google + + true + all + ./logs/tracker-server.log + + true + true + true + true + true + true + true + + + + org.h2.Driver + jdbc:h2:./data/database + sa + + + true + + ./schema/changelog-master.xml + + + SELECT * FROM server + + + + UPDATE server SET + registration = :registration, + readonly = :readonly, + map = :map, + bingKey = :bingKey, + mapUrl = :mapUrl, + distanceUnit = :distanceUnit, + speedUnit = :speedUnit, + latitude = :latitude, + longitude = :longitude, + zoom = :zoom, + twelveHourFormat = :twelveHourFormat, + attributes = :attributes + WHERE id = :id + + + + SELECT * FROM users + WHERE email = :email + + + + SELECT * FROM users + + + + INSERT INTO users (name, email, hashedPassword, salt, admin, map, distanceUnit, speedUnit, latitude, longitude, zoom, twelveHourFormat, attributes) + VALUES (:name, :email, :hashedPassword, :salt, :admin, :map, :distanceUnit, :speedUnit, :latitude, :longitude, :zoom, :twelveHourFormat, :attributes) + + + + UPDATE users SET + name = :name, + email = :email, + admin = :admin, + map = :map, + distanceUnit = :distanceUnit, + speedUnit = :speedUnit, + latitude = :latitude, + longitude = :longitude, + zoom = :zoom, + twelveHourFormat = :twelveHourFormat, + attributes = :attributes + WHERE id = :id + + + + UPDATE users SET hashedPassword = :hashedPassword, salt = :salt WHERE id = :id + + + + DELETE FROM users WHERE id = :id + + + + SELECT userId, deviceId FROM user_device + + + + SELECT userId, groupId FROM user_group + + + + SELECT * FROM devices + + + + INSERT INTO devices (name, uniqueId, groupId, attributes, phone, model, contact, category) + VALUES (:name, :uniqueId, :groupId, :attributes, :phone, :model, :contact, :category) + + + + UPDATE devices SET + name = :name, + uniqueId = :uniqueId, + groupId = :groupId, + attributes = :attributes, + phone = :phone, + model = :model, + contact = :contact, + category = :category + WHERE id = :id + + + + UPDATE devices SET lastUpdate = :lastUpdate WHERE id = :id + + + + DELETE FROM devices WHERE id = :id + + + + INSERT INTO user_device (userId, deviceId) VALUES (:userId, :deviceId) + + + + DELETE FROM user_device WHERE userId = :userId AND deviceId = :deviceId + + + + SELECT * FROM groups + + + + INSERT INTO groups (name, groupId, attributes) VALUES (:name, :groupId, :attributes) + + + + UPDATE groups SET name = :name, groupId = :groupId, attributes = :attributes WHERE id = :id + + + + DELETE FROM groups WHERE id = :id + + + + INSERT INTO user_group (userId, groupId) VALUES (:userId, :groupId) + + + + DELETE FROM user_group WHERE userId = :userId AND groupId = :groupId + + + + SELECT * FROM positions WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to ORDER BY fixTime + + + + INSERT INTO positions (deviceId, protocol, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, address, attributes) + VALUES (:deviceId, :protocol, :now, :deviceTime, :fixTime, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :attributes) + + + + SELECT * FROM positions WHERE id IN (SELECT positionId FROM devices) + + + + UPDATE devices SET positionId = :id WHERE id = :deviceId + + + + SELECT * FROM events WHERE id = :id + + + + INSERT INTO events (type, serverTime, deviceId, positionId, geofenceId, attributes) + VALUES (:type, :serverTime, :deviceId, :positionId, :geofenceId, :attributes) + + + + SELECT * FROM events WHERE deviceId = :deviceId AND serverTime BETWEEN :from AND :to ORDER BY serverTime + + + + SELECT * FROM geofences + + + + INSERT INTO geofences (name, description, area, attributes) + VALUES (:name, :description, :area, :attributes) + + + + UPDATE geofences SET + name = :name, + description = :description, + area = :area, + attributes = :attributes + WHERE id = :id + + + + DELETE FROM geofences WHERE id = :id + + + + SELECT userId, geofenceId FROM user_geofence + + + + INSERT INTO user_geofence (userId, geofenceId) VALUES (:userId, :geofenceId) + + + + DELETE FROM user_geofence WHERE userId = :userId AND geofenceId = :geofenceId + + + + SELECT groupId, geofenceId FROM group_geofence + + + + INSERT INTO group_geofence (groupId, geofenceId) VALUES (:groupId, :geofenceId) + + + + DELETE FROM group_geofence WHERE groupId = :groupId AND geofenceId = :geofenceId + + + + SELECT deviceId, geofenceId FROM device_geofence + + + + INSERT INTO device_geofence (deviceId, geofenceId) VALUES (:deviceId, :geofenceId) + + + + DELETE FROM device_geofence WHERE deviceId = :deviceId AND geofenceId = :geofenceId + + + + SELECT * FROM notifications + + + + INSERT INTO notifications (userId, type, attributes) + VALUES (:userId, :type, :attributes) + + + + UPDATE notifications SET + userId = :userId, + type = :type, + attributes = :attributes + WHERE id = :id + + + + DELETE FROM notifications WHERE id = :id + + + + DELETE FROM positions WHERE serverTime < :serverTime AND id NOT IN (SELECT positionId FROM devices) + + + + SELECT * FROM attribute_aliases + + + + INSERT INTO attribute_aliases (deviceId, attribute, alias) + VALUES (:deviceId, :attribute, :alias) + + + + UPDATE attribute_aliases SET + deviceId = :deviceId, + attribute = :attribute, + alias = :alias + WHERE id = :id + + + + DELETE FROM attribute_aliases WHERE id = :id + + + + SELECT * FROM statistics WHERE captureTime BETWEEN :from AND :to ORDER BY captureTime + + + + INSERT INTO statistics (captureTime, activeUsers, activeDevices, requests, messagesReceived, messagesStored, attributes) + VALUES (:captureTime, :activeUsers, :activeDevices, :requests, :messagesReceived, :messagesStored, :attributes) + + + + + 5001 + 5002 + 5003 + 5004 + 5005 + 5006 + false + 5007 + 5008 + 5009 + 5010 + 5011 + 5012 + 5013 + 5014 + 5015 + 5016 + 5017 + 5018 + 5019 + 5020 + 5021 + 5022 + 5023 + 5024 + 5025 + 5026 + 5027 + 5028 + 5029 + 5030 + 5031 + 5032 + 5033 + 5034 + 5035 + 5036 + 5037 + 5038 + 5039 + 5040 + 5041 + 5042 + 5043 + 5044 + 5045 + 5046 + 5047 + 5048 + 5049 + 5050 + 5051 + 5052 + 5053 + 5054 + 5055 + 5056 + 5057 + 5058 + 5059 + 5060 + 5061 + 5062 + 5063 + 5064 + 5065 + 5066 + 5067 + 5068 + 5069 + 5070 + 5071 + 5072 + 5073 + 5074 + 5075 + 5076 + 5077 + 5078 + 5079 + 5080 + 5081 + 5082 + 5083 + 5084 + 5085 + 5086 + 5087 + 5088 + 5089 + 5090 + 5091 + 5092 + 5093 + 5094 + 5095 + 5096 + 5097 + 5098 + 5099 + 5100 + 5101 + 5102 + 5103 + 5104 + 5105 + 5106 + 5107 + 5108 + 5109 + 5110 + 5111 + 5112 + 5113 + 5114 + 5115 + 5116 + 5117 + 5118 + 5119 + 5120 + 5121 + 5122 + 5123 + 5124 + 5125 + 5126 + 5127 + + diff --git a/setup/traccar.xml b/setup/traccar.xml index c13abb3e2..e4b3e9167 100644 --- a/setup/traccar.xml +++ b/setup/traccar.xml @@ -4,390 +4,6 @@ - - - true - 8082 - ./web - - true - google - - true - all - ./logs/tracker-server.log - - true - true - true - true - true - true - true - - - - org.h2.Driver - jdbc:h2:./data/database - sa - - - true - - ./schema/changelog-master.xml - - - SELECT * FROM server; - - - - UPDATE server SET - registration = :registration, - readonly = :readonly, - map = :map, - bingKey = :bingKey, - mapUrl = :mapUrl, - distanceUnit = :distanceUnit, - speedUnit = :speedUnit, - latitude = :latitude, - longitude = :longitude, - zoom = :zoom, - twelveHourFormat = :twelveHourFormat, - attributes = :attributes - WHERE id = :id; - - - - SELECT * FROM users - WHERE email = :email; - - - - SELECT * FROM users; - - - - INSERT INTO users (name, email, hashedPassword, salt, admin, map, distanceUnit, speedUnit, latitude, longitude, zoom, twelveHourFormat, attributes) - VALUES (:name, :email, :hashedPassword, :salt, :admin, :map, :distanceUnit, :speedUnit, :latitude, :longitude, :zoom, :twelveHourFormat, :attributes); - - - - UPDATE users SET - name = :name, - email = :email, - admin = :admin, - map = :map, - distanceUnit = :distanceUnit, - speedUnit = :speedUnit, - latitude = :latitude, - longitude = :longitude, - zoom = :zoom, - twelveHourFormat = :twelveHourFormat, - attributes = :attributes - WHERE id = :id; - - - - UPDATE users SET hashedPassword = :hashedPassword, salt = :salt WHERE id = :id; - - - - DELETE FROM users WHERE id = :id; - - - - SELECT userId, deviceId FROM user_device; - - - - SELECT userId, groupId FROM user_group; - - - - SELECT * FROM devices; - - - - INSERT INTO devices (name, uniqueId, groupId, attributes) VALUES (:name, :uniqueId, :groupId, :attributes); - - - - UPDATE devices SET name = :name, uniqueId = :uniqueId, groupId = :groupId, attributes = :attributes WHERE id = :id; - - - - UPDATE devices SET lastUpdate = :lastUpdate WHERE id = :id; - - - - DELETE FROM devices WHERE id = :id; - - - - INSERT INTO user_device (userId, deviceId) VALUES (:userId, :deviceId); - - - - DELETE FROM user_device WHERE userId = :userId AND deviceId = :deviceId; - - - - SELECT * FROM groups; - - - - INSERT INTO groups (name, groupId, attributes) VALUES (:name, :groupId, :attributes); - - - - UPDATE groups SET name = :name, groupId = :groupId, attributes = :attributes WHERE id = :id; - - - - DELETE FROM groups WHERE id = :id; - - - - INSERT INTO user_group (userId, groupId) VALUES (:userId, :groupId); - - - - DELETE FROM user_group WHERE userId = :userId AND groupId = :groupId; - - - - SELECT * FROM positions WHERE deviceId = :deviceId AND fixTime BETWEEN :from AND :to ORDER BY fixTime; - - - - INSERT INTO positions (deviceId, protocol, serverTime, deviceTime, fixTime, valid, latitude, longitude, altitude, speed, course, address, attributes) - VALUES (:deviceId, :protocol, :now, :deviceTime, :fixTime, :valid, :latitude, :longitude, :altitude, :speed, :course, :address, :attributes); - - - - SELECT * FROM positions WHERE id IN (SELECT positionId FROM devices); - - - - UPDATE devices SET positionId = :id WHERE id = :deviceId; - - - - SELECT * FROM events WHERE id = :id; - - - - INSERT INTO events (type, serverTime, deviceId, positionId, geofenceId, attributes) - VALUES (:type, :serverTime, :deviceId, :positionId, :geofenceId, :attributes); - - - - SELECT * FROM events WHERE deviceId = :deviceId AND type LIKE :type AND serverTime BETWEEN :from AND :to ORDER BY serverTime DESC; - - - - SELECT * FROM geofences; - - - - INSERT INTO geofences (name, description, area, attributes) - VALUES (:name, :description, :area, :attributes); - - - - UPDATE geofences SET - name = :name, - description = :description, - area = :area, - attributes = :attributes - WHERE id = :id; - - - - DELETE FROM geofences WHERE id = :id; - - - - SELECT userId, geofenceId FROM user_geofence; - - - - INSERT INTO user_geofence (userId, geofenceId) VALUES (:userId, :geofenceId); - - - - DELETE FROM user_geofence WHERE userId = :userId AND geofenceId = :geofenceId; - - - - SELECT groupId, geofenceId FROM group_geofence; - - - - INSERT INTO group_geofence (groupId, geofenceId) VALUES (:groupId, :geofenceId); - - - - DELETE FROM group_geofence WHERE groupId = :groupId AND geofenceId = :geofenceId; - - - - SELECT deviceId, geofenceId FROM device_geofence; - - - - INSERT INTO device_geofence (deviceId, geofenceId) VALUES (:deviceId, :geofenceId); - - - - DELETE FROM device_geofence WHERE deviceId = :deviceId AND geofenceId = :geofenceId; - - - - SELECT * FROM notifications; - - - - INSERT INTO notifications (userId, type, attributes) - VALUES (:userId, :type, :attributes); - - - - UPDATE notifications SET - userId = :userId, - type = :type, - attributes = :attributes - WHERE id = :id; - - - - DELETE FROM notifications WHERE id = :id; - - - - DELETE FROM positions WHERE serverTime < :serverTime AND id NOT IN (SELECT positionId FROM devices); - - - - - 5001 - 5002 - 5003 - 5004 - 5005 - 5006 - false - 5007 - 5008 - 5009 - 5010 - 5011 - 5012 - 5013 - 5014 - 5015 - 5016 - 5017 - 5018 - 5019 - 5020 - 5021 - 5022 - 5023 - 5024 - 5025 - 5026 - 5027 - 5028 - 5029 - 5030 - 5031 - 5032 - 5033 - 5034 - 5035 - 5036 - 5037 - 5038 - 5039 - 5040 - 5041 - 5042 - 5043 - 5044 - 5045 - 5046 - 5047 - 5048 - 5049 - 5050 - 5051 - 5052 - 5053 - 5054 - 5055 - 5056 - 5057 - 5058 - 5059 - 5060 - 5061 - 5062 - 5063 - 5064 - 5065 - 5066 - 5067 - 5068 - 5069 - 5070 - 5071 - 5072 - 5073 - 5074 - 5075 - 5076 - 5077 - 5078 - 5079 - 5080 - 5081 - 5082 - 5083 - 5084 - 5085 - 5086 - 5087 - 5088 - 5089 - 5090 - 5091 - 5092 - 5093 - 5094 - 5095 - 5096 - 5097 - 5098 - 5099 - 5100 - 5101 - 5102 - 5103 - 5104 - 5105 - 5106 - 5107 - 5108 - 5109 - 5110 - 5111 - 5112 - 5113 - 5114 - 5115 - 5116 - 5117 - 5118 + ./conf/default.xml 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; } -- cgit v1.2.3