org/sonews/config/Config.java
author cli
Mon, 24 Aug 2009 13:00:05 +0200
changeset 20 6ae5e4f8329b
parent 15 f2293e8566f5
child 30 146b3275b792
permissions -rw-r--r--
Add stubs for org.sonews.acl and add method "impliedCapability" for org.sonews.command.Command interface.
     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 LOGLEVEL          = "sonews.loglevel";
    46   public static final String MLPOLL_DELETEUNKNOWN = "sonews.mlpoll.deleteunknown";
    47   public static final String MLPOLL_HOST       = "sonews.mlpoll.host";
    48   public static final String MLPOLL_PASSWORD   = "sonews.mlpoll.password";
    49   public static final String MLPOLL_USER       = "sonews.mlpoll.user";
    50   public static final String MLSEND_ADDRESS    = "sonews.mlsend.address";
    51   public static final String MLSEND_RW_FROM    = "sonews.mlsend.rewrite.from";
    52   public static final String MLSEND_RW_SENDER  = "sonews.mlsend.rewrite.sender";
    53   public static final String MLSEND_HOST       = "sonews.mlsend.host";
    54   public static final String MLSEND_PASSWORD   = "sonews.mlsend.password";
    55   public static final String MLSEND_PORT       = "sonews.mlsend.port";
    56   public static final String MLSEND_USER       = "sonews.mlsend.user";
    57   
    58   /** Key constant. If value is "true" every I/O is written to logfile
    59    * (which is a lot!)
    60    */
    61   public static final String DEBUG              = "sonews.debug";
    62 
    63   /** Key constant. Value is classname of the JDBC driver */
    64   public static final String STORAGE_DBMSDRIVER = "sonews.storage.dbmsdriver";
    65 
    66   /** Key constant. Value is JDBC connect String to the database. */
    67   public static final String STORAGE_DATABASE   = "sonews.storage.database";
    68 
    69   /** Key constant. Value is the username for the DBMS. */
    70   public static final String STORAGE_USER       = "sonews.storage.user";
    71 
    72   /** Key constant. Value is the password for the DBMS. */
    73   public static final String STORAGE_PASSWORD   = "sonews.storage.password";
    74 
    75   /** Key constant. Value is the name of the host which is allowed to use the
    76    *  XDAEMON command; default: "localhost" */
    77   public static final String XDAEMON_HOST       = "sonews.xdaemon.host";
    78 
    79   /** The config key for the filename of the logfile */
    80   public static final String LOGFILE = "sonews.log";
    81 
    82   public static final String[] AVAILABLE_KEYS = {
    83       ARTICLE_MAXSIZE,
    84       EVENTLOG,
    85       FEED_NEWSPERRUN,
    86       FEED_PULLINTERVAL,
    87       HOSTNAME,
    88       MLPOLL_DELETEUNKNOWN,
    89       MLPOLL_HOST,
    90       MLPOLL_PASSWORD,
    91       MLPOLL_USER,
    92       MLSEND_ADDRESS,
    93       MLSEND_HOST,
    94       MLSEND_PASSWORD,
    95       MLSEND_PORT,
    96       MLSEND_RW_FROM,
    97       MLSEND_RW_SENDER,
    98       MLSEND_USER,
    99       PORT,
   100       TIMEOUT,
   101       XDAEMON_HOST
   102   };
   103 
   104   private static Config instance = new Config();
   105   
   106   public static Config inst()
   107   {
   108     return instance;
   109   }
   110   
   111   private Config(){}
   112 
   113   @Override
   114   public String get(String key, String def)
   115   {
   116     String val = CommandLineConfig.getInstance().get(key, null);
   117     
   118     if(val == null)
   119     {
   120       val = FileConfig.getInstance().get(key, null);
   121     }
   122 
   123     if(val == null)
   124     {
   125       val = BackendConfig.getInstance().get(key, def);
   126     }
   127 
   128     return val;
   129   }
   130 
   131   public String get(int level, String key, String def)
   132   {
   133     switch(level)
   134     {
   135       case LEVEL_CLI:
   136       {
   137         return CommandLineConfig.getInstance().get(key, def);
   138       }
   139       case LEVEL_FILE:
   140       {
   141         return FileConfig.getInstance().get(key, def);
   142       }
   143       case LEVEL_BACKEND:
   144       {
   145         return BackendConfig.getInstance().get(key, def);
   146       }
   147     }
   148     return null;
   149   }
   150 
   151   @Override
   152   public void set(String key, String val)
   153   {
   154     set(LEVEL_BACKEND, key, val);
   155   }
   156 
   157   public void set(int level, String key, String val)
   158   {
   159     switch(level)
   160     {
   161       case LEVEL_CLI:
   162       {
   163         CommandLineConfig.getInstance().set(key, val);
   164         break;
   165       }
   166       case LEVEL_FILE:
   167       {
   168         FileConfig.getInstance().set(key, val);
   169         break;
   170       }
   171       case LEVEL_BACKEND:
   172       {
   173         BackendConfig.getInstance().set(key, val);
   174         break;
   175       }
   176     }
   177   }
   178 
   179 }