src/org/sonews/config/Config.java
author cli
Tue Sep 13 20:14:44 2011 +0200 (2011-09-13)
changeset 57 7c682f4de8ce
parent 45 7e24949b87b0
child 58 b2df305a13ce
permissions -rwxr-xr-x
Move default db to /var/spool/news/sonews/sonewsdb
chris@3
     1
/*
chris@3
     2
 *   SONEWS News Server
chris@3
     3
 *   see AUTHORS for the list of contributors
chris@3
     4
 *
chris@3
     5
 *   This program is free software: you can redistribute it and/or modify
chris@3
     6
 *   it under the terms of the GNU General Public License as published by
chris@3
     7
 *   the Free Software Foundation, either version 3 of the License, or
chris@3
     8
 *   (at your option) any later version.
chris@3
     9
 *
chris@3
    10
 *   This program is distributed in the hope that it will be useful,
chris@3
    11
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
chris@3
    12
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
chris@3
    13
 *   GNU General Public License for more details.
chris@3
    14
 *
chris@3
    15
 *   You should have received a copy of the GNU General Public License
chris@3
    16
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
chris@3
    17
 */
chris@3
    18
package org.sonews.config;
chris@3
    19
chris@3
    20
/**
chris@3
    21
 * Configuration facade class.
chris@3
    22
 * @author Christian Lins
chris@3
    23
 * @since sonews/1.0
chris@3
    24
 */
cli@49
    25
public class Config extends AbstractConfig {
chris@3
    26
cli@37
    27
	public static final int LEVEL_CLI = 1;
cli@37
    28
	public static final int LEVEL_FILE = 2;
cli@37
    29
	public static final int LEVEL_BACKEND = 3;
cli@37
    30
	public static final String CONFIGFILE = "sonews.configfile";
cli@37
    31
	/** BackendConfig key constant. Value is the maximum article size in kilobytes. */
cli@37
    32
	public static final String ARTICLE_MAXSIZE = "sonews.article.maxsize";
cli@37
    33
	/** BackendConfig key constant. Value: Amount of news that are feeded per run. */
cli@37
    34
	public static final String EVENTLOG = "sonews.eventlog";
cli@37
    35
	public static final String FEED_NEWSPERRUN = "sonews.feed.newsperrun";
cli@37
    36
	public static final String FEED_PULLINTERVAL = "sonews.feed.pullinterval";
cli@37
    37
	public static final String HOSTNAME = "sonews.hostname";
cli@37
    38
	public static final String PORT = "sonews.port";
cli@37
    39
	public static final String TIMEOUT = "sonews.timeout";
cli@37
    40
	public static final String LOGLEVEL = "sonews.loglevel";
cli@37
    41
	public static final String MLPOLL_DELETEUNKNOWN = "sonews.mlpoll.deleteunknown";
cli@37
    42
	public static final String MLPOLL_HOST = "sonews.mlpoll.host";
cli@37
    43
	public static final String MLPOLL_PASSWORD = "sonews.mlpoll.password";
cli@37
    44
	public static final String MLPOLL_USER = "sonews.mlpoll.user";
cli@37
    45
	public static final String MLSEND_ADDRESS = "sonews.mlsend.address";
cli@37
    46
	public static final String MLSEND_RW_FROM = "sonews.mlsend.rewrite.from";
cli@37
    47
	public static final String MLSEND_RW_SENDER = "sonews.mlsend.rewrite.sender";
cli@37
    48
	public static final String MLSEND_HOST = "sonews.mlsend.host";
cli@37
    49
	public static final String MLSEND_PASSWORD = "sonews.mlsend.password";
cli@37
    50
	public static final String MLSEND_PORT = "sonews.mlsend.port";
cli@37
    51
	public static final String MLSEND_USER = "sonews.mlsend.user";
cli@37
    52
	/** Key constant. If value is "true" every I/O is written to logfile
cli@45
    53
	 * (which is a lot!) */
cli@37
    54
	public static final String DEBUG = "sonews.debug";
cli@37
    55
	/** Key constant. Value is classname of the JDBC driver */
cli@37
    56
	public static final String STORAGE_DBMSDRIVER = "sonews.storage.dbmsdriver";
cli@37
    57
	/** Key constant. Value is JDBC connect String to the database. */
cli@37
    58
	public static final String STORAGE_DATABASE = "sonews.storage.database";
cli@37
    59
	/** Key constant. Value is the username for the DBMS. */
cli@37
    60
	public static final String STORAGE_USER = "sonews.storage.user";
cli@37
    61
	/** Key constant. Value is the password for the DBMS. */
cli@37
    62
	public static final String STORAGE_PASSWORD = "sonews.storage.password";
cli@45
    63
	public static final String STORAGE_PROVIDER = "sonews.storage.provider";
cli@37
    64
	/** Key constant. Value is the name of the host which is allowed to use the
cli@37
    65
	 *  XDAEMON command; default: "localhost" */
cli@37
    66
	public static final String XDAEMON_HOST = "sonews.xdaemon.host";
cli@37
    67
	/** The config key for the filename of the logfile */
cli@37
    68
	public static final String LOGFILE = "sonews.log";
cli@37
    69
	public static final String[] AVAILABLE_KEYS = {
cli@37
    70
		ARTICLE_MAXSIZE,
cli@37
    71
		EVENTLOG,
cli@37
    72
		FEED_NEWSPERRUN,
cli@37
    73
		FEED_PULLINTERVAL,
cli@37
    74
		HOSTNAME,
cli@37
    75
		MLPOLL_DELETEUNKNOWN,
cli@37
    76
		MLPOLL_HOST,
cli@37
    77
		MLPOLL_PASSWORD,
cli@37
    78
		MLPOLL_USER,
cli@37
    79
		MLSEND_ADDRESS,
cli@37
    80
		MLSEND_HOST,
cli@37
    81
		MLSEND_PASSWORD,
cli@37
    82
		MLSEND_PORT,
cli@37
    83
		MLSEND_RW_FROM,
cli@37
    84
		MLSEND_RW_SENDER,
cli@37
    85
		MLSEND_USER,
cli@37
    86
		PORT,
cli@37
    87
		TIMEOUT,
cli@37
    88
		XDAEMON_HOST
cli@37
    89
	};
cli@37
    90
	private static Config instance = new Config();
chris@3
    91
cli@49
    92
	public static Config inst() {
cli@37
    93
		return instance;
cli@37
    94
	}
chris@3
    95
cli@49
    96
	private Config() {
cli@37
    97
	}
chris@3
    98
cli@37
    99
	@Override
cli@49
   100
	public String get(String key, String def) {
cli@37
   101
		String val = CommandLineConfig.getInstance().get(key, null);
chris@3
   102
cli@37
   103
		if (val == null) {
cli@37
   104
			val = FileConfig.getInstance().get(key, null);
cli@37
   105
		}
chris@3
   106
cli@37
   107
		if (val == null) {
cli@37
   108
			val = BackendConfig.getInstance().get(key, def);
cli@37
   109
		}
chris@3
   110
cli@37
   111
		return val;
cli@37
   112
	}
chris@3
   113
cli@49
   114
	public String get(int maxLevel, String key, String def) {
cli@37
   115
		String val = CommandLineConfig.getInstance().get(key, null);
chris@3
   116
cli@37
   117
		if (val == null && maxLevel >= LEVEL_FILE) {
cli@37
   118
			val = FileConfig.getInstance().get(key, null);
cli@37
   119
			if (val == null && maxLevel >= LEVEL_BACKEND) {
cli@37
   120
				val = BackendConfig.getInstance().get(key, def);
cli@37
   121
			}
cli@37
   122
		}
chris@3
   123
cli@37
   124
		return val != null ? val : def;
cli@37
   125
	}
chris@3
   126
cli@37
   127
	@Override
cli@49
   128
	public void set(String key, String val) {
cli@37
   129
		set(LEVEL_BACKEND, key, val);
cli@37
   130
	}
chris@3
   131
cli@49
   132
	public void set(int level, String key, String val) {
cli@37
   133
		switch (level) {
cli@37
   134
			case LEVEL_CLI: {
cli@37
   135
				CommandLineConfig.getInstance().set(key, val);
cli@37
   136
				break;
cli@37
   137
			}
cli@37
   138
			case LEVEL_FILE: {
cli@37
   139
				FileConfig.getInstance().set(key, val);
cli@37
   140
				break;
cli@37
   141
			}
cli@37
   142
			case LEVEL_BACKEND: {
cli@37
   143
				BackendConfig.getInstance().set(key, val);
cli@37
   144
				break;
cli@37
   145
			}
cli@37
   146
		}
cli@37
   147
	}
chris@3
   148
}