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-svlEnvVariablesVar$E{key[,default]}
SystemPropertiesVar$S{key[,default]}
ArgsVar$A{key[,default]}
ManifestFileVar$MF{key[,default]}
IfVar$IF{arg,then[,else]}
SwitchVar$SW{arg,pattern1:then1[,pattern2:then2...]}
CoalesceVar$CO{arg1[,arg2...]}
PatternMatchVar$PM{arg,pattern}
PatternReplaceVar$PR{arg,pattern,replace}
PatternExtractVar$PE{arg,pattern,groupdIndex}
NotEmptyVar$NE{arg}
UpperCaseVar$UC{arg}
LowerCaseVar$LC{arg}
LenVar$LN{arg[,delimiter]}
SubstringVar$ST{arg,start[,end]}
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}