public class Settings extends Object
SETTINGS_FILE_PROPERTY
, multiple files can be separated by
File.pathSeparator
, that is ':' on linux and ';' on windows; or if that property is not set, the default
location is DEFAULT_SETTINGS_FILEPATH
.Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_SETTINGS_FILEPATH
The file path to look for settings in, if the system property
SETTINGS_FILE_PROPERTY is not set. |
static String |
SETTINGS_FILE_PROPERTY
This system property specifies alternative position(s) to look for settings files.
|
Constructor and Description |
---|
Settings() |
Modifier and Type | Method and Description |
---|---|
static void |
addDefaultClasspathSettings(String defaultClasspathSettingsPath)
Add the settings file represented by this path to the list of default classpath settings.
|
static String |
get(String key)
Gets a setting.
|
static String[] |
getAll(String key)
Gets a list of settings.
|
static boolean |
getBoolean(String key)
Gets a setting as a boolean.
|
static double |
getDouble(String key)
Gets a setting as a double.
|
static File |
getFile(String key)
Gets a setting as a file.
|
static int |
getInt(String key)
Gets a setting as an int.
|
static long |
getLong(String key)
Gets a setting as a long.
|
static List<File> |
getSettingsFiles()
Return the file these settings are read from.
|
static StringTree<String> |
getTree(String path)
Get a tree view of a part of the settings.
|
static void |
reload()
Reloads the settings.
|
static void |
set(String key,
String... values)
Sets the key to one or more values.
|
public static final String SETTINGS_FILE_PROPERTY
File.pathSeparatorChar
public static final String DEFAULT_SETTINGS_FILEPATH
SETTINGS_FILE_PROPERTY
is not set.public Settings()
public static List<File> getSettingsFiles()
public static String get(String key) throws UnknownID, IOFailure, ArgumentNotValid
First it is checked, if the argument key is set as a System property. If yes, return this value. If no, we continue the search.
Secondly, we check, if the setting is in one of the loaded settings xml files. If the value is there, it is returned. If no, we continue the search.
Finally, we check if the setting is in one of default settings files from classpath. If the value is there, it is returned. Otherwise an UnknownId exception is thrown.
Note: The retrieved value can be the empty string
key
- name of the setting to retrieveArgumentNotValid
- if key is null or the empty stringUnknownID
- if no setting loaded matches keyIOFailure
- if IO Failurepublic static int getInt(String key) throws UnknownID, ArgumentNotValid
key
- name of the setting to retrieveArgumentNotValid
- if key is null, the empty string or key is not parseable as an integerUnknownID
- if no setting loaded matches keypublic static long getLong(String key) throws UnknownID, ArgumentNotValid
key
- name of the setting to retrieveArgumentNotValid
- if key is null, the empty string or key is not parseable as a longUnknownID
- if no setting loaded matches keypublic static double getDouble(String key) throws UnknownID, ArgumentNotValid
key
- name of the setting to retrieveArgumentNotValid
- if key is null, the empty string or key is not parseable as a doubleUnknownID
- if no setting loaded matches keypublic static File getFile(String key)
key
- name of the setting to retrieveArgumentNotValid
- if key is null, the empty stringUnknownID
- if no setting loaded matches kepublic static boolean getBoolean(String key) throws UnknownID, ArgumentNotValid
key
- name of the setting to retrieveArgumentNotValid
- if key is null or the empty stringUnknownID
- if no setting loaded matches keypublic static String[] getAll(String key) throws UnknownID, ArgumentNotValid
Note that the values will not be concatenated, the first place with a match will define the entire list. Furthemore the list cannot be empty.
key
- name of the setting to retrieveArgumentNotValid
- if key is null or the empty stringUnknownID
- if no setting loaded matches keypublic static void set(String key, String... values)
reload()
is
executed.
TODO write these values to its own simpleXml structure, that are not reset during reload.
key
- The settings key to add this under, legal keys are fields in this class.values
- The (ordered) list of values to put under this key.ArgumentNotValid
- if key or values are nullUnknownID
- if the key does not already existpublic static void reload()
set(java.lang.String, java.lang.String...)
The field lastModified
is updated to timestamp of the settings file that has been changed most recently.
IOFailure
- if settings cannot be loadedpublic static void addDefaultClasspathSettings(String defaultClasspathSettingsPath)
defaultClasspathSettingsPath
- the given default classpath setting.public static StringTree<String> getTree(String path)
path
- Dotted path to a unique element in the tree.Copyright © 2005–2015 The Royal Danish Library, the Danish State and University Library, the National Library of France and the Austrian National Library.. All rights reserved.