org/sonews/config/Config.java
author cli
Wed, 12 Aug 2009 16:38:11 +0200
changeset 8 b62fe6ed39d3
parent 3 2fdc9cc89502
child 12 bb6990c0dd1a
permissions -rw-r--r--
Disable strict parsing of email addresses.
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
  
chris@3
    29
  public static final int LEVEL_CLI     = 1;
chris@3
    30
  public static final int LEVEL_FILE    = 2;
chris@3
    31
  public static final int LEVEL_BACKEND = 3;
chris@3
    32
chris@3
    33
  public static final String CONFIGFILE = "sonews.configfile";
chris@3
    34
  
chris@3
    35
    /** BackendConfig key constant. Value is the maximum article size in kilobytes. */
chris@3
    36
  public static final String ARTICLE_MAXSIZE   = "sonews.article.maxsize";
chris@3
    37
chris@3
    38
  /** BackendConfig key constant. Value: Amount of news that are feeded per run. */
chris@3
    39
  public static final String EVENTLOG          = "sonews.eventlog";
chris@3
    40
  public static final String FEED_NEWSPERRUN   = "sonews.feed.newsperrun";
chris@3
    41
  public static final String FEED_PULLINTERVAL = "sonews.feed.pullinterval";
chris@3
    42
  public static final String HOSTNAME          = "sonews.hostname";
chris@3
    43
  public static final String PORT              = "sonews.port";
chris@3
    44
  public static final String TIMEOUT           = "sonews.timeout";
chris@3
    45
  public static final String MLPOLL_DELETEUNKNOWN = "sonews.mlpoll.deleteunknown";
chris@3
    46
  public static final String MLPOLL_HOST       = "sonews.mlpoll.host";
chris@3
    47
  public static final String MLPOLL_PASSWORD   = "sonews.mlpoll.password";
chris@3
    48
  public static final String MLPOLL_USER       = "sonews.mlpoll.user";
chris@3
    49
  public static final String MLSEND_ADDRESS    = "sonews.mlsend.address";
chris@3
    50
  public static final String MLSEND_RW_FROM    = "sonews.mlsend.rewrite.from";
chris@3
    51
  public static final String MLSEND_RW_SENDER  = "sonews.mlsend.rewrite.sender";
chris@3
    52
  public static final String MLSEND_HOST       = "sonews.mlsend.host";
chris@3
    53
  public static final String MLSEND_PASSWORD   = "sonews.mlsend.password";
chris@3
    54
  public static final String MLSEND_PORT       = "sonews.mlsend.port";
chris@3
    55
  public static final String MLSEND_USER       = "sonews.mlsend.user";
chris@3
    56
  
chris@3
    57
  /** Key constant. If value is "true" every I/O is written to logfile
chris@3
    58
   * (which is a lot!)
chris@3
    59
   */
chris@3
    60
  public static final String DEBUG              = "sonews.debug";
chris@3
    61
chris@3
    62
  /** Key constant. Value is classname of the JDBC driver */
chris@3
    63
  public static final String STORAGE_DBMSDRIVER = "sonews.storage.dbmsdriver";
chris@3
    64
chris@3
    65
  /** Key constant. Value is JDBC connect String to the database. */
chris@3
    66
  public static final String STORAGE_DATABASE   = "sonews.storage.database";
chris@3
    67
chris@3
    68
  /** Key constant. Value is the username for the DBMS. */
chris@3
    69
  public static final String STORAGE_USER       = "sonews.storage.user";
chris@3
    70
chris@3
    71
  /** Key constant. Value is the password for the DBMS. */
chris@3
    72
  public static final String STORAGE_PASSWORD   = "sonews.storage.password";
chris@3
    73
chris@3
    74
  /** Key constant. Value is the name of the host which is allowed to use the
chris@3
    75
   *  XDAEMON command; default: "localhost" */
chris@3
    76
  public static final String XDAEMON_HOST       = "sonews.xdaemon.host";
chris@3
    77
chris@3
    78
  /** The config key for the filename of the logfile */
chris@3
    79
  public static final String LOGFILE = "sonews.log";
chris@3
    80
chris@3
    81
    public static final String[] AVAILABLE_KEYS = {
chris@3
    82
      ARTICLE_MAXSIZE,
chris@3
    83
      EVENTLOG,
chris@3
    84
      FEED_NEWSPERRUN,
chris@3
    85
      FEED_PULLINTERVAL,
chris@3
    86
      HOSTNAME,
chris@3
    87
      MLPOLL_DELETEUNKNOWN,
chris@3
    88
      MLPOLL_HOST,
chris@3
    89
      MLPOLL_PASSWORD,
chris@3
    90
      MLPOLL_USER,
chris@3
    91
      MLSEND_ADDRESS,
chris@3
    92
      MLSEND_HOST,
chris@3
    93
      MLSEND_PASSWORD,
chris@3
    94
      MLSEND_PORT,
chris@3
    95
      MLSEND_RW_FROM,
chris@3
    96
      MLSEND_RW_SENDER,
chris@3
    97
      MLSEND_USER,
chris@3
    98
      PORT,
chris@3
    99
      TIMEOUT,
chris@3
   100
      XDAEMON_HOST
chris@3
   101
  };
chris@3
   102
chris@3
   103
  private static Config instance = new Config();
chris@3
   104
  
chris@3
   105
  public static Config inst()
chris@3
   106
  {
chris@3
   107
    return instance;
chris@3
   108
  }
chris@3
   109
  
chris@3
   110
  private Config(){}
chris@3
   111
chris@3
   112
  @Override
chris@3
   113
  public String get(String key, String def)
chris@3
   114
  {
chris@3
   115
    String val = CommandLineConfig.getInstance().get(key, null);
chris@3
   116
    
chris@3
   117
    if(val == null)
chris@3
   118
    {
chris@3
   119
      val = FileConfig.getInstance().get(key, null);
chris@3
   120
    }
chris@3
   121
chris@3
   122
    if(val == null)
chris@3
   123
    {
chris@3
   124
      val = BackendConfig.getInstance().get(key, def);
chris@3
   125
    }
chris@3
   126
chris@3
   127
    return val;
chris@3
   128
  }
chris@3
   129
chris@3
   130
  public String get(int level, String key, String def)
chris@3
   131
  {
chris@3
   132
    switch(level)
chris@3
   133
    {
chris@3
   134
      case LEVEL_CLI:
chris@3
   135
      {
chris@3
   136
        return CommandLineConfig.getInstance().get(key, def);
chris@3
   137
      }
chris@3
   138
      case LEVEL_FILE:
chris@3
   139
      {
chris@3
   140
        return FileConfig.getInstance().get(key, def);
chris@3
   141
      }
chris@3
   142
      case LEVEL_BACKEND:
chris@3
   143
      {
chris@3
   144
        return BackendConfig.getInstance().get(key, def);
chris@3
   145
      }
chris@3
   146
    }
chris@3
   147
    return null;
chris@3
   148
  }
chris@3
   149
chris@3
   150
  @Override
chris@3
   151
  public void set(String key, String val)
chris@3
   152
  {
chris@3
   153
    set(LEVEL_BACKEND, key, val);
chris@3
   154
  }
chris@3
   155
chris@3
   156
  public void set(int level, String key, String val)
chris@3
   157
  {
chris@3
   158
    switch(level)
chris@3
   159
    {
chris@3
   160
      case LEVEL_CLI:
chris@3
   161
      {
chris@3
   162
        CommandLineConfig.getInstance().set(key, val);
chris@3
   163
        break;
chris@3
   164
      }
chris@3
   165
      case LEVEL_FILE:
chris@3
   166
      {
chris@3
   167
        FileConfig.getInstance().set(key, val);
chris@3
   168
        break;
chris@3
   169
      }
chris@3
   170
      case LEVEL_BACKEND:
chris@3
   171
      {
chris@3
   172
        BackendConfig.getInstance().set(key, val);
chris@3
   173
        break;
chris@3
   174
      }
chris@3
   175
    }
chris@3
   176
  }
chris@3
   177
chris@3
   178
}