Simple Variable Language

The org.apache.juneau.svl packages defines an API for a language called Simple Variable Language. In a nutshell, Simple Variable Language (or SVL) is text that contains variables of the form "$varName{varKey}". It is used extensively in the Config, REST and Microservice APIs.

Most variables can be recursively nested within the varKey (e.g. "$FOO{$BAR{xxx},$BAZ{xxx}}") and can return values that themselves contain more variables.

The {@link oaj.svl.VarResolver} class is used to resolve variables. The {@link oaj.svl.VarResolver#DEFAULT} resolver is a reusable instance of this class configured with the following basic variables:

- {@link oaj.svl.vars.SystemPropertiesVar} - $S{key[,default]}
- {@link oaj.svl.vars.EnvVariablesVar} - $E{key[,default]}

The following logic variables are also provided:

- {@link oaj.svl.vars.IfVar} - $IF{arg,then[,else]}
- {@link oaj.svl.vars.SwitchVar} - $SW{arg,pattern1:then1[,pattern2:then2...]}
- {@link oaj.svl.vars.CoalesceVar} - $CO{arg1[,arg2...]}
- {@link oaj.svl.vars.PatternMatchVar} - $PM{arg,pattern}
- {@link oaj.svl.vars.PatternReplaceVar} - $PR{arg,pattern,replace}
- {@link oaj.svl.vars.PatternExtractVar} - $PE{arg,pattern,groupIndex}
- {@link oaj.svl.vars.NotEmptyVar} - $NE{arg}
- {@link oaj.svl.vars.UpperCaseVar} - $UC{arg}
- {@link oaj.svl.vars.LowerCaseVar} - $LC{arg}
- {@link oaj.svl.vars.LenVar} - $LN{arg[,delimiter]}
- {@link oaj.svl.vars.SubstringVar} - $ST{arg,start[,end]}

##### Example:

// Use the default variable resolver to resolve a string that contains $S (system property) variables String myProperty = VarResolver.DEFAULT.resolve("The Java home directory is $S{java.home}");

The following shows how variables can be arbitrarily nested...

// Look up a property in the following order: // 1) MYPROPERTY environment variable. // 2) 'my.property' system property if environment variable not found. // 3) 'not found' string if system property not found. String myproperty = VarResolver.DEFAULT.resolve("$E{MYPROPERTY,$S{my.property,not found}}");