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 | EnvVariablesVar | $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-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} |