java.lang.Object
com.github.hypfvieh.config.xml.XmlConfiguration
Slim replacement for commons-configuration2 XMLConfiguration.
This class handles configurations saved as XML. It does not do DTD/XSD validation.
- Seit:
- v1.0.1 - 2018-01-15
- Autor:
- hypfvieh
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungbooleangetBoolean(String _key, boolean _default) Retrieve a configuration value as boolean.doubleRetrieve a configuration value as double.Get file which is used as inputintGet a configuration value as int.Get the delimiting key (default is '/').Get the String value behind the given key.Get the string value behind the given key or return default.
Will first try to pick up key from environment variables (if enabled),
if that fails, config will be used.
If this also fails, default is returned.getStringList(String _key) Returns the results of key as ArrayList.getStringSet(String _key, Class<? extends Set> _setClass) Returns a result as Set of the given Set-Subclass.intkeyCount()Get the amount of nodes in config.voidsave()Save config file.voidsave(BiConsumer<Document, OutputStream> _outputGenerator) Save config usingBiConsumer.voidsetKeyDelimiter(String _keyDelimiter) Set the delimiting key.
If null is given, default ('/') will be used.voidSet string value of given keyvoidSet keys found in map to value found in map.
-
Methodendetails
-
getKeyDelimiter
Get the delimiting key (default is '/').- Gibt zurück:
- current delimiting key
-
setKeyDelimiter
Set the delimiting key.
If null is given, default ('/') will be used.- Parameter:
_keyDelimiter- delimiter to use
-
keyCount
public int keyCount()Get the amount of nodes in config.- Gibt zurück:
- nodes in document
-
getString
Get the String value behind the given key. Shortcut of getString(String, null).- Parameter:
_key- key to look for- Gibt zurück:
- value stored in config or null if value not found
-
getString
Get the string value behind the given key or return default.
Will first try to pick up key from environment variables (if enabled),
if that fails, config will be used.
If this also fails, default is returned.- Parameter:
_key- key to look for_default- default to return if key not found- Gibt zurück:
- value stored in environment/config or default if key not found
-
getInt
Get a configuration value as int. If _key not found, or not an integer, default is returned.- Parameter:
_key- key to read_default- default to return if key not found/invalid- Gibt zurück:
- value as int or default
-
getDouble
Retrieve a configuration value as double. If _key could not be found, or value was not of type 'double', default is returned.- Parameter:
_key- key to read_default- default to return if key not found/invalid- Gibt zurück:
- value as double or default
-
getBoolean
Retrieve a configuration value as boolean. If _key could not be found, default is returned.
All other values will be tried to read as boolean.
Considered true values are:
- 1
- y
- j
- ja
- yes
- true
- enabled
- enable
- active
- Parameter:
_key- key to read_default- default to return if key not found/invalid- Gibt zurück:
- boolean or default value
-
setString
Set string value of given key- Parameter:
_key- key to write_asAttribute- set this as attribute instead of node_value- value to write
-
getStringList
Returns the results of key as ArrayList.- Parameter:
_key- key to read- Gibt zurück:
- never null, maybe empty list
-
getStringSet
Returns a result as Set of the given Set-Subclass. If given Set-Class is null or could not be instantiated, TreeSet is used.- Parameter:
_key- key to read_setClass- Set class to use- Gibt zurück:
- set of string maybe empty
-
setValues
Set keys found in map to value found in map.- Parameter:
_values- values to write_asAttributes- write values as attributes instead of nodes
-
save
Save config file. Will replace input file!- Löst aus:
IOException- if file writing fails
-
save
Save config usingBiConsumer. This allows transforming/formatting of output before it is saved to the configured output stream.- Parameter:
_outputGenerator- lambda to modify output with before writing- Löst aus:
IOException- if writing fails
-
getInputFile
Get file which is used as input- Gibt zurück:
- file, maybe null if input is read from stream
-