Package org.craftercms.commons.config
Class YamlConfiguration
- java.lang.Object
-
- org.apache.commons.configuration2.event.BaseEventSource
-
- org.apache.commons.configuration2.AbstractConfiguration
-
- org.apache.commons.configuration2.AbstractHierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>
-
- org.apache.commons.configuration2.BaseHierarchicalConfiguration
-
- org.craftercms.commons.config.YamlConfiguration
-
- All Implemented Interfaces:
Cloneable
,org.apache.commons.configuration2.Configuration
,org.apache.commons.configuration2.event.EventSource
,org.apache.commons.configuration2.FileBasedConfiguration
,org.apache.commons.configuration2.HierarchicalConfiguration<org.apache.commons.configuration2.tree.ImmutableNode>
,org.apache.commons.configuration2.ImmutableConfiguration
,org.apache.commons.configuration2.ImmutableHierarchicalConfiguration
,org.apache.commons.configuration2.io.FileBased
,org.apache.commons.configuration2.io.InputStreamSupport
,org.apache.commons.configuration2.sync.SynchronizerSupport
,org.apache.commons.configuration2.tree.InMemoryNodeModelSupport
,org.apache.commons.configuration2.tree.NodeKeyResolver<org.apache.commons.configuration2.tree.ImmutableNode>
,org.apache.commons.configuration2.tree.NodeModelSupport<org.apache.commons.configuration2.tree.ImmutableNode>
public class YamlConfiguration extends org.apache.commons.configuration2.BaseHierarchicalConfiguration implements org.apache.commons.configuration2.FileBasedConfiguration, org.apache.commons.configuration2.io.InputStreamSupport
Implementation of Apache Commons HierarchicalConfiguration that parses a YAML configuration file and loads the configuration in memory for easy access.
Example configuration file:
server: hostname: localhost port: 8080 mimeTypes: - application/pdf - application/msword
How to read and access the configuration
YamlConfiguration config = new YamlConfiguration(); config.read(new FileReader("config.yaml")); String serverHostname = config.getString("server.hostname"); String serverPort = config.getInt("server.port"); String pdfMimeType = config.getString("mimeTypes(0)"); String mswordMimeType = config.getString("mimeTypes(1)");
- Author:
- avasquez
-
-
Field Summary
Fields Modifier and Type Field Description static String
ERROR_KEY_LOAD_ERROR
static String
ERROR_KEY_WRITE_NOT_SUPPORTED
static String
LOG_KEY_YAML_LOADED
-
Constructor Summary
Constructors Constructor Description YamlConfiguration()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
buildConfig(Map<String,Object> yamlObj)
protected void
buildConfigFromCollection(String name, Collection<Object> collection, org.apache.commons.configuration2.tree.ImmutableNode.Builder parent)
protected void
buildConfigFromKeyValuePair(String name, Object value, org.apache.commons.configuration2.tree.ImmutableNode.Builder parent)
protected void
buildConfigFromMap(Map<String,Object> map, org.apache.commons.configuration2.tree.ImmutableNode.Builder parent)
protected void
load(Reader in)
void
read(InputStream in)
void
read(Reader in)
void
write(Writer out)
-
Methods inherited from class org.apache.commons.configuration2.BaseHierarchicalConfiguration
childConfigurationsAt, childConfigurationsAt, cloneNodeModel, configurationAt, configurationAt, configurationsAt, configurationsAt, createSubConfigurationForTrackedNode, getNodeModel, getSubConfigurationNodeSelector, getSubConfigurationParentModel, immutableChildConfigurationsAt, immutableConfigurationAt, immutableConfigurationAt, immutableConfigurationsAt, initSubConfigurationForThisParent, interpolatedConfiguration, subnodeConfigurationChanged, subset
-
Methods inherited from class org.apache.commons.configuration2.AbstractHierarchicalConfiguration
addNodes, addNodesInternal, addPropertyDirect, addPropertyInternal, clearInternal, clearPropertyDirect, clearTree, clearTreeInternal, clone, containsKeyInternal, fetchNodeList, getExpressionEngine, getKeysInternal, getKeysInternal, getMaxIndex, getMaxIndexInternal, getModel, getPropertyInternal, getRootElementName, getRootElementNameInternal, isEmptyInternal, nodeDefined, nodeKey, resolveAddKey, resolveKey, resolveNodeKey, resolveUpdateKey, setExpressionEngine, setPropertyInternal, sizeInternal, toString
-
Methods inherited from class org.apache.commons.configuration2.AbstractConfiguration
addErrorLogListener, addProperty, append, beginRead, beginWrite, clear, clearProperty, cloneInterpolator, containsKey, copy, endRead, endWrite, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getConfigurationDecoder, getConversionHandler, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getInterpolator, getKeys, getKeys, getList, getList, getList, getList, getListDelimiterHandler, getLogger, getLong, getLong, getLong, getProperties, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, getSynchronizer, immutableSubset, initLogger, installInterpolator, interpolate, interpolate, isEmpty, isScalarValue, isThrowExceptionOnMissing, lock, setConfigurationDecoder, setConversionHandler, setDefaultLookups, setInterpolator, setListDelimiterHandler, setLogger, setParentInterpolator, setPrefixLookups, setProperty, setSynchronizer, setThrowExceptionOnMissing, size, unlock
-
Methods inherited from class org.apache.commons.configuration2.event.BaseEventSource
addEventListener, clearErrorListeners, clearEventListeners, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEvents
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.commons.configuration2.Configuration
addProperty, clear, clearProperty, getInterpolator, installInterpolator, setInterpolator, setProperty, subset
-
Methods inherited from interface org.apache.commons.configuration2.ImmutableConfiguration
containsKey, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getDouble, getDouble, getDouble, getDuration, getDuration, getEncodedString, getEncodedString, getEnum, getEnum, getFloat, getFloat, getFloat, getInt, getInt, getInteger, getKeys, getKeys, getList, getList, getList, getList, getLong, getLong, getLong, getProperties, getProperty, getShort, getShort, getShort, getString, getString, getStringArray, immutableSubset, isEmpty, size
-
-
-
-
Field Detail
-
LOG_KEY_YAML_LOADED
public static final String LOG_KEY_YAML_LOADED
- See Also:
- Constant Field Values
-
ERROR_KEY_WRITE_NOT_SUPPORTED
public static final String ERROR_KEY_WRITE_NOT_SUPPORTED
- See Also:
- Constant Field Values
-
ERROR_KEY_LOAD_ERROR
public static final String ERROR_KEY_LOAD_ERROR
- See Also:
- Constant Field Values
-
-
Method Detail
-
read
public void read(Reader in) throws org.apache.commons.configuration2.ex.ConfigurationException, IOException
- Specified by:
read
in interfaceorg.apache.commons.configuration2.io.FileBased
- Throws:
org.apache.commons.configuration2.ex.ConfigurationException
IOException
-
read
public void read(InputStream in) throws org.apache.commons.configuration2.ex.ConfigurationException, IOException
- Specified by:
read
in interfaceorg.apache.commons.configuration2.io.InputStreamSupport
- Throws:
org.apache.commons.configuration2.ex.ConfigurationException
IOException
-
write
public void write(Writer out) throws org.apache.commons.configuration2.ex.ConfigurationException, IOException
- Specified by:
write
in interfaceorg.apache.commons.configuration2.io.FileBased
- Throws:
org.apache.commons.configuration2.ex.ConfigurationException
IOException
-
load
protected void load(Reader in) throws org.apache.commons.configuration2.ex.ConfigurationException
- Throws:
org.apache.commons.configuration2.ex.ConfigurationException
-
buildConfigFromKeyValuePair
protected void buildConfigFromKeyValuePair(String name, Object value, org.apache.commons.configuration2.tree.ImmutableNode.Builder parent)
-
buildConfigFromMap
protected void buildConfigFromMap(Map<String,Object> map, org.apache.commons.configuration2.tree.ImmutableNode.Builder parent)
-
buildConfigFromCollection
protected void buildConfigFromCollection(String name, Collection<Object> collection, org.apache.commons.configuration2.tree.ImmutableNode.Builder parent)
-
-