public class Config
extends java.lang.Object
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.
Modifier and Type | Field and Description |
---|---|
private static java.util.SortedSet<java.lang.String> |
allCharsets |
private static java.util.SortedSet<java.lang.String> |
commonCharsets |
private static java.util.Properties |
config
Variable for holding the configuration properties.
|
private static java.io.File |
configDir |
private static boolean |
isInitialised |
private static java.util.Locale |
locale |
private static java.util.Properties |
overridden
Properties that has been programmatically overridden.
|
Constructor and Description |
---|
Config() |
Modifier and Type | Method and Description |
---|---|
static java.util.SortedSet<java.lang.String> |
getAllCharsets()
Get a set containing all character sets known to the current java virtual machine.
|
static boolean |
getBoolean(java.lang.String key)
Get the configuration setting specified by
key as a boolean
value. |
static java.lang.String |
getCharset()
Get the default character set to use when no other has been
specified.
|
static java.util.SortedSet<java.lang.String> |
getCommonCharsets()
Get a set containing the most common character sets used by text files.
|
static java.io.File |
getConfigDirectory()
Get the directory where the BASE configuration files are located.
|
static int |
getInt(java.lang.String key)
Get the configuration setting specified by
key as an integer value. |
static int |
getInt(java.lang.String key,
int defaultValue)
Get the configuration setting specified by
key as an integer value. |
static java.util.Locale |
getLocale()
Get the default locale configured for the server.
|
static long |
getLong(java.lang.String key,
long defaultValue)
Get the configuration setting specified by
key as a long value. |
static java.lang.String |
getRequiredString(java.lang.String key,
java.lang.String message)
Get a required configuration setting.
|
static java.lang.String |
getString(java.lang.String key)
Get the configuration setting specified by
key as a String value. |
static java.lang.String |
getString(java.lang.String key,
java.lang.String defaultValue)
Get the configuration setting specified by
key as a String value. |
(package private) static void |
init()
Loads the settings from the configuration file.
|
static void |
setProperty(java.lang.String key,
java.lang.String value)
Programatically set a configuration property that overrides a configuration
setting in the base.config file.
|
(package private) static void |
unload()
Unload all settings.
|
private static java.util.Properties config
private static java.util.Properties overridden
private static boolean isInitialised
private static java.io.File configDir
private static java.util.Locale locale
private static java.util.SortedSet<java.lang.String> commonCharsets
private static java.util.SortedSet<java.lang.String> allCharsets
static void init() throws ConfigurationException
ConfigurationException
- This exception is thrown if the
configuration settings cannot be loadedstatic void unload()
public static void setProperty(java.lang.String key, java.lang.String value)
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()
).key
- The name of the configuration propertyvalue
- The value or null to remove the overridden propertypublic static java.io.File getConfigDirectory()
java.io.File
objectpublic static java.lang.String getString(java.lang.String key)
key
as a String value.key
- The key for the settingkey
or null if it is not foundpublic static java.lang.String getRequiredString(java.lang.String key, java.lang.String message)
key
- The key for the settingmessage
- The error message to throw if the setting doesn't existskey
public static java.lang.String getString(java.lang.String key, java.lang.String defaultValue)
key
as a String value.key
- The key for the settingdefaultValue
- The value to return if the key
is not foundkey
or defaultValue
if it is not found or is emptypublic static int getInt(java.lang.String key)
key
as an integer value.key
- The key for the settingkey
or 0 if it is not found or
is not a numberpublic static int getInt(java.lang.String key, int defaultValue)
key
as an integer value.key
- The key for the settingdefaultValue
- The value to return if the key
is not foundkey
or defaultValue
if it is not foundpublic static long getLong(java.lang.String key, long defaultValue)
key
as a long value.key
- The key for the settingdefaultValue
- The value to return if the key
is not foundkey
or defaultValue
if it is not foundpublic static boolean getBoolean(java.lang.String key)
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.key
- The key for the settingkey
public static java.lang.String getCharset()
defaultCharset
setting and uses ISO-8859-1
if not specified.public static java.util.SortedSet<java.lang.String> getCommonCharsets()
public static java.util.SortedSet<java.lang.String> getAllCharsets()
public static java.util.Locale getLocale()