1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
/*
* Created on August 14 2003
*/
package org.workingfrog.i18n.util;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
/**
* @author Jean-Hugues de Raigniac
*/
public class PropertiesLoader {
private static Properties properties = new Properties();
private static String logLevelKey = "i18n.log.level";
private static String bundlesPathKey = "i18n.bundles.path";
public static void init () {
Properties defaults = new Properties();
FileInputStream in;
try {
in = new FileInputStream("default.properties");
defaults.load(in);
in.close();
} catch (FileNotFoundException e) {
Translator.log(LogLevel.I18N, "default property file not found.");
} catch (IOException e) {
// there may not be a default.properties file
}
properties = new Properties(defaults);
try {
in = new FileInputStream("user.properties");
properties.load(in);
in.close();
} catch (FileNotFoundException e) {
Translator.log(LogLevel.I18N, "user property file not found.");
} catch (IOException e) {
// there may not be a default.properties file
}
if (properties.size() <= 0) {
properties.setProperty(logLevelKey, "ALL");
}
}
public static String getLogLevel () {
String result = properties.getProperty(logLevelKey);
return (result != null) ? result : "NONE";
}
public static void setLogLevel (LogLevel level) {
properties.setProperty(logLevelKey, level.toString());
}
public static void setLogLevel (String level) {
properties.setProperty(logLevelKey, level);
}
public static String getBundlesPath () {
String result = properties.getProperty(bundlesPathKey);
return (result != null) ? result : "";
}
public static void setBundlesPath (String path) {
properties.setProperty(bundlesPathKey, path);
}
}
|