Skip to main content

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:

Var - Superclass of all vars.SimpleVar - Superclass of all vars that return strings.DefaultingVar - Variables that define a default value if the resolve method returns null.MapVar - Variables that pull values from maps.MultipartVar - Variables that consist of 2 or more comma-delimited arguments.StreamedVar - Superclass of all vars that stream their value to writers.

The following is the list of default variables defined in all modules:

ModuleClassPattern
juneau-svlPropertyVar$P{key[,default]}
juneau-svlEnvVariablesVar$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-configConfigVar$C{key[,default]}
juneau-rest-serverFileVar$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.

See also​