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)");
| Modifier and Type | Field and Description |
|---|---|
static String |
ERROR_KEY_LOAD_ERROR |
static String |
ERROR_KEY_WRITE_NOT_SUPPORTED |
static String |
LOG_KEY_YAML_LOADED |
| Constructor and Description |
|---|
YamlConfiguration() |
| Modifier and Type | Method and 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) |
childConfigurationsAt, childConfigurationsAt, cloneNodeModel, configurationAt, configurationAt, configurationsAt, configurationsAt, createSubConfigurationForTrackedNode, getNodeModel, getSubConfigurationNodeSelector, getSubConfigurationParentModel, immutableChildConfigurationsAt, immutableConfigurationAt, immutableConfigurationAt, immutableConfigurationsAt, initSubConfigurationForThisParent, interpolatedConfiguration, subnodeConfigurationChanged, subsetaddNodes, 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, sizeInternaladdErrorLogListener, 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, 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, unlockaddEventListener, clearErrorListeners, clearEventListeners, copyEventListeners, createErrorEvent, createEvent, fireError, fireEvent, getEventListenerRegistrations, getEventListeners, isDetailEvents, removeEventListener, setDetailEventsequals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddProperty, clear, clearProperty, getInterpolator, installInterpolator, setInterpolator, setProperty, subsetcontainsKey, get, get, getArray, getArray, getBigDecimal, getBigDecimal, getBigInteger, getBigInteger, getBoolean, getBoolean, getBoolean, getByte, getByte, getByte, getCollection, getCollection, getDouble, getDouble, getDouble, getEncodedString, getEncodedString, 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, sizepublic static final String LOG_KEY_YAML_LOADED
public static final String ERROR_KEY_WRITE_NOT_SUPPORTED
public static final String ERROR_KEY_LOAD_ERROR
public void read(Reader in) throws org.apache.commons.configuration2.ex.ConfigurationException, IOException
read in interface org.apache.commons.configuration2.io.FileBasedorg.apache.commons.configuration2.ex.ConfigurationExceptionIOExceptionpublic void read(InputStream in) throws org.apache.commons.configuration2.ex.ConfigurationException, IOException
read in interface org.apache.commons.configuration2.io.InputStreamSupportorg.apache.commons.configuration2.ex.ConfigurationExceptionIOExceptionpublic void write(Writer out) throws org.apache.commons.configuration2.ex.ConfigurationException, IOException
write in interface org.apache.commons.configuration2.io.FileBasedorg.apache.commons.configuration2.ex.ConfigurationExceptionIOExceptionprotected void load(Reader in) throws org.apache.commons.configuration2.ex.ConfigurationException
org.apache.commons.configuration2.ex.ConfigurationExceptionprotected 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 buildConfigFromCollection(String name, Collection<Object> collection, org.apache.commons.configuration2.tree.ImmutableNode.Builder parent)
Copyright © 2018 CrafterCMS. All rights reserved.