Class VarResolverSession
VarResolver with one or more session objects.
Instances of this class are considered light-weight and fast to construct, use, and discard.
This class contains the workhorse code for var resolution.
Instances of this class are created through the VarResolver.createSession() and
VarResolver.createSession(WritableBeanStore) methods.
Notes:
- This class is not guaranteed to be thread safe.
See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionVarResolverSession(VarResolver context, WritableBeanStore beanStore) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionAdds a bean to this session.Compiles the given template string into a reusableVarTemplate.<T> Optional<T>Returns the bean from the registered bean store.protected VarReturns theVarwith the specified name.Resolve all variables in the specified string.String[]Resolves the specified strings in the string array.<T> Tresolve(T o) Convenience method for resolving variables in arbitrary objects.Resolves SVL variables for HTML-doc chrome fields that write raw HTML.Resolves SVL variables for<script>and<style>chrome.resolveSupplier(String input) Returns a session-boundSupplierthat re-resolves the given template against this session each timeSupplier.get()is called.Resolves variables in the specified string and sends the output to the specified writer.toString()
-
Constructor Details
-
VarResolverSession
Constructor.- Parameters:
context- TheVarResolvercontext object that contains theVarsand context objects associated with that resolver.beanStore- The bean store to use for resolving beans needed by vars. Can benull (this session will then have no parent bean store, and only beans explicitly added viabean(Class, Object)will be resolvable).
-
-
Method Details
-
bean
Adds a bean to this session.- Type Parameters:
T- The bean type.- Parameters:
c- The bean type.value- The bean.- Returns:
- This object.
-
getBean
Returns the bean from the registered bean store.- Type Parameters:
T- The value type.- Parameters:
c- The bean type.- Returns:
- The bean.
Nevernull .
-
resolve
Resolve all variables in the specified string.- Parameters:
s- The string to resolve variables in. Can benull (returnsnull ).- Returns:
- The new string with all variables resolved, or the same string if no variables were found.
Returnsnull if the input wasnull .
-
resolveHtmlDoc
Resolves SVL variables for HTML-doc chrome fields that write raw HTML.Literal characters from the template (including tags) pass through unchanged. Each SVL substitution is XML-escaped via
StringUtils.escapeXml(String)before insert, except the HTML-passthrough vars$W,$C, and$RS.Plain
resolve(String)is unchanged. Use this only for HTML-doc chrome (aside, header, footer, nav HTML fragments, head, no-results).- Parameters:
s- The chrome template. Can benull .- Returns:
- The resolved chrome string, or
null if the input wasnull .
-
resolveScriptStyle
Resolves SVL variables for<script>and<style>chrome.Request-derived vars (
$RQ,$RH,$RF,$RP,$RA,$SA,$R) are left unresolved (same as an unknown var). Other vars including$W,$C, and$RSstill resolve.- Parameters:
s- The script or style template. Can benull .- Returns:
- The resolved string, or
null if the input wasnull .
-
compile
Compiles the given template string into a reusableVarTemplate.Equivalent to
this.context.compile(input); provided on the session for symmetry withresolve(String). The returned template is bound to the underlyingVarResolver, not to this session — see theVarTemplateclass javadoc for the compile-binding contract.- Parameters:
input- The template string. May benull.- Returns:
- A new
VarTemplatebound to the underlying resolver.
-
resolveSupplier
Returns a session-boundSupplierthat re-resolves the given template against this session each timeSupplier.get()is called.Unlike
VarResolver.resolveSupplier(String)— which opens a fresh session per.get()and is threadsafe to share — this Supplier captures the existing session and reuses it. It is therefore not threadsafe; it inherits the standard "VarResolverSessionis not guaranteed to be thread safe" contract.Use this variant only when the caller owns the session lifecycle and the perf saving of skipping per-call session construction matters. For shared / cross-thread use cases, prefer
VarResolver.resolveSupplier(String).- Parameters:
input- The template string. May benull.- Returns:
- A
Supplier<String>bound to this session.
-
resolve
Resolves the specified strings in the string array.- Parameters:
in- The string array containing variables to resolve. Must not benull or aNullPointerExceptionis thrown, though individual elements can benull .- Returns:
- An array with resolved strings. Elements are
null where the corresponding input element wasnull .
-
resolve
Convenience method for resolving variables in arbitrary objects.Supports resolving variables in the following object types:
CharSequence- Arrays containing values of type
CharSequence. - Collections containing values of type
CharSequence.
Collection class must have a no-arg constructor. - Maps containing values of type
CharSequence.
Map class must have a no-arg constructor.
- Type Parameters:
T- The value type.- Parameters:
o- The object. Can benull (returnsnull ).- Returns:
- The same object if no resolution was needed, otherwise a new object or data structure if resolution was
needed. Returns
null if the input wasnull .
-
resolveTo
Resolves variables in the specified string and sends the output to the specified writer.More efficient than first parsing to a string and then serializing to the writer since this method doesn't need to construct a large string.
- Parameters:
s- The string to resolve variables in. Can benull , in which case the writer is left unchanged.out- The writer to write to. Must not benull .- Returns:
- The same writer.
- Throws:
IOException- Thrown by underlying stream.
-
properties
-
toString
-
getVar
Returns theVarwith the specified name.- Parameters:
name- The var name (e.g."S" ). Must not benull .- Returns:
- The
Varinstance, ornull if noVar is associated with the specified name.
-