Class ConfigUtils

java.lang.Object
org.craftercms.commons.config.ConfigUtils

public class ConfigUtils extends Object
Utility methods for Apache Commons based configuration.
Author:
avasquez
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static Boolean
    getBooleanProperty(org.apache.commons.configuration2.Configuration config, String key)
    Returns the specified Boolean property from the configuration
    static Boolean
    getBooleanProperty(org.apache.commons.configuration2.Configuration config, String key, Boolean defaultValue)
    Returns the specified Boolean property from the configuration
    static org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>
    getConfigurationAt(org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode> config, String key)
    Returns the sub-configuration whose root is the specified key.
    static List<org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>>
    getConfigurationsAt(org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode> config, String key)
    Returns the sub-configurations whose root is the specified key.
    static Integer
    getIntegerProperty(org.apache.commons.configuration2.Configuration config, String key)
    Returns the specified Integer property from the configuration
    static Integer
    getIntegerProperty(org.apache.commons.configuration2.Configuration config, String key, Integer defaultValue)
    Returns the specified Integer property from the configuration
    static Long
    getLongProperty(org.apache.commons.configuration2.Configuration config, String key)
    Returns the specified Long property from the configuration
    static Long
    getLongProperty(org.apache.commons.configuration2.Configuration config, String key, Long defaultValue)
    Returns the specified Long property from the configuration
    static Boolean
    getRequiredBooleanProperty(org.apache.commons.configuration2.Configuration config, String key)
    Returns the specified Boolean property from the configuration.
    static org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>
    getRequiredConfigurationAt(org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode> config, String key)
    Returns the sub-configuration whose root is the specified key.
    static List<org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>>
    getRequiredConfigurationsAt(org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode> config, String key)
    Returns the sub-configurations whose root is the specified key.
    static Integer
    getRequiredIntegerProperty(org.apache.commons.configuration2.Configuration config, String key)
    Returns the specified Integer property from the configuration.
    static Long
    getRequiredLongProperty(org.apache.commons.configuration2.Configuration config, String key)
    Returns the specified Long property from the configuration.
    static String[]
    getRequiredStringArrayProperty(org.apache.commons.configuration2.Configuration config, String key)
    Returns the specified String array property from the configuration.
    static String
    getRequiredStringProperty(org.apache.commons.configuration2.Configuration config, String key)
    Returns the specified String property from the configuration.
    static String[]
    getStringArrayProperty(org.apache.commons.configuration2.Configuration config, String key)
    Returns the specified String array property from the configuration.
    static String
    getStringProperty(org.apache.commons.configuration2.Configuration config, String key)
    Returns the specified String property from the configuration
    static String
    getStringProperty(org.apache.commons.configuration2.Configuration config, String key, String defaultValue)
    Returns the specified String property from the configuration
    static org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>
    readXmlConfiguration(InputStream input, char listDelimiter, Map<String,org.apache.commons.configuration2.interpol.Lookup> prefixLookups)
    Reads the XML configuration from the specified input stream, using the DEFAULT_ENCODING.
    static org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>
    readXmlConfiguration(InputStream input, char listDelimiter, Map<String,org.apache.commons.configuration2.interpol.Lookup> prefixLookups, String fileEncoding)
    Reads the XML configuration from the specified input stream, using the given file encoding.
    static org.apache.commons.configuration2.XMLConfiguration
    readXmlConfiguration(org.springframework.core.io.Resource resource, char listDelimiter, Map<String,org.apache.commons.configuration2.interpol.Lookup> prefixLookups)
     
    static org.apache.commons.configuration2.HierarchicalConfiguration<?>
    readYamlConfiguration(Reader reader, Map<String,org.apache.commons.configuration2.interpol.Lookup> prefixLookups)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • ConfigUtils

      protected ConfigUtils()
  • Method Details

    • readXmlConfiguration

      public static org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode> readXmlConfiguration(InputStream input, char listDelimiter, Map<String,org.apache.commons.configuration2.interpol.Lookup> prefixLookups) throws ConfigurationException
      Reads the XML configuration from the specified input stream, using the DEFAULT_ENCODING.
      Parameters:
      input - the input stream from where to read the configuration
      Returns:
      the loaded XML configuration, as a an Apache Commons HierarchicalConfiguration
      Throws:
      ConfigurationException - if an error occurs while reading the configuration
    • readXmlConfiguration

      public static org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode> readXmlConfiguration(InputStream input, char listDelimiter, Map<String,org.apache.commons.configuration2.interpol.Lookup> prefixLookups, String fileEncoding) throws ConfigurationException
      Reads the XML configuration from the specified input stream, using the given file encoding.
      Parameters:
      input - the input stream from where to read the configuration
      fileEncoding - the encoding of the file. If not specified DEFAULT_ENCODING will be used
      Returns:
      the loaded XML configuration, as a an Apache Commons HierarchicalConfiguration
      Throws:
      ConfigurationException - if an error occurs while reading the configuration
    • readXmlConfiguration

      public static org.apache.commons.configuration2.XMLConfiguration readXmlConfiguration(org.springframework.core.io.Resource resource, char listDelimiter, Map<String,org.apache.commons.configuration2.interpol.Lookup> prefixLookups) throws ConfigurationException
      Throws:
      ConfigurationException
    • readYamlConfiguration

      public static org.apache.commons.configuration2.HierarchicalConfiguration<?> readYamlConfiguration(Reader reader, Map<String,org.apache.commons.configuration2.interpol.Lookup> prefixLookups) throws ConfigurationException
      Throws:
      ConfigurationException
    • getStringProperty

      public static String getStringProperty(org.apache.commons.configuration2.Configuration config, String key) throws ConfigurationException
      Returns the specified String property from the configuration
      Parameters:
      config - the configuration
      key - the key of the property
      Returns:
      the String value of the property, or null if not found
      Throws:
      ConfigurationException - if an error occurred
    • getStringProperty

      public static String getStringProperty(org.apache.commons.configuration2.Configuration config, String key, String defaultValue) throws ConfigurationException
      Returns the specified String property from the configuration
      Parameters:
      config - the configuration
      key - the key of the property
      defaultValue - the default value if the property is not found
      Returns:
      the String value of the property, or the default value if not found
      Throws:
      ConfigurationException - if an error occurred
    • getRequiredStringProperty

      public static String getRequiredStringProperty(org.apache.commons.configuration2.Configuration config, String key) throws ConfigurationException
      Returns the specified String property from the configuration. If the property is missing a MissingConfigurationException is thrown.
      Parameters:
      config - the configuration
      key - the key of the property
      Returns:
      the String value of the property
      Throws:
      MissingConfigurationException - if the property is missing from the configuration
      ConfigurationException - if an error occurred
    • getBooleanProperty

      public static Boolean getBooleanProperty(org.apache.commons.configuration2.Configuration config, String key) throws ConfigurationException
      Returns the specified Boolean property from the configuration
      Parameters:
      config - the configuration
      key - the key of the property
      Returns:
      the Boolean value of the property, or null if not found
      Throws:
      ConfigurationException - if an error occurred
    • getBooleanProperty

      public static Boolean getBooleanProperty(org.apache.commons.configuration2.Configuration config, String key, Boolean defaultValue) throws ConfigurationException
      Returns the specified Boolean property from the configuration
      Parameters:
      config - the configuration
      key - the key of the property
      defaultValue - the default value if the property is not found
      Returns:
      the Boolean value of the property, or the default value if not found
      Throws:
      ConfigurationException - if an error occurred
    • getRequiredBooleanProperty

      public static Boolean getRequiredBooleanProperty(org.apache.commons.configuration2.Configuration config, String key) throws ConfigurationException
      Returns the specified Boolean property from the configuration. If the property is missing a MissingConfigurationException is thrown.
      Parameters:
      config - the configuration
      key - the key of the property
      Returns:
      the Boolean value of the property
      Throws:
      MissingConfigurationException - if the property is missing from the configuration
      ConfigurationException - if an error occurred
    • getIntegerProperty

      public static Integer getIntegerProperty(org.apache.commons.configuration2.Configuration config, String key) throws ConfigurationException
      Returns the specified Integer property from the configuration
      Parameters:
      config - the configuration
      key - the key of the property
      Returns:
      the Integer value of the property, or null if not found
      Throws:
      ConfigurationException - if an error occurred
    • getIntegerProperty

      public static Integer getIntegerProperty(org.apache.commons.configuration2.Configuration config, String key, Integer defaultValue) throws ConfigurationException
      Returns the specified Integer property from the configuration
      Parameters:
      config - the configuration
      key - the key of the property
      defaultValue - the default value if the property is not found
      Returns:
      the Integer value of the property, or the default value if not found
      Throws:
      ConfigurationException - if an error occurred
    • getRequiredIntegerProperty

      public static Integer getRequiredIntegerProperty(org.apache.commons.configuration2.Configuration config, String key) throws ConfigurationException
      Returns the specified Integer property from the configuration. If the property is missing a MissingConfigurationException is thrown.
      Parameters:
      config - the configuration
      key - the key of the property
      Returns:
      the Integer value of the property
      Throws:
      MissingConfigurationException - if the property is missing from the configuration
      ConfigurationException - if an error occurred
    • getLongProperty

      public static Long getLongProperty(org.apache.commons.configuration2.Configuration config, String key) throws ConfigurationException
      Returns the specified Long property from the configuration
      Parameters:
      config - the configuration
      key - the key of the property
      Returns:
      the Long value of the property, or null if not found
      Throws:
      ConfigurationException - if an error occurred
    • getLongProperty

      public static Long getLongProperty(org.apache.commons.configuration2.Configuration config, String key, Long defaultValue) throws ConfigurationException
      Returns the specified Long property from the configuration
      Parameters:
      config - the configuration
      key - the key of the property
      defaultValue - the default value if the property is not found
      Returns:
      the Long value of the property, or the default value if not found
      Throws:
      ConfigurationException - if an error occurred
    • getRequiredLongProperty

      public static Long getRequiredLongProperty(org.apache.commons.configuration2.Configuration config, String key) throws ConfigurationException
      Returns the specified Long property from the configuration. If the property is missing a MissingConfigurationException is thrown.
      Parameters:
      config - the configuration
      key - the key of the property
      Returns:
      the Long value of the property
      Throws:
      MissingConfigurationException - if the property is missing from the configuration
      ConfigurationException - if an error occurred
    • getStringArrayProperty

      public static String[] getStringArrayProperty(org.apache.commons.configuration2.Configuration config, String key) throws ConfigurationException
      Returns the specified String array property from the configuration. A String array property is normally specified as a String with values separated by commas in the configuration.
      Parameters:
      config - the configuration
      key - the key of the property
      Returns:
      the String array value of the property, or null if not found
      Throws:
      ConfigurationException - if an error occurred
    • getRequiredStringArrayProperty

      public static String[] getRequiredStringArrayProperty(org.apache.commons.configuration2.Configuration config, String key) throws ConfigurationException
      Returns the specified String array property from the configuration. If the property is missing a MissingConfigurationException is thrown. A String array property is normally specified as a String with values separated by commas in the configuration.
      Parameters:
      config - the configuration
      key - the key of the property
      Returns:
      the String value of the property
      Throws:
      MissingConfigurationException - if the property is missing from the configuration
      ConfigurationException - if an error occurred
    • getConfigurationAt

      public static org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode> getConfigurationAt(org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode> config, String key) throws ConfigurationException
      Returns the sub-configuration whose root is the specified key.
      Parameters:
      config - the main configuration
      key - the sub-configuration key
      Returns:
      the sub-configuration, or null if not found
      Throws:
      ConfigurationException - if an error occurs
    • getRequiredConfigurationAt

      public static org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode> getRequiredConfigurationAt(org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode> config, String key) throws ConfigurationException
      Returns the sub-configuration whose root is the specified key. If it's missing a MissingConfigurationException is thrown.
      Parameters:
      config - the main configuration
      key - the sub-configuration key
      Returns:
      the sub-configuration, or null if not found
      Throws:
      MissingConfigurationException - if the sub-configuration is missing from the configuration
      ConfigurationException - if an error occurs
    • getConfigurationsAt

      public static List<org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>> getConfigurationsAt(org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode> config, String key) throws ConfigurationException
      Returns the sub-configurations whose root is the specified key.
      Parameters:
      config - the main configuration
      key - the sub-configurations key
      Returns:
      the sub-configurations, or null if not found
      Throws:
      ConfigurationException - if an error occurs
    • getRequiredConfigurationsAt

      public static List<org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>> getRequiredConfigurationsAt(org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode> config, String key) throws ConfigurationException
      Returns the sub-configurations whose root is the specified key. If they're missing a MissingConfigurationException is thrown
      Parameters:
      config - the main configuration
      key - the sub-configurations key
      Returns:
      the sub-configurations
      Throws:
      MissingConfigurationException - if the sub-configurations are missing from the configuration
      ConfigurationException - if an error occurs