src/org/sonews/config/Config.java
author František Kučera <franta-hg@frantovo.cz>
Fri Oct 14 00:45:06 2011 +0200 (2011-10-14)
changeset 76 b5690fc25af6
parent 49 8df94bfd3e2f
permissions -rwxr-xr-x
Drupal: XSL šablona pro formátování XHTML části zprávy.
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@58
    35
cli@37
    36
	public static final String FEED_NEWSPERRUN = "sonews.feed.newsperrun";
cli@37
    37
	public static final String FEED_PULLINTERVAL = "sonews.feed.pullinterval";
cli@58
    38
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@58
    43
cli@37
    44
	public static final String MLPOLL_DELETEUNKNOWN = "sonews.mlpoll.deleteunknown";
cli@37
    45
	public static final String MLPOLL_HOST = "sonews.mlpoll.host";
cli@37
    46
	public static final String MLPOLL_PASSWORD = "sonews.mlpoll.password";
cli@37
    47
	public static final String MLPOLL_USER = "sonews.mlpoll.user";
cli@58
    48
cli@37
    49
	public static final String MLSEND_ADDRESS = "sonews.mlsend.address";
cli@37
    50
	public static final String MLSEND_RW_FROM = "sonews.mlsend.rewrite.from";
cli@37
    51
	public static final String MLSEND_RW_SENDER = "sonews.mlsend.rewrite.sender";
cli@37
    52
	public static final String MLSEND_HOST = "sonews.mlsend.host";
cli@37
    53
	public static final String MLSEND_PASSWORD = "sonews.mlsend.password";
cli@37
    54
	public static final String MLSEND_PORT = "sonews.mlsend.port";
cli@37
    55
	public static final String MLSEND_USER = "sonews.mlsend.user";
cli@58
    56
	public static final String MLSEND_AUTH = "sonews.mlsend.auth";
cli@58
    57
cli@37
    58
	/** Key constant. If value is "true" every I/O is written to logfile
cli@45
    59
	 * (which is a lot!) */
cli@37
    60
	public static final String DEBUG = "sonews.debug";
cli@58
    61
cli@37
    62
	/** Key constant. Value is classname of the JDBC driver */
cli@37
    63
	public static final String STORAGE_DBMSDRIVER = "sonews.storage.dbmsdriver";
cli@37
    64
	/** Key constant. Value is JDBC connect String to the database. */
cli@37
    65
	public static final String STORAGE_DATABASE = "sonews.storage.database";
cli@37
    66
	/** Key constant. Value is the username for the DBMS. */
cli@37
    67
	public static final String STORAGE_USER = "sonews.storage.user";
cli@37
    68
	/** Key constant. Value is the password for the DBMS. */
cli@37
    69
	public static final String STORAGE_PASSWORD = "sonews.storage.password";
cli@45
    70
	public static final String STORAGE_PROVIDER = "sonews.storage.provider";
cli@58
    71
cli@37
    72
	/** Key constant. Value is the name of the host which is allowed to use the
cli@37
    73
	 *  XDAEMON command; default: "localhost" */
cli@37
    74
	public static final String XDAEMON_HOST = "sonews.xdaemon.host";
cli@58
    75
cli@37
    76
	/** The config key for the filename of the logfile */
cli@37
    77
	public static final String LOGFILE = "sonews.log";
cli@37
    78
	public static final String[] AVAILABLE_KEYS = {
cli@37
    79
		ARTICLE_MAXSIZE,
cli@37
    80
		EVENTLOG,
cli@37
    81
		FEED_NEWSPERRUN,
cli@37
    82
		FEED_PULLINTERVAL,
cli@37
    83
		HOSTNAME,
cli@37
    84
		MLPOLL_DELETEUNKNOWN,
cli@37
    85
		MLPOLL_HOST,
cli@37
    86
		MLPOLL_PASSWORD,
cli@37
    87
		MLPOLL_USER,
cli@37
    88
		MLSEND_ADDRESS,
cli@37
    89
		MLSEND_HOST,
cli@37
    90
		MLSEND_PASSWORD,
cli@37
    91
		MLSEND_PORT,
cli@37
    92
		MLSEND_RW_FROM,
cli@37
    93
		MLSEND_RW_SENDER,
cli@37
    94
		MLSEND_USER,
cli@37
    95
		PORT,
cli@37
    96
		TIMEOUT,
cli@37
    97
		XDAEMON_HOST
cli@37
    98
	};
cli@37
    99
	private static Config instance = new Config();
chris@3
   100
cli@49
   101
	public static Config inst() {
cli@37
   102
		return instance;
cli@37
   103
	}
chris@3
   104
cli@49
   105
	private Config() {
cli@37
   106
	}
chris@3
   107
cli@37
   108
	@Override
cli@49
   109
	public String get(String key, String def) {
cli@37
   110
		String val = CommandLineConfig.getInstance().get(key, null);
chris@3
   111
cli@37
   112
		if (val == null) {
cli@37
   113
			val = FileConfig.getInstance().get(key, null);
cli@37
   114
		}
chris@3
   115
cli@37
   116
		if (val == null) {
cli@37
   117
			val = BackendConfig.getInstance().get(key, def);
cli@37
   118
		}
chris@3
   119
cli@37
   120
		return val;
cli@37
   121
	}
chris@3
   122
cli@49
   123
	public String get(int maxLevel, String key, String def) {
cli@37
   124
		String val = CommandLineConfig.getInstance().get(key, null);
chris@3
   125
cli@37
   126
		if (val == null && maxLevel >= LEVEL_FILE) {
cli@37
   127
			val = FileConfig.getInstance().get(key, null);
cli@37
   128
			if (val == null && maxLevel >= LEVEL_BACKEND) {
cli@37
   129
				val = BackendConfig.getInstance().get(key, def);
cli@37
   130
			}
cli@37
   131
		}
chris@3
   132
cli@37
   133
		return val != null ? val : def;
cli@37
   134
	}
chris@3
   135
cli@37
   136
	@Override
cli@49
   137
	public void set(String key, String val) {
cli@37
   138
		set(LEVEL_BACKEND, key, val);
cli@37
   139
	}
chris@3
   140
cli@49
   141
	public void set(int level, String key, String val) {
cli@37
   142
		switch (level) {
cli@37
   143
			case LEVEL_CLI: {
cli@37
   144
				CommandLineConfig.getInstance().set(key, val);
cli@37
   145
				break;
cli@37
   146
			}
cli@37
   147
			case LEVEL_FILE: {
cli@37
   148
				FileConfig.getInstance().set(key, val);
cli@37
   149
				break;
cli@37
   150
			}
cli@37
   151
			case LEVEL_BACKEND: {
cli@37
   152
				BackendConfig.getInstance().set(key, val);
cli@37
   153
				break;
cli@37
   154
			}
cli@37
   155
		}
cli@37
   156
	}
chris@3
   157
}