org/sonews/config/Config.java
author cli
Thu Aug 06 18:41:34 2009 +0200 (2009-08-06)
changeset 6 dcc7e491fbc9
child 12 bb6990c0dd1a
permissions -rw-r--r--
Removing doc subdir which resides now in sonews-doc repository.
     1 /*
     2  *   SONEWS News Server
     3  *   see AUTHORS for the list of contributors
     4  *
     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.
     9  *
    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.
    14  *
    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/>.
    17  */
    18 
    19 package org.sonews.config;
    20 
    21 /**
    22  * Configuration facade class.
    23  * @author Christian Lins
    24  * @since sonews/1.0
    25  */
    26 public class Config extends AbstractConfig
    27 {
    28   
    29   public static final int LEVEL_CLI     = 1;
    30   public static final int LEVEL_FILE    = 2;
    31   public static final int LEVEL_BACKEND = 3;
    32 
    33   public static final String CONFIGFILE = "sonews.configfile";
    34   
    35     /** BackendConfig key constant. Value is the maximum article size in kilobytes. */
    36   public static final String ARTICLE_MAXSIZE   = "sonews.article.maxsize";
    37 
    38   /** BackendConfig key constant. Value: Amount of news that are feeded per run. */
    39   public static final String EVENTLOG          = "sonews.eventlog";
    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";
    56   
    57   /** Key constant. If value is "true" every I/O is written to logfile
    58    * (which is a lot!)
    59    */
    60   public static final String DEBUG              = "sonews.debug";
    61 
    62   /** Key constant. Value is classname of the JDBC driver */
    63   public static final String STORAGE_DBMSDRIVER = "sonews.storage.dbmsdriver";
    64 
    65   /** Key constant. Value is JDBC connect String to the database. */
    66   public static final String STORAGE_DATABASE   = "sonews.storage.database";
    67 
    68   /** Key constant. Value is the username for the DBMS. */
    69   public static final String STORAGE_USER       = "sonews.storage.user";
    70 
    71   /** Key constant. Value is the password for the DBMS. */
    72   public static final String STORAGE_PASSWORD   = "sonews.storage.password";
    73 
    74   /** Key constant. Value is the name of the host which is allowed to use the
    75    *  XDAEMON command; default: "localhost" */
    76   public static final String XDAEMON_HOST       = "sonews.xdaemon.host";
    77 
    78   /** The config key for the filename of the logfile */
    79   public static final String LOGFILE = "sonews.log";
    80 
    81     public static final String[] AVAILABLE_KEYS = {
    82       ARTICLE_MAXSIZE,
    83       EVENTLOG,
    84       FEED_NEWSPERRUN,
    85       FEED_PULLINTERVAL,
    86       HOSTNAME,
    87       MLPOLL_DELETEUNKNOWN,
    88       MLPOLL_HOST,
    89       MLPOLL_PASSWORD,
    90       MLPOLL_USER,
    91       MLSEND_ADDRESS,
    92       MLSEND_HOST,
    93       MLSEND_PASSWORD,
    94       MLSEND_PORT,
    95       MLSEND_RW_FROM,
    96       MLSEND_RW_SENDER,
    97       MLSEND_USER,
    98       PORT,
    99       TIMEOUT,
   100       XDAEMON_HOST
   101   };
   102 
   103   private static Config instance = new Config();
   104   
   105   public static Config inst()
   106   {
   107     return instance;
   108   }
   109   
   110   private Config(){}
   111 
   112   @Override
   113   public String get(String key, String def)
   114   {
   115     String val = CommandLineConfig.getInstance().get(key, null);
   116     
   117     if(val == null)
   118     {
   119       val = FileConfig.getInstance().get(key, null);
   120     }
   121 
   122     if(val == null)
   123     {
   124       val = BackendConfig.getInstance().get(key, def);
   125     }
   126 
   127     return val;
   128   }
   129 
   130   public String get(int level, String key, String def)
   131   {
   132     switch(level)
   133     {
   134       case LEVEL_CLI:
   135       {
   136         return CommandLineConfig.getInstance().get(key, def);
   137       }
   138       case LEVEL_FILE:
   139       {
   140         return FileConfig.getInstance().get(key, def);
   141       }
   142       case LEVEL_BACKEND:
   143       {
   144         return BackendConfig.getInstance().get(key, def);
   145       }
   146     }
   147     return null;
   148   }
   149 
   150   @Override
   151   public void set(String key, String val)
   152   {
   153     set(LEVEL_BACKEND, key, val);
   154   }
   155 
   156   public void set(int level, String key, String val)
   157   {
   158     switch(level)
   159     {
   160       case LEVEL_CLI:
   161       {
   162         CommandLineConfig.getInstance().set(key, val);
   163         break;
   164       }
   165       case LEVEL_FILE:
   166       {
   167         FileConfig.getInstance().set(key, val);
   168         break;
   169       }
   170       case LEVEL_BACKEND:
   171       {
   172         BackendConfig.getInstance().set(key, val);
   173         break;
   174       }
   175     }
   176   }
   177 
   178 }