chris@3: /* chris@3: * SONEWS News Server chris@3: * see AUTHORS for the list of contributors chris@3: * chris@3: * This program is free software: you can redistribute it and/or modify chris@3: * it under the terms of the GNU General Public License as published by chris@3: * the Free Software Foundation, either version 3 of the License, or chris@3: * (at your option) any later version. chris@3: * chris@3: * This program is distributed in the hope that it will be useful, chris@3: * but WITHOUT ANY WARRANTY; without even the implied warranty of chris@3: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the chris@3: * GNU General Public License for more details. chris@3: * chris@3: * You should have received a copy of the GNU General Public License chris@3: * along with this program. If not, see . chris@3: */ chris@3: package org.sonews.config; chris@3: chris@3: /** chris@3: * Configuration facade class. chris@3: * @author Christian Lins chris@3: * @since sonews/1.0 chris@3: */ cli@49: public class Config extends AbstractConfig { chris@3: cli@37: public static final int LEVEL_CLI = 1; cli@37: public static final int LEVEL_FILE = 2; cli@37: public static final int LEVEL_BACKEND = 3; cli@37: public static final String CONFIGFILE = "sonews.configfile"; cli@37: /** BackendConfig key constant. Value is the maximum article size in kilobytes. */ cli@37: public static final String ARTICLE_MAXSIZE = "sonews.article.maxsize"; cli@37: /** BackendConfig key constant. Value: Amount of news that are feeded per run. */ cli@37: public static final String EVENTLOG = "sonews.eventlog"; cli@58: cli@37: public static final String FEED_NEWSPERRUN = "sonews.feed.newsperrun"; cli@37: public static final String FEED_PULLINTERVAL = "sonews.feed.pullinterval"; cli@58: cli@37: public static final String HOSTNAME = "sonews.hostname"; cli@37: public static final String PORT = "sonews.port"; cli@37: public static final String TIMEOUT = "sonews.timeout"; cli@37: public static final String LOGLEVEL = "sonews.loglevel"; cli@58: cli@37: public static final String MLPOLL_DELETEUNKNOWN = "sonews.mlpoll.deleteunknown"; cli@37: public static final String MLPOLL_HOST = "sonews.mlpoll.host"; cli@37: public static final String MLPOLL_PASSWORD = "sonews.mlpoll.password"; cli@37: public static final String MLPOLL_USER = "sonews.mlpoll.user"; cli@58: cli@37: public static final String MLSEND_ADDRESS = "sonews.mlsend.address"; cli@37: public static final String MLSEND_RW_FROM = "sonews.mlsend.rewrite.from"; cli@37: public static final String MLSEND_RW_SENDER = "sonews.mlsend.rewrite.sender"; cli@37: public static final String MLSEND_HOST = "sonews.mlsend.host"; cli@37: public static final String MLSEND_PASSWORD = "sonews.mlsend.password"; cli@37: public static final String MLSEND_PORT = "sonews.mlsend.port"; cli@37: public static final String MLSEND_USER = "sonews.mlsend.user"; cli@58: public static final String MLSEND_AUTH = "sonews.mlsend.auth"; cli@58: cli@37: /** Key constant. If value is "true" every I/O is written to logfile cli@45: * (which is a lot!) */ cli@37: public static final String DEBUG = "sonews.debug"; cli@58: cli@37: /** Key constant. Value is classname of the JDBC driver */ cli@37: public static final String STORAGE_DBMSDRIVER = "sonews.storage.dbmsdriver"; cli@37: /** Key constant. Value is JDBC connect String to the database. */ cli@37: public static final String STORAGE_DATABASE = "sonews.storage.database"; cli@37: /** Key constant. Value is the username for the DBMS. */ cli@37: public static final String STORAGE_USER = "sonews.storage.user"; cli@37: /** Key constant. Value is the password for the DBMS. */ cli@37: public static final String STORAGE_PASSWORD = "sonews.storage.password"; cli@45: public static final String STORAGE_PROVIDER = "sonews.storage.provider"; cli@58: cli@37: /** Key constant. Value is the name of the host which is allowed to use the cli@37: * XDAEMON command; default: "localhost" */ cli@37: public static final String XDAEMON_HOST = "sonews.xdaemon.host"; cli@58: cli@37: /** The config key for the filename of the logfile */ cli@37: public static final String LOGFILE = "sonews.log"; cli@37: public static final String[] AVAILABLE_KEYS = { cli@37: ARTICLE_MAXSIZE, cli@37: EVENTLOG, cli@37: FEED_NEWSPERRUN, cli@37: FEED_PULLINTERVAL, cli@37: HOSTNAME, cli@37: MLPOLL_DELETEUNKNOWN, cli@37: MLPOLL_HOST, cli@37: MLPOLL_PASSWORD, cli@37: MLPOLL_USER, cli@37: MLSEND_ADDRESS, cli@37: MLSEND_HOST, cli@37: MLSEND_PASSWORD, cli@37: MLSEND_PORT, cli@37: MLSEND_RW_FROM, cli@37: MLSEND_RW_SENDER, cli@37: MLSEND_USER, cli@37: PORT, cli@37: TIMEOUT, cli@37: XDAEMON_HOST cli@37: }; cli@37: private static Config instance = new Config(); chris@3: cli@49: public static Config inst() { cli@37: return instance; cli@37: } chris@3: cli@49: private Config() { cli@37: } chris@3: cli@37: @Override cli@49: public String get(String key, String def) { cli@37: String val = CommandLineConfig.getInstance().get(key, null); chris@3: cli@37: if (val == null) { cli@37: val = FileConfig.getInstance().get(key, null); cli@37: } chris@3: cli@37: if (val == null) { cli@37: val = BackendConfig.getInstance().get(key, def); cli@37: } chris@3: cli@37: return val; cli@37: } chris@3: cli@49: public String get(int maxLevel, String key, String def) { cli@37: String val = CommandLineConfig.getInstance().get(key, null); chris@3: cli@37: if (val == null && maxLevel >= LEVEL_FILE) { cli@37: val = FileConfig.getInstance().get(key, null); cli@37: if (val == null && maxLevel >= LEVEL_BACKEND) { cli@37: val = BackendConfig.getInstance().get(key, def); cli@37: } cli@37: } chris@3: cli@37: return val != null ? val : def; cli@37: } chris@3: cli@37: @Override cli@49: public void set(String key, String val) { cli@37: set(LEVEL_BACKEND, key, val); cli@37: } chris@3: cli@49: public void set(int level, String key, String val) { cli@37: switch (level) { cli@37: case LEVEL_CLI: { cli@37: CommandLineConfig.getInstance().set(key, val); cli@37: break; cli@37: } cli@37: case LEVEL_FILE: { cli@37: FileConfig.getInstance().set(key, val); cli@37: break; cli@37: } cli@37: case LEVEL_BACKEND: { cli@37: BackendConfig.getInstance().set(key, val); cli@37: break; cli@37: } cli@37: } cli@37: } chris@3: }