diff artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java @ 19:1259d192e3c3

* New configuration based on config directory * Artifact database launches REST web server at startup. artifacts/trunk@43 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 09 Sep 2009 07:55:44 +0000
parents 5a6b6a3debc7
children 00596a591a2f
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java	Tue Sep 08 07:51:34 2009 +0000
+++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/Config.java	Wed Sep 09 07:55:44 2009 +0000
@@ -29,9 +29,13 @@
 {
     private static Logger logger = Logger.getLogger(Config.class);
 
-    public static final String CONFIG_PROPERTY = "artifact.database.config";
+    public static final String CONFIG_DIR = "artifact.database.dir";
 
-    public static final String CONFIG_DEFAULT  = "artifactdb-conf.xml";
+    public static final File CONFIG_DIR_DEFAULT =
+        new File(new File(System.getProperty("user.home",
+            System.getProperty("user.dir", "."))), ".artifactdb");
+
+    public static final String CONFIG_FILE  = "conf.xml";
 
     private static Document config;
 
@@ -45,9 +49,26 @@
         return config;
     }
 
+    public static File getConfigDirectory() {
+        String configDirString = System.getProperty(CONFIG_DIR);
+
+        File configDir = configDirString != null
+            ? new File(configDirString)
+            : CONFIG_DIR_DEFAULT;
+
+        if (!configDir.isDirectory()) {
+            logger.warn("'" + configDir + "' is not a directory.");
+            configDir = CONFIG_DIR_DEFAULT;
+        }
+
+        return configDir;
+    }
+
     private static Document loadConfig() {
-        File file = new File(
-            System.getProperty(CONFIG_PROPERTY, CONFIG_DEFAULT));
+
+        File configDir = getConfigDirectory();
+
+        File file = new File(configDir, CONFIG_FILE);
 
         if (!file.canRead() && !file.isFile()) {
             logger.error("Cannot read config file '"

http://dive4elements.wald.intevation.org