Class Config

java.lang.Object
net.sf.basedb.core.Config

public class Config
extends Object
Use this class to access the configuration settings for BASE.

The configuration settings are always stored in a file named base.config. It should be located at the root of one of the paths in the CLASSPATH environment variable. For Tomcat this means it should be located in the WEB-INF/classes folder.

Version:
2.0
Author:
Nicklas
  • Field Details

    • config

      private static Properties config
      Variable for holding the configuration properties.
    • overridden

      private static Properties overridden
      Properties that has been programmatically overridden.
    • isInitialised

      private static boolean isInitialised
    • configDir

      private static File configDir
    • locale

      private static Locale locale
    • commonCharsets

      private static SortedSet<String> commonCharsets
    • allCharsets

      private static SortedSet<String> allCharsets
  • Constructor Details

    • Config

      public Config()
  • Method Details

    • init

      static void init() throws ConfigurationException
      Loads the settings from the configuration file.
      Throws:
      ConfigurationException - This exception is thrown if the configuration settings cannot be loaded
    • unload

      static void unload()
      Unload all settings.
    • setProperty

      public static void setProperty​(String key, String value)
      Programatically set a configuration property that overrides a configuration setting in the base.config file. This method should be called before the init() method is called (eg. before Application.start() is called). The configuration can't be changed once BASE has been started. Properties that has been overridden are automatically cleared when BASE is stopped (Application.stop(), unload()).
      Parameters:
      key - The name of the configuration property
      value - The value or null to remove the overridden property
      Since:
      2.16
    • getConfigDirectory

      public static File getConfigDirectory()
      Get the directory where the BASE configuration files are located.
      Returns:
      The directory as a java.io.File object
      Since:
      2.6
    • getString

      public static String getString​(String key)
      Get the configuration setting specified by key as a String value.
      Parameters:
      key - The key for the setting
      Returns:
      The value specified by key or null if it is not found
    • getRequiredString

      public static String getRequiredString​(String key, String message)
      Get a required configuration setting. If the setting doesn't exists or is empty the given message is thrown as a ConfigurationException
      Parameters:
      key - The key for the setting
      message - The error message to throw if the setting doesn't exists
      Returns:
      The value specified by key
      Since:
      3.0
    • getString

      public static String getString​(String key, String defaultValue)
      Get the configuration setting specified by key as a String value.
      Parameters:
      key - The key for the setting
      defaultValue - The value to return if the key is not found
      Returns:
      The value specified by key or defaultValue if it is not found or is empty
    • getInt

      public static int getInt​(String key)
      Get the configuration setting specified by key as an integer value.
      Parameters:
      key - The key for the setting
      Returns:
      The value specified by key or 0 if it is not found or is not a number
    • getInt

      public static int getInt​(String key, int defaultValue)
      Get the configuration setting specified by key as an integer value.
      Parameters:
      key - The key for the setting
      defaultValue - The value to return if the key is not found
      Returns:
      The value specified by key or defaultValue if it is not found
    • getLong

      public static long getLong​(String key, long defaultValue)
      Get the configuration setting specified by key as a long value.
      Parameters:
      key - The key for the setting
      defaultValue - The value to return if the key is not found
      Returns:
      The value specified by key or defaultValue if it is not found
    • getBoolean

      public static boolean getBoolean​(String key)
      Get the configuration setting specified by key as a boolean value. FALSE is returned if the setting doesn't exist, if it contains an empty string, or one of the values 'no', 'false' or '0'. In all other cases TRUE is returned.
      Parameters:
      key - The key for the setting
      Returns:
      The value specified by key
    • getCharset

      public static String getCharset()
      Get the default character set to use when no other has been specified. It reads the setting from the defaultCharset setting and uses ISO-8859-1 if not specified.
      Returns:
      The name of the default charset to use
      Since:
      2.1.1
    • getCommonCharsets

      public static SortedSet<String> getCommonCharsets()
      Get a set containing the most common character sets used by text files. The set is sorted by name.
      Returns:
      A sorted set
      Since:
      2.17
    • getAllCharsets

      public static SortedSet<String> getAllCharsets()
      Get a set containing all character sets known to the current java virtual machine. The set is sorted by name with the most common character sets first.
      Returns:
      A sorted set
      Since:
      2.17
    • getLocale

      public static Locale getLocale()
      Get the default locale configured for the server.
      Since:
      2.16