Hooray... sonews/0.5.0 final
HG: Enter commit message. Lines beginning with 'HG:' are removed.
HG: Remove all lines to abort the collapse operation.
3 * see AUTHORS for the list of contributors
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 package org.sonews.daemon;
21 import org.sonews.util.Log;
22 import java.sql.SQLException;
23 import org.sonews.daemon.storage.Database;
24 import org.sonews.util.AbstractConfig;
25 import org.sonews.util.TimeoutMap;
28 * Provides access to the program wide configuration that is stored within
29 * the server's database.
30 * @author Christian Lins
33 public final class Config extends AbstractConfig
36 /** Config key constant. Value is the maximum article size in kilobytes. */
37 public static final String ARTICLE_MAXSIZE = "sonews.article.maxsize";
39 /** Config key constant. Value: Amount of news that are feeded per run. */
40 public static final String FEED_NEWSPERRUN = "sonews.feed.newsperrun";
41 public static final String FEED_PULLINTERVAL = "sonews.feed.pullinterval";
42 public static final String HOSTNAME = "sonews.hostname";
43 public static final String PORT = "sonews.port";
44 public static final String TIMEOUT = "sonews.timeout";
45 public static final String MLPOLL_DELETEUNKNOWN = "sonews.mlpoll.deleteunknown";
46 public static final String MLPOLL_HOST = "sonews.mlpoll.host";
47 public static final String MLPOLL_PASSWORD = "sonews.mlpoll.password";
48 public static final String MLPOLL_USER = "sonews.mlpoll.user";
49 public static final String MLSEND_ADDRESS = "sonews.mlsend.address";
50 public static final String MLSEND_RW_FROM = "sonews.mlsend.rewrite.from";
51 public static final String MLSEND_RW_SENDER = "sonews.mlsend.rewrite.sender";
52 public static final String MLSEND_HOST = "sonews.mlsend.host";
53 public static final String MLSEND_PASSWORD = "sonews.mlsend.password";
54 public static final String MLSEND_PORT = "sonews.mlsend.port";
55 public static final String MLSEND_USER = "sonews.mlsend.user";
57 public static final String[] AVAILABLE_KEYS = {
58 Config.ARTICLE_MAXSIZE,
59 Config.FEED_NEWSPERRUN,
60 Config.FEED_PULLINTERVAL,
62 Config.MLPOLL_DELETEUNKNOWN,
64 Config.MLPOLL_PASSWORD,
66 Config.MLSEND_ADDRESS,
68 Config.MLSEND_PASSWORD,
70 Config.MLSEND_RW_FROM,
71 Config.MLSEND_RW_SENDER,
77 private static Config instance = new Config();
79 public static Config getInstance()
84 private final TimeoutMap<String, String> values
85 = new TimeoutMap<String, String>();
93 * Returns the config value for the given key or the defaultValue if the
94 * key is not found in config.
99 public String get(String key, String defaultValue)
103 String configValue = values.get(key);
104 if(configValue == null)
106 configValue = Database.getInstance().getConfigValue(key);
107 if(configValue == null)
113 values.put(key, configValue);
122 catch(SQLException ex)
124 Log.msg(ex.getMessage(), false);
130 * Sets the config value which is identified by the given key.
134 public void set(String key, String value)
136 values.put(key, value);
140 // Write values to database
141 Database.getInstance().setConfigValue(key, value);
143 catch(SQLException ex)
145 ex.printStackTrace();