org/sonews/config/Config.java
changeset 7 0b76e099eb96
child 12 bb6990c0dd1a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/org/sonews/config/Config.java	Wed Aug 12 13:03:23 2009 +0200
     1.3 @@ -0,0 +1,178 @@
     1.4 +/*
     1.5 + *   SONEWS News Server
     1.6 + *   see AUTHORS for the list of contributors
     1.7 + *
     1.8 + *   This program is free software: you can redistribute it and/or modify
     1.9 + *   it under the terms of the GNU General Public License as published by
    1.10 + *   the Free Software Foundation, either version 3 of the License, or
    1.11 + *   (at your option) any later version.
    1.12 + *
    1.13 + *   This program is distributed in the hope that it will be useful,
    1.14 + *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 + *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.16 + *   GNU General Public License for more details.
    1.17 + *
    1.18 + *   You should have received a copy of the GNU General Public License
    1.19 + *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    1.20 + */
    1.21 +
    1.22 +package org.sonews.config;
    1.23 +
    1.24 +/**
    1.25 + * Configuration facade class.
    1.26 + * @author Christian Lins
    1.27 + * @since sonews/1.0
    1.28 + */
    1.29 +public class Config extends AbstractConfig
    1.30 +{
    1.31 +  
    1.32 +  public static final int LEVEL_CLI     = 1;
    1.33 +  public static final int LEVEL_FILE    = 2;
    1.34 +  public static final int LEVEL_BACKEND = 3;
    1.35 +
    1.36 +  public static final String CONFIGFILE = "sonews.configfile";
    1.37 +  
    1.38 +    /** BackendConfig key constant. Value is the maximum article size in kilobytes. */
    1.39 +  public static final String ARTICLE_MAXSIZE   = "sonews.article.maxsize";
    1.40 +
    1.41 +  /** BackendConfig key constant. Value: Amount of news that are feeded per run. */
    1.42 +  public static final String EVENTLOG          = "sonews.eventlog";
    1.43 +  public static final String FEED_NEWSPERRUN   = "sonews.feed.newsperrun";
    1.44 +  public static final String FEED_PULLINTERVAL = "sonews.feed.pullinterval";
    1.45 +  public static final String HOSTNAME          = "sonews.hostname";
    1.46 +  public static final String PORT              = "sonews.port";
    1.47 +  public static final String TIMEOUT           = "sonews.timeout";
    1.48 +  public static final String MLPOLL_DELETEUNKNOWN = "sonews.mlpoll.deleteunknown";
    1.49 +  public static final String MLPOLL_HOST       = "sonews.mlpoll.host";
    1.50 +  public static final String MLPOLL_PASSWORD   = "sonews.mlpoll.password";
    1.51 +  public static final String MLPOLL_USER       = "sonews.mlpoll.user";
    1.52 +  public static final String MLSEND_ADDRESS    = "sonews.mlsend.address";
    1.53 +  public static final String MLSEND_RW_FROM    = "sonews.mlsend.rewrite.from";
    1.54 +  public static final String MLSEND_RW_SENDER  = "sonews.mlsend.rewrite.sender";
    1.55 +  public static final String MLSEND_HOST       = "sonews.mlsend.host";
    1.56 +  public static final String MLSEND_PASSWORD   = "sonews.mlsend.password";
    1.57 +  public static final String MLSEND_PORT       = "sonews.mlsend.port";
    1.58 +  public static final String MLSEND_USER       = "sonews.mlsend.user";
    1.59 +  
    1.60 +  /** Key constant. If value is "true" every I/O is written to logfile
    1.61 +   * (which is a lot!)
    1.62 +   */
    1.63 +  public static final String DEBUG              = "sonews.debug";
    1.64 +
    1.65 +  /** Key constant. Value is classname of the JDBC driver */
    1.66 +  public static final String STORAGE_DBMSDRIVER = "sonews.storage.dbmsdriver";
    1.67 +
    1.68 +  /** Key constant. Value is JDBC connect String to the database. */
    1.69 +  public static final String STORAGE_DATABASE   = "sonews.storage.database";
    1.70 +
    1.71 +  /** Key constant. Value is the username for the DBMS. */
    1.72 +  public static final String STORAGE_USER       = "sonews.storage.user";
    1.73 +
    1.74 +  /** Key constant. Value is the password for the DBMS. */
    1.75 +  public static final String STORAGE_PASSWORD   = "sonews.storage.password";
    1.76 +
    1.77 +  /** Key constant. Value is the name of the host which is allowed to use the
    1.78 +   *  XDAEMON command; default: "localhost" */
    1.79 +  public static final String XDAEMON_HOST       = "sonews.xdaemon.host";
    1.80 +
    1.81 +  /** The config key for the filename of the logfile */
    1.82 +  public static final String LOGFILE = "sonews.log";
    1.83 +
    1.84 +    public static final String[] AVAILABLE_KEYS = {
    1.85 +      ARTICLE_MAXSIZE,
    1.86 +      EVENTLOG,
    1.87 +      FEED_NEWSPERRUN,
    1.88 +      FEED_PULLINTERVAL,
    1.89 +      HOSTNAME,
    1.90 +      MLPOLL_DELETEUNKNOWN,
    1.91 +      MLPOLL_HOST,
    1.92 +      MLPOLL_PASSWORD,
    1.93 +      MLPOLL_USER,
    1.94 +      MLSEND_ADDRESS,
    1.95 +      MLSEND_HOST,
    1.96 +      MLSEND_PASSWORD,
    1.97 +      MLSEND_PORT,
    1.98 +      MLSEND_RW_FROM,
    1.99 +      MLSEND_RW_SENDER,
   1.100 +      MLSEND_USER,
   1.101 +      PORT,
   1.102 +      TIMEOUT,
   1.103 +      XDAEMON_HOST
   1.104 +  };
   1.105 +
   1.106 +  private static Config instance = new Config();
   1.107 +  
   1.108 +  public static Config inst()
   1.109 +  {
   1.110 +    return instance;
   1.111 +  }
   1.112 +  
   1.113 +  private Config(){}
   1.114 +
   1.115 +  @Override
   1.116 +  public String get(String key, String def)
   1.117 +  {
   1.118 +    String val = CommandLineConfig.getInstance().get(key, null);
   1.119 +    
   1.120 +    if(val == null)
   1.121 +    {
   1.122 +      val = FileConfig.getInstance().get(key, null);
   1.123 +    }
   1.124 +
   1.125 +    if(val == null)
   1.126 +    {
   1.127 +      val = BackendConfig.getInstance().get(key, def);
   1.128 +    }
   1.129 +
   1.130 +    return val;
   1.131 +  }
   1.132 +
   1.133 +  public String get(int level, String key, String def)
   1.134 +  {
   1.135 +    switch(level)
   1.136 +    {
   1.137 +      case LEVEL_CLI:
   1.138 +      {
   1.139 +        return CommandLineConfig.getInstance().get(key, def);
   1.140 +      }
   1.141 +      case LEVEL_FILE:
   1.142 +      {
   1.143 +        return FileConfig.getInstance().get(key, def);
   1.144 +      }
   1.145 +      case LEVEL_BACKEND:
   1.146 +      {
   1.147 +        return BackendConfig.getInstance().get(key, def);
   1.148 +      }
   1.149 +    }
   1.150 +    return null;
   1.151 +  }
   1.152 +
   1.153 +  @Override
   1.154 +  public void set(String key, String val)
   1.155 +  {
   1.156 +    set(LEVEL_BACKEND, key, val);
   1.157 +  }
   1.158 +
   1.159 +  public void set(int level, String key, String val)
   1.160 +  {
   1.161 +    switch(level)
   1.162 +    {
   1.163 +      case LEVEL_CLI:
   1.164 +      {
   1.165 +        CommandLineConfig.getInstance().set(key, val);
   1.166 +        break;
   1.167 +      }
   1.168 +      case LEVEL_FILE:
   1.169 +      {
   1.170 +        FileConfig.getInstance().set(key, val);
   1.171 +        break;
   1.172 +      }
   1.173 +      case LEVEL_BACKEND:
   1.174 +      {
   1.175 +        BackendConfig.getInstance().set(key, val);
   1.176 +        break;
   1.177 +      }
   1.178 +    }
   1.179 +  }
   1.180 +
   1.181 +}