summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/config/Config.java
diff options
context:
space:
mode:
authorJonathan Bauer2014-09-22 16:55:49 +0200
committerJonathan Bauer2014-09-22 16:55:49 +0200
commit8379b2e4a5dd76fcbd344b7a152dc14629f64ae9 (patch)
tree3b5082edd282f0143b5ea67ebf3f0956b8eed814 /dozentenmodul/src/main/java/config/Config.java
parent[client] NEW: Logging mechanisms for the client (diff)
downloadtutor-module-8379b2e4a5dd76fcbd344b7a152dc14629f64ae9.tar.gz
tutor-module-8379b2e4a5dd76fcbd344b7a152dc14629f64ae9.tar.xz
tutor-module-8379b2e4a5dd76fcbd344b7a152dc14629f64ae9.zip
[client] do commit the changes :)
Diffstat (limited to 'dozentenmodul/src/main/java/config/Config.java')
-rw-r--r--dozentenmodul/src/main/java/config/Config.java29
1 files changed, 23 insertions, 6 deletions
diff --git a/dozentenmodul/src/main/java/config/Config.java b/dozentenmodul/src/main/java/config/Config.java
index 95547b5f..547e0ad5 100644
--- a/dozentenmodul/src/main/java/config/Config.java
+++ b/dozentenmodul/src/main/java/config/Config.java
@@ -1,8 +1,10 @@
package config;
+
import java.io.File;
import java.io.IOException;
+import org.apache.log4j.Logger;
import org.ini4j.Wini;
/**
@@ -14,6 +16,11 @@ import org.ini4j.Wini;
public class Config {
/**
+ * Logger for this class
+ */
+ private final static Logger LOGGER = Logger.getLogger(Config.class);
+
+ /**
* The main configuration object is of type Wini
* It contains the content of the config.ini as
* determined in the init() function.
@@ -39,7 +46,7 @@ public class Config {
// Determine OS
String OSName = System.getProperty("os.name").toLowerCase();
- System.out.println("Machine's OS: " + OSName);
+ LOGGER.info("Machine's OS: " + OSName);
if (OSName.contains("windows")) {
// Windows machine. Use the environment variable 'APPDATA' which
// should point to a path similar to:
@@ -49,7 +56,7 @@ public class Config {
configPath = appDataPath + "\\bwSuite\\config.ini";
} else {
// APPDATA was empty, let's build it ourselves...
- System.out.println("APPDATA ist leer.");
+ LOGGER.warn("APPDATA ist leer.");
configPath = System.getProperty("user.home") + "\\AppData\\Roaming\\bwSuite\\config.ini";
}
@@ -69,7 +76,7 @@ public class Config {
// Check if the directory exists.
if (!configFile.getParentFile().exists()) {
- System.out.println("Ordner " + configFile.getParentFile() + " exisitiert nicht - lege ihn jetzt an.");
+ LOGGER.info("Ordner " + configFile.getParentFile() + " exisitiert nicht - lege ihn jetzt an.");
// Does not, create it
if (!configFile.getParentFile().mkdirs()) {
throw new IOException("Konnte '" + configFile.getParentFile() + "' nicht erstellen.");
@@ -84,7 +91,7 @@ public class Config {
// Check if file is writeable
if(configFile.canWrite()) {
ini = new Wini(configFile);
- System.out.println("Erzeuge '" + configFile + "'...");
+ LOGGER.info("Erzeuge '" + configFile + "'...");
// write default configuration options and values
ini.put("main", "BillOfRights", false);
ini.put("main", "vmware", false);
@@ -98,7 +105,7 @@ public class Config {
throw new IOException("Konnte nicht in '" + configFile + "' schreiben. Haben Sie Rechte dazu?");
}
} else {
- System.out.println("'" + configFile + "' existiert bereits - keine weitere Aktion.");
+ LOGGER.info("'" + configFile + "' existiert bereits - keine weitere Aktion.");
ini = new Wini(configFile);
}
} // end constructor.
@@ -147,6 +154,17 @@ public class Config {
}
/**
+ * Query the path of the configuration file
+ * @return path to the configuration file
+ */
+ public static String getPath() {
+ if (ini.getFile().getParentFile().isDirectory())
+ return ini.getFile().getParentFile().toString();
+ else
+ return null;
+ }
+
+ /**
* Sets the value of 'BillOfRights' in the configuration file to 'value'
* @return true if it succeeded, false otherwise
*/
@@ -199,7 +217,6 @@ public class Config {
ini.store();
return true;
} catch (IOException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
return false;
}