serverSwitch get(App/Data)Path() use common helper method

Signed-off-by: Marek Otahal <markotahal@gmail.com>
pull/1/head
Marek Otahal 13 years ago committed by Michael Peter Christen
parent 371fbb4deb
commit 64e4bcee82

@ -311,19 +311,23 @@ public class serverSwitch
* the relative path setting. * the relative path setting.
*/ */
public File getDataPath(final String key, final String dflt) { public File getDataPath(final String key, final String dflt) {
File ret; return getFileByPath(key, dflt, dataPath);
final String path = getConfig(key, dflt).replace('\\', '/');
final File f = new File(path);
ret = (f.isAbsolute() ? new File(f.getAbsolutePath()) : new File(this.dataPath, path));
return ret;
} }
/**
* return file at path from config entry "key", or fallback to default dflt
* @param key
* @param dflt
* @return
*/
public File getAppPath(final String key, final String dflt) { public File getAppPath(final String key, final String dflt) {
File ret; return getFileByPath(key, dflt, appPath);
}
private File getFileByPath(String key, String dflt, File prefix) {
final String path = getConfig(key, dflt).replace('\\', '/'); final String path = getConfig(key, dflt).replace('\\', '/');
final File f = new File(path); final File f = new File(path);
ret = (f.isAbsolute() ? new File(f.getAbsolutePath()) : new File(this.appPath, path)); return (f.isAbsolute() ? new File(f.getAbsolutePath()) : new File(prefix, path));
return ret;
} }
public Iterator<String> configKeys() { public Iterator<String> configKeys() {

Loading…
Cancel
Save