Logic Variables
The dedicated $IF{}/$SW{}/$CO{}/$PM{}/$NE{}/$UC{}/$LC{} variable classes described in earlier
versions of this page (IfVar, SwitchVar, CoalesceVar, PatternMatchVar, NotEmptyVar, UpperCaseVar,
LowerCaseVar) were removed in the 10.0.0 cycle. They were replaced by a unified #{name(args...)}
function-call syntax backed by org.apache.juneau.commons.svl.functions.ConditionalFunctions
(if/switch/coalesce/notEmpty) and org.apache.juneau.commons.svl.functions.StringFunctions
(upper/lower). See Simple Variable Language for the full, current
function catalog and syntax — this page shows the config-file equivalents of the old $IF/$SW/$CO/$PM
examples using the current syntax.
Config files can use the #{...} function-call syntax anywhere a $Var{...} variable is valid, including nested
inside other variables such as $S{...} (system property lookup).
The #{if(cond,then,else)} function can be used for simple if/else logic. Unlike the old $IF{} variable, the
else argument is required (pass an empty string if no "else" value is needed):
# Value set to 'foo' if myBooleanProperty is true, empty otherwise.
key1 = #{if($S{myBooleanProperty}, foo, "")}
# Value set to 'foo' if myBooleanProperty is true, 'bar' if false.
key2 = #{if($S{myBooleanProperty}, foo, bar)}
# Value set to key1 value if myBooleanProperty is true, key2 value if false.
key3 = #{if($S{myBooleanProperty}, $C{key1}, $C{key2})}
The #{switch(...)} function can be used for switch blocks based on pattern matching. Arguments are flat and
comma-delimited: value, pattern1, result1, pattern2, result2, ..., default. Patterns support */? glob
wildcards (matched against the whole value):
# Shell command depends on the OS
shellCommand = #{switch(#{lower($S{os.name})}, *win*, bat, linux, bash, sh)}
The #{coalesce(...)} function can be used for coalescing of values (finding the first non-null/empty match):
# Debug flag can be enabled by system property or environment variable.
debug = #{coalesce($S{debug}, $E{DEBUG}, false)}
The #{match(s,regex)} function is the direct replacement for the old $PM{arg,pattern} pattern-match variable,
returning "true"/"false":
# Debug flag can be enabled by system property or environment variable.
isWindows = #{match(#{lower($S{os.name})}, .*win.*)}
- Simple Variable Language — the canonical reference for the full
#{name(args...)}function catalog (string, type-conversion, arithmetic, boolean, conditional, regex, encoding, date/time, random/UUID, and JSON-navigation functions), plus the$Var{...}syntax these functions compose with.