src/org/sonews/config/Config.java
author cli
Sat Sep 10 18:18:05 2011 +0200 (2011-09-10)
changeset 45 7e24949b87b0
parent 37 74139325d305
child 49 8df94bfd3e2f
permissions -rwxr-xr-x
HSQLDB backend support completed, but untested.
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
chris@3
    19
package org.sonews.config;
chris@3
    20
chris@3
    21
/**
chris@3
    22
 * Configuration facade class.
chris@3
    23
 * @author Christian Lins
chris@3
    24
 * @since sonews/1.0
chris@3
    25
 */
chris@3
    26
public class Config extends AbstractConfig
chris@3
    27
{
chris@3
    28
cli@37
    29
	public static final int LEVEL_CLI = 1;
cli@37
    30
	public static final int LEVEL_FILE = 2;
cli@37
    31
	public static final int LEVEL_BACKEND = 3;
cli@37
    32
	public static final String CONFIGFILE = "sonews.configfile";
cli@37
    33
	/** BackendConfig key constant. Value is the maximum article size in kilobytes. */
cli@37
    34
	public static final String ARTICLE_MAXSIZE = "sonews.article.maxsize";
cli@37
    35
	/** BackendConfig key constant. Value: Amount of news that are feeded per run. */
cli@37
    36
	public static final String EVENTLOG = "sonews.eventlog";
cli@37
    37
	public static final String FEED_NEWSPERRUN = "sonews.feed.newsperrun";
cli@37
    38
	public static final String FEED_PULLINTERVAL = "sonews.feed.pullinterval";
cli@37
    39
	public static final String HOSTNAME = "sonews.hostname";
cli@37
    40
	public static final String PORT = "sonews.port";
cli@37
    41
	public static final String TIMEOUT = "sonews.timeout";
cli@37
    42
	public static final String LOGLEVEL = "sonews.loglevel";
cli@37
    43
	public static final String MLPOLL_DELETEUNKNOWN = "sonews.mlpoll.deleteunknown";
cli@37
    44
	public static final String MLPOLL_HOST = "sonews.mlpoll.host";
cli@37
    45
	public static final String MLPOLL_PASSWORD = "sonews.mlpoll.password";
cli@37
    46
	public static final String MLPOLL_USER = "sonews.mlpoll.user";
cli@37
    47
	public static final String MLSEND_ADDRESS = "sonews.mlsend.address";
cli@37
    48
	public static final String MLSEND_RW_FROM = "sonews.mlsend.rewrite.from";
cli@37
    49
	public static final String MLSEND_RW_SENDER = "sonews.mlsend.rewrite.sender";
cli@37
    50
	public static final String MLSEND_HOST = "sonews.mlsend.host";
cli@37
    51
	public static final String MLSEND_PASSWORD = "sonews.mlsend.password";
cli@37
    52
	public static final String MLSEND_PORT = "sonews.mlsend.port";
cli@37
    53
	public static final String MLSEND_USER = "sonews.mlsend.user";
cli@37
    54
	/** Key constant. If value is "true" every I/O is written to logfile
cli@45
    55
	 * (which is a lot!) */
cli@37
    56
	public static final String DEBUG = "sonews.debug";
cli@37
    57
	/** Key constant. Value is classname of the JDBC driver */
cli@37
    58
	public static final String STORAGE_DBMSDRIVER = "sonews.storage.dbmsdriver";
cli@37
    59
	/** Key constant. Value is JDBC connect String to the database. */
cli@37
    60
	public static final String STORAGE_DATABASE = "sonews.storage.database";
cli@37
    61
	/** Key constant. Value is the username for the DBMS. */
cli@37
    62
	public static final String STORAGE_USER = "sonews.storage.user";
cli@37
    63
	/** Key constant. Value is the password for the DBMS. */
cli@37
    64
	public static final String STORAGE_PASSWORD = "sonews.storage.password";
cli@45
    65
	public static final String STORAGE_PROVIDER = "sonews.storage.provider";
cli@37
    66
	/** Key constant. Value is the name of the host which is allowed to use the
cli@37
    67
	 *  XDAEMON command; default: "localhost" */
cli@37
    68
	public static final String XDAEMON_HOST = "sonews.xdaemon.host";
cli@37
    69
	/** The config key for the filename of the logfile */
cli@37
    70
	public static final String LOGFILE = "sonews.log";
cli@37
    71
	public static final String[] AVAILABLE_KEYS = {
cli@37
    72
		ARTICLE_MAXSIZE,
cli@37
    73
		EVENTLOG,
cli@37
    74
		FEED_NEWSPERRUN,
cli@37
    75
		FEED_PULLINTERVAL,
cli@37
    76
		HOSTNAME,
cli@37
    77
		MLPOLL_DELETEUNKNOWN,
cli@37
    78
		MLPOLL_HOST,
cli@37
    79
		MLPOLL_PASSWORD,
cli@37
    80
		MLPOLL_USER,
cli@37
    81
		MLSEND_ADDRESS,
cli@37
    82
		MLSEND_HOST,
cli@37
    83
		MLSEND_PASSWORD,
cli@37
    84
		MLSEND_PORT,
cli@37
    85
		MLSEND_RW_FROM,
cli@37
    86
		MLSEND_RW_SENDER,
cli@37
    87
		MLSEND_USER,
cli@37
    88
		PORT,
cli@37
    89
		TIMEOUT,
cli@37
    90
		XDAEMON_HOST
cli@37
    91
	};
cli@37
    92
	private static Config instance = new Config();
chris@3
    93
cli@37
    94
	public static Config inst()
cli@37
    95
	{
cli@37
    96
		return instance;
cli@37
    97
	}
chris@3
    98
cli@37
    99
	private Config()
cli@37
   100
	{
cli@37
   101
	}
chris@3
   102
cli@37
   103
	@Override
cli@37
   104
	public String get(String key, String def)
cli@37
   105
	{
cli@37
   106
		String val = CommandLineConfig.getInstance().get(key, null);
chris@3
   107
cli@37
   108
		if (val == null) {
cli@37
   109
			val = FileConfig.getInstance().get(key, null);
cli@37
   110
		}
chris@3
   111
cli@37
   112
		if (val == null) {
cli@37
   113
			val = BackendConfig.getInstance().get(key, def);
cli@37
   114
		}
chris@3
   115
cli@37
   116
		return val;
cli@37
   117
	}
chris@3
   118
cli@37
   119
	public String get(int maxLevel, String key, String def)
cli@37
   120
	{
cli@37
   121
		String val = CommandLineConfig.getInstance().get(key, null);
chris@3
   122
cli@37
   123
		if (val == null && maxLevel >= LEVEL_FILE) {
cli@37
   124
			val = FileConfig.getInstance().get(key, null);
cli@37
   125
			if (val == null && maxLevel >= LEVEL_BACKEND) {
cli@37
   126
				val = BackendConfig.getInstance().get(key, def);
cli@37
   127
			}
cli@37
   128
		}
chris@3
   129
cli@37
   130
		return val != null ? val : def;
cli@37
   131
	}
chris@3
   132
cli@37
   133
	@Override
cli@37
   134
	public void set(String key, String val)
cli@37
   135
	{
cli@37
   136
		set(LEVEL_BACKEND, key, val);
cli@37
   137
	}
chris@3
   138
cli@37
   139
	public void set(int level, String key, String val)
cli@37
   140
	{
cli@37
   141
		switch (level) {
cli@37
   142
			case LEVEL_CLI: {
cli@37
   143
				CommandLineConfig.getInstance().set(key, val);
cli@37
   144
				break;
cli@37
   145
			}
cli@37
   146
			case LEVEL_FILE: {
cli@37
   147
				FileConfig.getInstance().set(key, val);
cli@37
   148
				break;
cli@37
   149
			}
cli@37
   150
			case LEVEL_BACKEND: {
cli@37
   151
				BackendConfig.getInstance().set(key, val);
cli@37
   152
				break;
cli@37
   153
			}
cli@37
   154
		}
cli@37
   155
	}
chris@3
   156
}