public abstract class Var extends Object
Vars are used to convert simple variables of the form VarResolver
class.
Subclasses must implement one of the following two methods:
resolve(VarResolverSession,String)
- For simple vars.
resolveTo(VarResolverSession,Writer,String)
- For streamed vars.
Subclasses MUST implement a no-arg constructor so that class names can be passed to the
VarResolverBuilder.vars(Class...)
method.
They must also be thread safe!
Two direct abstract subclasses are provided to differentiated between simple and streamed vars:
Constructor and Description |
---|
Var(String name,
boolean streamed)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
protected boolean |
allowNested()
Returns whether nested variables are supported by this variable.
|
protected boolean |
allowRecurse()
Returns whether variables in the resolved contents of this variable should also be resolved.
|
protected String |
doResolve(VarResolverSession session,
String arg)
The method called from
VarResolver . |
protected String |
getName()
Return the name of this variable.
|
abstract String |
resolve(VarResolverSession session,
String arg)
The interface that needs to be implemented for subclasses of
SimpleVar . |
abstract void |
resolveTo(VarResolverSession session,
Writer w,
String arg)
The interface that needs to be implemented for subclasses of
StreamedVar . |
public Var(String name, boolean streamed)
name
- The name of this variable.streamed
- Whether this variable is 'streamed', meaning the resolveTo(VarResolverSession, Writer, String)
method
is implemented.
If resolve(VarResolverSession, String)
method is implemented.protected String getName()
For example, the system property variable returns
protected boolean allowNested()
For example, in
The default implementation of this method always returns
protected boolean allowRecurse()
For example, if
The default implementation of this method always returns
Subclasses can override this method to override the default behavior.
As a general rule, variables that resolve user-entered data should not be recursively resolved as this may cause a security hole.
protected String doResolve(VarResolverSession session, String arg) throws Exception
VarResolver
.
Can be overridden to intercept the request and do special handling.
Default implementation simply calls resolve(String).
session
- The session object used for a single instance of a string resolution.arg
- The inside argument of the variable.Exception
- Any thrown exception will be serialized as public abstract String resolve(VarResolverSession session, String arg) throws Exception
SimpleVar
.session
- The session object used for a single instance of a var resolution.arg
- The inside argument of the variable.Exception
- Any thrown exception will be serialized as public abstract void resolveTo(VarResolverSession session, Writer w, String arg) throws Exception
StreamedVar
.session
- The session object used for a single instance of a var resolution.w
- The writer to send the resolved value to.arg
- The inside argument of the variable.Exception
- Any thrown exception will be serialized as Copyright © 2018 Apache. All rights reserved.