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
-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.commons.configuration2.BaseHierarchicalConfiguration
org.apache.commons.configuration2.BaseHierarchicalConfiguration.BuilderVisitor -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbuildConfig(Map<String, Object> yamlObj) protected voidbuildConfigFromCollection(String name, Collection<Object> collection, org.apache.commons.configuration2.tree.ImmutableNode.Builder parent) protected voidbuildConfigFromKeyValuePair(String name, Object value, org.apache.commons.configuration2.tree.ImmutableNode.Builder parent) protected voidbuildConfigFromMap(Map<String, Object> map, org.apache.commons.configuration2.tree.ImmutableNode.Builder parent) org.yaml.snakeyaml.LoaderOptionsprotected voidvoidread(InputStream in) voidvoidMethods 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, subsetMethods 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, toStringMethods 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, unlockMethods inherited from class org.apache.commons.configuration2.event.BaseEventSource
addEventListener, clearErrorListeners, clearEventListeners, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEventsMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.commons.configuration2.Configuration
addProperty, clear, clearProperty, getInterpolator, installInterpolator, setInterpolator, setProperty, subsetMethods 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, sizeMethods inherited from interface org.apache.commons.configuration2.sync.SynchronizerSupport
getSynchronizer, lock, setSynchronizer, unlock
-
Field Details
-
LOG_KEY_YAML_LOADED
- See Also:
-
ERROR_KEY_WRITE_NOT_SUPPORTED
- See Also:
-
ERROR_KEY_LOAD_ERROR
- See Also:
-
loaderOptions
protected final org.yaml.snakeyaml.LoaderOptions loaderOptions
-
-
Constructor Details
-
YamlConfiguration
public YamlConfiguration()
-
-
Method Details
-
getLoaderOptions
public org.yaml.snakeyaml.LoaderOptions getLoaderOptions() -
read
public void read(Reader in) throws org.apache.commons.configuration2.ex.ConfigurationException, IOException - Specified by:
readin interfaceorg.apache.commons.configuration2.io.FileBased- Throws:
org.apache.commons.configuration2.ex.ConfigurationExceptionIOException
-
read
public void read(InputStream in) throws org.apache.commons.configuration2.ex.ConfigurationException, IOException - Specified by:
readin interfaceorg.apache.commons.configuration2.io.InputStreamSupport- Throws:
org.apache.commons.configuration2.ex.ConfigurationExceptionIOException
-
write
public void write(Writer out) throws org.apache.commons.configuration2.ex.ConfigurationException, IOException - Specified by:
writein interfaceorg.apache.commons.configuration2.io.FileBased- Throws:
org.apache.commons.configuration2.ex.ConfigurationExceptionIOException
-
load
- Throws:
org.apache.commons.configuration2.ex.ConfigurationException
-
buildConfig
-
buildConfigFromKeyValuePair
-
buildConfigFromMap
-
buildConfigFromCollection
protected void buildConfigFromCollection(String name, Collection<Object> collection, org.apache.commons.configuration2.tree.ImmutableNode.Builder parent)
-