Simple Variable Language Basics
The org.apache.juneau.svl package 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 VarResolver class is used to resolve variables.
The VarResolver.DEFAULT resolver is a reusable instance of this class configured with the following basic variables:
$S{key[,default]}
$E{key[,default]}
The following logic variables are also provided:
$IF{arg,then[,else]}
$SW{arg,pattern1:then1[,pattern2:then2...]}
$CO{arg1[,arg2...]}
$PM{arg,pattern}
$PR{arg,pattern,replace}
$PE{arg,pattern,groupIndex}
$NE{arg}
$UC{arg}
$LC{arg}
$LN{arg[,delimiter]}
$ST{arg,start[,end]}
Example
// Use the default variable resolver to resolve a string that contains
// $S (system property) variables.
String property = 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 property = VarResolver.DEFAULT.resolve("$E{MYPROPERTY,$S{my.property,not found}}");