Package org.craftercms.commons.config
Class ConfigUtils
java.lang.Object
org.craftercms.commons.config.ConfigUtils
Utility methods for Apache Commons based configuration.
- Author:
- avasquez
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic Boolean
getBooleanProperty
(org.apache.commons.configuration2.Configuration config, String key) Returns the specified Boolean property from the configurationstatic Boolean
getBooleanProperty
(org.apache.commons.configuration2.Configuration config, String key, Boolean defaultValue) Returns the specified Boolean property from the configurationstatic 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 configurationstatic Integer
getIntegerProperty
(org.apache.commons.configuration2.Configuration config, String key, Integer defaultValue) Returns the specified Integer property from the configurationstatic Long
getLongProperty
(org.apache.commons.configuration2.Configuration config, String key) Returns the specified Long property from the configurationstatic Long
getLongProperty
(org.apache.commons.configuration2.Configuration config, String key, Long defaultValue) Returns the specified Long property from the configurationstatic 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 configurationstatic String
getStringProperty
(org.apache.commons.configuration2.Configuration config, String key, String defaultValue) Returns the specified String property from the configurationstatic 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 theDEFAULT_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)
-
Field Details
-
DEFAULT_ENCODING
- See Also:
-
-
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 ConfigurationExceptionReads the XML configuration from the specified input stream, using theDEFAULT_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 ConfigurationExceptionReads the XML configuration from the specified input stream, using the given file encoding.- Parameters:
input
- the input stream from where to read the configurationfileEncoding
- the encoding of the file. If not specifiedDEFAULT_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 configurationkey
- 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 configurationkey
- the key of the propertydefaultValue
- 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 aMissingConfigurationException
is thrown.- Parameters:
config
- the configurationkey
- the key of the property- Returns:
- the String value of the property
- Throws:
MissingConfigurationException
- if the property is missing from the configurationConfigurationException
- 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 configurationkey
- 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 configurationkey
- the key of the propertydefaultValue
- 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 aMissingConfigurationException
is thrown.- Parameters:
config
- the configurationkey
- the key of the property- Returns:
- the Boolean value of the property
- Throws:
MissingConfigurationException
- if the property is missing from the configurationConfigurationException
- 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 configurationkey
- 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 configurationkey
- the key of the propertydefaultValue
- 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 aMissingConfigurationException
is thrown.- Parameters:
config
- the configurationkey
- the key of the property- Returns:
- the Integer value of the property
- Throws:
MissingConfigurationException
- if the property is missing from the configurationConfigurationException
- 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 configurationkey
- 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 configurationkey
- the key of the propertydefaultValue
- 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 aMissingConfigurationException
is thrown.- Parameters:
config
- the configurationkey
- the key of the property- Returns:
- the Long value of the property
- Throws:
MissingConfigurationException
- if the property is missing from the configurationConfigurationException
- 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 configurationkey
- 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 aMissingConfigurationException
is thrown. A String array property is normally specified as a String with values separated by commas in the configuration.- Parameters:
config
- the configurationkey
- the key of the property- Returns:
- the String value of the property
- Throws:
MissingConfigurationException
- if the property is missing from the configurationConfigurationException
- 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 configurationkey
- 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 aMissingConfigurationException
is thrown.- Parameters:
config
- the main configurationkey
- the sub-configuration key- Returns:
- the sub-configuration, or null if not found
- Throws:
MissingConfigurationException
- if the sub-configuration is missing from the configurationConfigurationException
- 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 configurationkey
- 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 aMissingConfigurationException
is thrown- Parameters:
config
- the main configurationkey
- the sub-configurations key- Returns:
- the sub-configurations
- Throws:
MissingConfigurationException
- if the sub-configurations are missing from the configurationConfigurationException
- if an error occurs
-