Package org.yaml.snakeyaml.env
Class EnvScalarConstructor
- java.lang.Object
-
- org.yaml.snakeyaml.constructor.BaseConstructor
-
- org.yaml.snakeyaml.constructor.SafeConstructor
-
- org.yaml.snakeyaml.constructor.Constructor
-
- org.yaml.snakeyaml.env.EnvScalarConstructor
-
public class EnvScalarConstructor extends Constructor
Construct scalar for format ${VARIABLE} replacing the template with the value from environment. It can also be used to create JavaBeans when the all the arguments are provided.- See Also:
- Variable substitution, Variable substitution
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
EnvScalarConstructor.ConstructEnv
-
Nested classes/interfaces inherited from class org.yaml.snakeyaml.constructor.Constructor
Constructor.ConstructMapping, Constructor.ConstructScalar, Constructor.ConstructSequence, Constructor.ConstructYamlObject
-
Nested classes/interfaces inherited from class org.yaml.snakeyaml.constructor.SafeConstructor
SafeConstructor.ConstructUndefined, SafeConstructor.ConstructYamlBinary, SafeConstructor.ConstructYamlBool, SafeConstructor.ConstructYamlFloat, SafeConstructor.ConstructYamlInt, SafeConstructor.ConstructYamlMap, SafeConstructor.ConstructYamlNull, SafeConstructor.ConstructYamlOmap, SafeConstructor.ConstructYamlPairs, SafeConstructor.ConstructYamlSeq, SafeConstructor.ConstructYamlSet, SafeConstructor.ConstructYamlStr, SafeConstructor.ConstructYamlTimestamp
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.regex.Pattern
ENV_FORMAT
static Tag
ENV_TAG
-
Fields inherited from class org.yaml.snakeyaml.constructor.SafeConstructor
undefinedConstructor
-
Fields inherited from class org.yaml.snakeyaml.constructor.BaseConstructor
composer, loadingConfig, NOT_INSTANTIATED_OBJECT, rootTag, typeDefinitions, typeTags, yamlClassConstructors, yamlConstructors, yamlMultiConstructors
-
-
Constructor Summary
Constructors Constructor Description EnvScalarConstructor()
For simple cases when no JavaBeans are neededEnvScalarConstructor(TypeDescription theRoot, java.util.Collection<TypeDescription> moreTDs, LoaderOptions loadingConfig)
Create EnvScalarConstructor which can create JavaBeans with variable substitution
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
apply(java.lang.String name, java.lang.String separator, java.lang.String value, java.lang.String environment)
Implement the logic for missing and unset variablesjava.lang.String
getEnv(java.lang.String key)
Get value of the environment variable-
Methods inherited from class org.yaml.snakeyaml.constructor.Constructor
getClassForName, getClassForNode
-
Methods inherited from class org.yaml.snakeyaml.constructor.SafeConstructor
constructMapping2ndStep, constructSet2ndStep, createLongOrBigInteger, flattenMapping, flattenMapping, processDuplicateKeys, processDuplicateKeys
-
Methods inherited from class org.yaml.snakeyaml.constructor.BaseConstructor
addTypeDescription, checkData, constructArray, constructArrayStep2, constructDocument, constructMapping, constructObject, constructObjectNoCheck, constructScalar, constructSequence, constructSequenceStep2, constructSet, constructSet, createArray, createDefaultList, createDefaultMap, createDefaultSet, finalizeConstruction, getConstructor, getData, getPropertyUtils, getSingleData, isAllowDuplicateKeys, isEnumCaseSensitive, isExplicitPropertyUtils, isWrappedToRootException, newInstance, newInstance, newInstance, newList, newMap, newSet, postponeMapFilling, postponeSetFilling, setAllowDuplicateKeys, setComposer, setEnumCaseSensitive, setPropertyUtils, setWrappedToRootException
-
-
-
-
Field Detail
-
ENV_TAG
public static final Tag ENV_TAG
-
ENV_FORMAT
public static final java.util.regex.Pattern ENV_FORMAT
-
-
Constructor Detail
-
EnvScalarConstructor
public EnvScalarConstructor()
For simple cases when no JavaBeans are needed
-
EnvScalarConstructor
public EnvScalarConstructor(TypeDescription theRoot, java.util.Collection<TypeDescription> moreTDs, LoaderOptions loadingConfig)
Create EnvScalarConstructor which can create JavaBeans with variable substitution- Parameters:
theRoot
- - the class (usually JavaBean) to be constructedmoreTDs
- - collection of classes used by the root classloadingConfig
- - configuration
-
-
Method Detail
-
apply
public java.lang.String apply(java.lang.String name, java.lang.String separator, java.lang.String value, java.lang.String environment)
Implement the logic for missing and unset variables- Parameters:
name
- - variable name in the templateseparator
- - separator in the template, can be :-, -, :?, ?value
- - default value or the error in the templateenvironment
- - the value from environment for the provided variable- Returns:
- the value to apply in the template
-
getEnv
public java.lang.String getEnv(java.lang.String key)
Get value of the environment variable- Parameters:
key
- - the name of the variable- Returns:
- value or null if not set
-
-