Klasse XmlConfiguration

java.lang.Object
com.github.hypfvieh.config.xml.XmlConfiguration

public class XmlConfiguration extends Object
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
  • Methodendetails

    • getKeyDelimiter

      public String getKeyDelimiter()
      Get the delimiting key (default is '/').
      Gibt zurück:
      current delimiting key
    • setKeyDelimiter

      public void setKeyDelimiter(String _keyDelimiter)
      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

      public String getString(String _key)
      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

      public String getString(String _key, String _default)
      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

      public int getInt(String _key, int _default)
      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

      public double getDouble(String _key, double _default)
      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

      public boolean getBoolean(String _key, boolean _default)
      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
      All other values are considered to be false.
      Parameter:
      _key - key to read
      _default - default to return if key not found/invalid
      Gibt zurück:
      boolean or default value
    • setString

      public void setString(String _key, boolean _asAttribute, String _value)
      Set string value of given key
      Parameter:
      _key - key to write
      _asAttribute - set this as attribute instead of node
      _value - value to write
    • getStringList

      public List<String> getStringList(String _key)
      Returns the results of key as ArrayList.
      Parameter:
      _key - key to read
      Gibt zurück:
      never null, maybe empty list
    • getStringSet

      public Set<String> getStringSet(String _key, Class<? extends Set> _setClass)
      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

      public void setValues(Map<String,String> _values, boolean _asAttributes)
      Set keys found in map to value found in map.
      Parameter:
      _values - values to write
      _asAttributes - write values as attributes instead of nodes
    • save

      public void save() throws IOException
      Save config file. Will replace input file!
      Löst aus:
      IOException - if file writing fails
    • save

      public void save(BiConsumer<Document,OutputStream> _outputGenerator) throws IOException
      Save config using BiConsumer. 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

      public File getInputFile()
      Get file which is used as input
      Gibt zurück:
      file, maybe null if input is read from stream