1.1 --- a/src/org/sonews/config/Config.java Sun Aug 29 17:28:58 2010 +0200
1.2 +++ b/src/org/sonews/config/Config.java Mon Aug 30 00:20:06 2010 +0200
1.3 @@ -25,151 +25,132 @@
1.4 */
1.5 public class Config extends AbstractConfig
1.6 {
1.7 -
1.8 - public static final int LEVEL_CLI = 1;
1.9 - public static final int LEVEL_FILE = 2;
1.10 - public static final int LEVEL_BACKEND = 3;
1.11
1.12 - public static final String CONFIGFILE = "sonews.configfile";
1.13 -
1.14 - /** BackendConfig key constant. Value is the maximum article size in kilobytes. */
1.15 - public static final String ARTICLE_MAXSIZE = "sonews.article.maxsize";
1.16 + public static final int LEVEL_CLI = 1;
1.17 + public static final int LEVEL_FILE = 2;
1.18 + public static final int LEVEL_BACKEND = 3;
1.19 + public static final String CONFIGFILE = "sonews.configfile";
1.20 + /** BackendConfig key constant. Value is the maximum article size in kilobytes. */
1.21 + public static final String ARTICLE_MAXSIZE = "sonews.article.maxsize";
1.22 + /** BackendConfig key constant. Value: Amount of news that are feeded per run. */
1.23 + public static final String EVENTLOG = "sonews.eventlog";
1.24 + public static final String FEED_NEWSPERRUN = "sonews.feed.newsperrun";
1.25 + public static final String FEED_PULLINTERVAL = "sonews.feed.pullinterval";
1.26 + public static final String HOSTNAME = "sonews.hostname";
1.27 + public static final String PORT = "sonews.port";
1.28 + public static final String TIMEOUT = "sonews.timeout";
1.29 + public static final String LOGLEVEL = "sonews.loglevel";
1.30 + public static final String MLPOLL_DELETEUNKNOWN = "sonews.mlpoll.deleteunknown";
1.31 + public static final String MLPOLL_HOST = "sonews.mlpoll.host";
1.32 + public static final String MLPOLL_PASSWORD = "sonews.mlpoll.password";
1.33 + public static final String MLPOLL_USER = "sonews.mlpoll.user";
1.34 + public static final String MLSEND_ADDRESS = "sonews.mlsend.address";
1.35 + public static final String MLSEND_RW_FROM = "sonews.mlsend.rewrite.from";
1.36 + public static final String MLSEND_RW_SENDER = "sonews.mlsend.rewrite.sender";
1.37 + public static final String MLSEND_HOST = "sonews.mlsend.host";
1.38 + public static final String MLSEND_PASSWORD = "sonews.mlsend.password";
1.39 + public static final String MLSEND_PORT = "sonews.mlsend.port";
1.40 + public static final String MLSEND_USER = "sonews.mlsend.user";
1.41 + /** Key constant. If value is "true" every I/O is written to logfile
1.42 + * (which is a lot!)
1.43 + */
1.44 + public static final String DEBUG = "sonews.debug";
1.45 + /** Key constant. Value is classname of the JDBC driver */
1.46 + public static final String STORAGE_DBMSDRIVER = "sonews.storage.dbmsdriver";
1.47 + /** Key constant. Value is JDBC connect String to the database. */
1.48 + public static final String STORAGE_DATABASE = "sonews.storage.database";
1.49 + /** Key constant. Value is the username for the DBMS. */
1.50 + public static final String STORAGE_USER = "sonews.storage.user";
1.51 + /** Key constant. Value is the password for the DBMS. */
1.52 + public static final String STORAGE_PASSWORD = "sonews.storage.password";
1.53 + /** Key constant. Value is the name of the host which is allowed to use the
1.54 + * XDAEMON command; default: "localhost" */
1.55 + public static final String XDAEMON_HOST = "sonews.xdaemon.host";
1.56 + /** The config key for the filename of the logfile */
1.57 + public static final String LOGFILE = "sonews.log";
1.58 + public static final String[] AVAILABLE_KEYS = {
1.59 + ARTICLE_MAXSIZE,
1.60 + EVENTLOG,
1.61 + FEED_NEWSPERRUN,
1.62 + FEED_PULLINTERVAL,
1.63 + HOSTNAME,
1.64 + MLPOLL_DELETEUNKNOWN,
1.65 + MLPOLL_HOST,
1.66 + MLPOLL_PASSWORD,
1.67 + MLPOLL_USER,
1.68 + MLSEND_ADDRESS,
1.69 + MLSEND_HOST,
1.70 + MLSEND_PASSWORD,
1.71 + MLSEND_PORT,
1.72 + MLSEND_RW_FROM,
1.73 + MLSEND_RW_SENDER,
1.74 + MLSEND_USER,
1.75 + PORT,
1.76 + TIMEOUT,
1.77 + XDAEMON_HOST
1.78 + };
1.79 + private static Config instance = new Config();
1.80
1.81 - /** BackendConfig key constant. Value: Amount of news that are feeded per run. */
1.82 - public static final String EVENTLOG = "sonews.eventlog";
1.83 - public static final String FEED_NEWSPERRUN = "sonews.feed.newsperrun";
1.84 - public static final String FEED_PULLINTERVAL = "sonews.feed.pullinterval";
1.85 - public static final String HOSTNAME = "sonews.hostname";
1.86 - public static final String PORT = "sonews.port";
1.87 - public static final String TIMEOUT = "sonews.timeout";
1.88 - public static final String LOGLEVEL = "sonews.loglevel";
1.89 - public static final String MLPOLL_DELETEUNKNOWN = "sonews.mlpoll.deleteunknown";
1.90 - public static final String MLPOLL_HOST = "sonews.mlpoll.host";
1.91 - public static final String MLPOLL_PASSWORD = "sonews.mlpoll.password";
1.92 - public static final String MLPOLL_USER = "sonews.mlpoll.user";
1.93 - public static final String MLSEND_ADDRESS = "sonews.mlsend.address";
1.94 - public static final String MLSEND_RW_FROM = "sonews.mlsend.rewrite.from";
1.95 - public static final String MLSEND_RW_SENDER = "sonews.mlsend.rewrite.sender";
1.96 - public static final String MLSEND_HOST = "sonews.mlsend.host";
1.97 - public static final String MLSEND_PASSWORD = "sonews.mlsend.password";
1.98 - public static final String MLSEND_PORT = "sonews.mlsend.port";
1.99 - public static final String MLSEND_USER = "sonews.mlsend.user";
1.100 -
1.101 - /** Key constant. If value is "true" every I/O is written to logfile
1.102 - * (which is a lot!)
1.103 - */
1.104 - public static final String DEBUG = "sonews.debug";
1.105 + public static Config inst()
1.106 + {
1.107 + return instance;
1.108 + }
1.109
1.110 - /** Key constant. Value is classname of the JDBC driver */
1.111 - public static final String STORAGE_DBMSDRIVER = "sonews.storage.dbmsdriver";
1.112 + private Config()
1.113 + {
1.114 + }
1.115
1.116 - /** Key constant. Value is JDBC connect String to the database. */
1.117 - public static final String STORAGE_DATABASE = "sonews.storage.database";
1.118 + @Override
1.119 + public String get(String key, String def)
1.120 + {
1.121 + String val = CommandLineConfig.getInstance().get(key, null);
1.122
1.123 - /** Key constant. Value is the username for the DBMS. */
1.124 - public static final String STORAGE_USER = "sonews.storage.user";
1.125 + if (val == null) {
1.126 + val = FileConfig.getInstance().get(key, null);
1.127 + }
1.128
1.129 - /** Key constant. Value is the password for the DBMS. */
1.130 - public static final String STORAGE_PASSWORD = "sonews.storage.password";
1.131 + if (val == null) {
1.132 + val = BackendConfig.getInstance().get(key, def);
1.133 + }
1.134
1.135 - /** Key constant. Value is the name of the host which is allowed to use the
1.136 - * XDAEMON command; default: "localhost" */
1.137 - public static final String XDAEMON_HOST = "sonews.xdaemon.host";
1.138 + return val;
1.139 + }
1.140
1.141 - /** The config key for the filename of the logfile */
1.142 - public static final String LOGFILE = "sonews.log";
1.143 + public String get(int maxLevel, String key, String def)
1.144 + {
1.145 + String val = CommandLineConfig.getInstance().get(key, null);
1.146
1.147 - public static final String[] AVAILABLE_KEYS = {
1.148 - ARTICLE_MAXSIZE,
1.149 - EVENTLOG,
1.150 - FEED_NEWSPERRUN,
1.151 - FEED_PULLINTERVAL,
1.152 - HOSTNAME,
1.153 - MLPOLL_DELETEUNKNOWN,
1.154 - MLPOLL_HOST,
1.155 - MLPOLL_PASSWORD,
1.156 - MLPOLL_USER,
1.157 - MLSEND_ADDRESS,
1.158 - MLSEND_HOST,
1.159 - MLSEND_PASSWORD,
1.160 - MLSEND_PORT,
1.161 - MLSEND_RW_FROM,
1.162 - MLSEND_RW_SENDER,
1.163 - MLSEND_USER,
1.164 - PORT,
1.165 - TIMEOUT,
1.166 - XDAEMON_HOST
1.167 - };
1.168 + if (val == null && maxLevel >= LEVEL_FILE) {
1.169 + val = FileConfig.getInstance().get(key, null);
1.170 + if (val == null && maxLevel >= LEVEL_BACKEND) {
1.171 + val = BackendConfig.getInstance().get(key, def);
1.172 + }
1.173 + }
1.174
1.175 - private static Config instance = new Config();
1.176 -
1.177 - public static Config inst()
1.178 - {
1.179 - return instance;
1.180 - }
1.181 -
1.182 - private Config(){}
1.183 + return val != null ? val : def;
1.184 + }
1.185
1.186 - @Override
1.187 - public String get(String key, String def)
1.188 - {
1.189 - String val = CommandLineConfig.getInstance().get(key, null);
1.190 -
1.191 - if(val == null)
1.192 - {
1.193 - val = FileConfig.getInstance().get(key, null);
1.194 - }
1.195 + @Override
1.196 + public void set(String key, String val)
1.197 + {
1.198 + set(LEVEL_BACKEND, key, val);
1.199 + }
1.200
1.201 - if(val == null)
1.202 - {
1.203 - val = BackendConfig.getInstance().get(key, def);
1.204 - }
1.205 -
1.206 - return val;
1.207 - }
1.208 -
1.209 - public String get(int maxLevel, String key, String def)
1.210 - {
1.211 - String val = CommandLineConfig.getInstance().get(key, null);
1.212 -
1.213 - if(val == null && maxLevel >= LEVEL_FILE)
1.214 - {
1.215 - val = FileConfig.getInstance().get(key, null);
1.216 - if(val == null && maxLevel >= LEVEL_BACKEND)
1.217 - {
1.218 - val = BackendConfig.getInstance().get(key, def);
1.219 - }
1.220 - }
1.221 -
1.222 - return val != null ? val : def;
1.223 - }
1.224 -
1.225 - @Override
1.226 - public void set(String key, String val)
1.227 - {
1.228 - set(LEVEL_BACKEND, key, val);
1.229 - }
1.230 -
1.231 - public void set(int level, String key, String val)
1.232 - {
1.233 - switch(level)
1.234 - {
1.235 - case LEVEL_CLI:
1.236 - {
1.237 - CommandLineConfig.getInstance().set(key, val);
1.238 - break;
1.239 - }
1.240 - case LEVEL_FILE:
1.241 - {
1.242 - FileConfig.getInstance().set(key, val);
1.243 - break;
1.244 - }
1.245 - case LEVEL_BACKEND:
1.246 - {
1.247 - BackendConfig.getInstance().set(key, val);
1.248 - break;
1.249 - }
1.250 - }
1.251 - }
1.252 -
1.253 + public void set(int level, String key, String val)
1.254 + {
1.255 + switch (level) {
1.256 + case LEVEL_CLI: {
1.257 + CommandLineConfig.getInstance().set(key, val);
1.258 + break;
1.259 + }
1.260 + case LEVEL_FILE: {
1.261 + FileConfig.getInstance().set(key, val);
1.262 + break;
1.263 + }
1.264 + case LEVEL_BACKEND: {
1.265 + BackendConfig.getInstance().set(key, val);
1.266 + break;
1.267 + }
1.268 + }
1.269 + }
1.270 }