diff -r ed84c8bdd87b -r 73b21e9f3958 src/org/sonews/config/Config.java --- a/src/org/sonews/config/Config.java Sun Aug 29 17:28:58 2010 +0200 +++ b/src/org/sonews/config/Config.java Mon Aug 30 00:20:06 2010 +0200 @@ -25,151 +25,132 @@ */ public class Config extends AbstractConfig { - - public static final int LEVEL_CLI = 1; - public static final int LEVEL_FILE = 2; - public static final int LEVEL_BACKEND = 3; - public static final String CONFIGFILE = "sonews.configfile"; - - /** BackendConfig key constant. Value is the maximum article size in kilobytes. */ - public static final String ARTICLE_MAXSIZE = "sonews.article.maxsize"; + public static final int LEVEL_CLI = 1; + public static final int LEVEL_FILE = 2; + public static final int LEVEL_BACKEND = 3; + public static final String CONFIGFILE = "sonews.configfile"; + /** BackendConfig key constant. Value is the maximum article size in kilobytes. */ + public static final String ARTICLE_MAXSIZE = "sonews.article.maxsize"; + /** BackendConfig key constant. Value: Amount of news that are feeded per run. */ + public static final String EVENTLOG = "sonews.eventlog"; + public static final String FEED_NEWSPERRUN = "sonews.feed.newsperrun"; + public static final String FEED_PULLINTERVAL = "sonews.feed.pullinterval"; + public static final String HOSTNAME = "sonews.hostname"; + public static final String PORT = "sonews.port"; + public static final String TIMEOUT = "sonews.timeout"; + public static final String LOGLEVEL = "sonews.loglevel"; + public static final String MLPOLL_DELETEUNKNOWN = "sonews.mlpoll.deleteunknown"; + public static final String MLPOLL_HOST = "sonews.mlpoll.host"; + public static final String MLPOLL_PASSWORD = "sonews.mlpoll.password"; + public static final String MLPOLL_USER = "sonews.mlpoll.user"; + public static final String MLSEND_ADDRESS = "sonews.mlsend.address"; + public static final String MLSEND_RW_FROM = "sonews.mlsend.rewrite.from"; + public static final String MLSEND_RW_SENDER = "sonews.mlsend.rewrite.sender"; + public static final String MLSEND_HOST = "sonews.mlsend.host"; + public static final String MLSEND_PASSWORD = "sonews.mlsend.password"; + public static final String MLSEND_PORT = "sonews.mlsend.port"; + public static final String MLSEND_USER = "sonews.mlsend.user"; + /** Key constant. If value is "true" every I/O is written to logfile + * (which is a lot!) + */ + public static final String DEBUG = "sonews.debug"; + /** Key constant. Value is classname of the JDBC driver */ + public static final String STORAGE_DBMSDRIVER = "sonews.storage.dbmsdriver"; + /** Key constant. Value is JDBC connect String to the database. */ + public static final String STORAGE_DATABASE = "sonews.storage.database"; + /** Key constant. Value is the username for the DBMS. */ + public static final String STORAGE_USER = "sonews.storage.user"; + /** Key constant. Value is the password for the DBMS. */ + public static final String STORAGE_PASSWORD = "sonews.storage.password"; + /** Key constant. Value is the name of the host which is allowed to use the + * XDAEMON command; default: "localhost" */ + public static final String XDAEMON_HOST = "sonews.xdaemon.host"; + /** The config key for the filename of the logfile */ + public static final String LOGFILE = "sonews.log"; + public static final String[] AVAILABLE_KEYS = { + ARTICLE_MAXSIZE, + EVENTLOG, + FEED_NEWSPERRUN, + FEED_PULLINTERVAL, + HOSTNAME, + MLPOLL_DELETEUNKNOWN, + MLPOLL_HOST, + MLPOLL_PASSWORD, + MLPOLL_USER, + MLSEND_ADDRESS, + MLSEND_HOST, + MLSEND_PASSWORD, + MLSEND_PORT, + MLSEND_RW_FROM, + MLSEND_RW_SENDER, + MLSEND_USER, + PORT, + TIMEOUT, + XDAEMON_HOST + }; + private static Config instance = new Config(); - /** BackendConfig key constant. Value: Amount of news that are feeded per run. */ - public static final String EVENTLOG = "sonews.eventlog"; - public static final String FEED_NEWSPERRUN = "sonews.feed.newsperrun"; - public static final String FEED_PULLINTERVAL = "sonews.feed.pullinterval"; - public static final String HOSTNAME = "sonews.hostname"; - public static final String PORT = "sonews.port"; - public static final String TIMEOUT = "sonews.timeout"; - public static final String LOGLEVEL = "sonews.loglevel"; - public static final String MLPOLL_DELETEUNKNOWN = "sonews.mlpoll.deleteunknown"; - public static final String MLPOLL_HOST = "sonews.mlpoll.host"; - public static final String MLPOLL_PASSWORD = "sonews.mlpoll.password"; - public static final String MLPOLL_USER = "sonews.mlpoll.user"; - public static final String MLSEND_ADDRESS = "sonews.mlsend.address"; - public static final String MLSEND_RW_FROM = "sonews.mlsend.rewrite.from"; - public static final String MLSEND_RW_SENDER = "sonews.mlsend.rewrite.sender"; - public static final String MLSEND_HOST = "sonews.mlsend.host"; - public static final String MLSEND_PASSWORD = "sonews.mlsend.password"; - public static final String MLSEND_PORT = "sonews.mlsend.port"; - public static final String MLSEND_USER = "sonews.mlsend.user"; - - /** Key constant. If value is "true" every I/O is written to logfile - * (which is a lot!) - */ - public static final String DEBUG = "sonews.debug"; + public static Config inst() + { + return instance; + } - /** Key constant. Value is classname of the JDBC driver */ - public static final String STORAGE_DBMSDRIVER = "sonews.storage.dbmsdriver"; + private Config() + { + } - /** Key constant. Value is JDBC connect String to the database. */ - public static final String STORAGE_DATABASE = "sonews.storage.database"; + @Override + public String get(String key, String def) + { + String val = CommandLineConfig.getInstance().get(key, null); - /** Key constant. Value is the username for the DBMS. */ - public static final String STORAGE_USER = "sonews.storage.user"; + if (val == null) { + val = FileConfig.getInstance().get(key, null); + } - /** Key constant. Value is the password for the DBMS. */ - public static final String STORAGE_PASSWORD = "sonews.storage.password"; + if (val == null) { + val = BackendConfig.getInstance().get(key, def); + } - /** Key constant. Value is the name of the host which is allowed to use the - * XDAEMON command; default: "localhost" */ - public static final String XDAEMON_HOST = "sonews.xdaemon.host"; + return val; + } - /** The config key for the filename of the logfile */ - public static final String LOGFILE = "sonews.log"; + public String get(int maxLevel, String key, String def) + { + String val = CommandLineConfig.getInstance().get(key, null); - public static final String[] AVAILABLE_KEYS = { - ARTICLE_MAXSIZE, - EVENTLOG, - FEED_NEWSPERRUN, - FEED_PULLINTERVAL, - HOSTNAME, - MLPOLL_DELETEUNKNOWN, - MLPOLL_HOST, - MLPOLL_PASSWORD, - MLPOLL_USER, - MLSEND_ADDRESS, - MLSEND_HOST, - MLSEND_PASSWORD, - MLSEND_PORT, - MLSEND_RW_FROM, - MLSEND_RW_SENDER, - MLSEND_USER, - PORT, - TIMEOUT, - XDAEMON_HOST - }; + if (val == null && maxLevel >= LEVEL_FILE) { + val = FileConfig.getInstance().get(key, null); + if (val == null && maxLevel >= LEVEL_BACKEND) { + val = BackendConfig.getInstance().get(key, def); + } + } - private static Config instance = new Config(); - - public static Config inst() - { - return instance; - } - - private Config(){} + return val != null ? val : def; + } - @Override - public String get(String key, String def) - { - String val = CommandLineConfig.getInstance().get(key, null); - - if(val == null) - { - val = FileConfig.getInstance().get(key, null); - } + @Override + public void set(String key, String val) + { + set(LEVEL_BACKEND, key, val); + } - if(val == null) - { - val = BackendConfig.getInstance().get(key, def); - } - - return val; - } - - public String get(int maxLevel, String key, String def) - { - String val = CommandLineConfig.getInstance().get(key, null); - - if(val == null && maxLevel >= LEVEL_FILE) - { - val = FileConfig.getInstance().get(key, null); - if(val == null && maxLevel >= LEVEL_BACKEND) - { - val = BackendConfig.getInstance().get(key, def); - } - } - - return val != null ? val : def; - } - - @Override - public void set(String key, String val) - { - set(LEVEL_BACKEND, key, val); - } - - public void set(int level, String key, String val) - { - switch(level) - { - case LEVEL_CLI: - { - CommandLineConfig.getInstance().set(key, val); - break; - } - case LEVEL_FILE: - { - FileConfig.getInstance().set(key, val); - break; - } - case LEVEL_BACKEND: - { - BackendConfig.getInstance().set(key, val); - break; - } - } - } - + public void set(int level, String key, String val) + { + switch (level) { + case LEVEL_CLI: { + CommandLineConfig.getInstance().set(key, val); + break; + } + case LEVEL_FILE: { + FileConfig.getInstance().set(key, val); + break; + } + case LEVEL_BACKEND: { + BackendConfig.getInstance().set(key, val); + break; + } + } + } }