SVL Variables
Variables are defined through the Var API. The API comes with several predefined variables and is easily extensible.
The following is an example of a variable that performs URL-Encoding on strings.
// First create our var.
public class UrlEncodeVar extends SimpleVar {
// Must have a no-arg constructor!
public UrlEncodeVar() {
super("UE");
}
// The method we must implement
@Override
public String resolve(VarResolverSession session, String key) {
return URLEncoder.encode(key, "UTF-8");
}
}
// Next create a var resolver that extends the existing DEFAULT resolver
// that supports resolving system properties.
VarResolver varResolver = VarResolver.DEFAULT
.copy()
.vars(UrlEncodeVar.class)
.build();
// Retrieve a system property and URL-encode it if necessary.
String myProperty = varResolver.resolve("$UE{$S{my.property}}");
The following shows the class hierarchy of the Var class:
The following is the list of default variables defined in all modules:
| Module | Class | Pattern |
|---|---|---|
| juneau-svl | PropertyVar | $P{key[,default]} |
| juneau-svl | EnvVariablesVar | $E{key[,default]} |
| SystemPropertiesVar | $S{key[,default]} | |
| EnvFileVar | $EF{key[,default]} | |
| DotenvVar | $DE{key[,default]} | |
| ArgsVar | $A{key[,default]} | |
| ManifestFileVar | $MF{key[,default]} | |
| HtmlWidgetVar | $W{name} | |
| juneau-config | ConfigVar | $C{key[,default]} |
| juneau-rest-server | FileVar | $F{path[,default]} |
| ServletInitParamVar | $I{name[,default]} | |
| LocalizationVar | $L{key[,args...]} | |
| RequestAttributeVar | $RA{key1[,key2...]} | |
| RequestFormDataVar | $RF{key1[,key2...]} | |
| RequestHeaderVar | $RH{key1[,key2...]} | |
| RequestPathVar | $RP{key1[,key2...]} | |
| RequestQueryVar | $RQ{key1[,key2...]} | |
| RequestSwaggerVar | $RS{key} | |
| RequestVar | $R{key1[,key2...]} | |
| SerializedRequestAttrVar | $SA{contentType,key[,default]} | |
| SwaggerVar | $SS{key1[,key2...]} | |
| UrlVar | $U{uri} | |
| UrlEncodeVar | $UE{uriPart} |
$P{...} is the unified property-stack resolver. It walks the configured Settings property source precedence
(local overrides, global overrides, args, system properties, environment, .env, and any custom sources). Use
$S{...} / $E{...} / $EF{...} / $DE{...} / $A{...} / $MF{...} / $C{...} when you need a source-specific lookup.