public class InvokeHelper extends BasicHelper
All the helper parameters are considered to be method parameters.
The method name must be always defined - either using the key
OptionsHashKeys.M/OptionsHashKeys.METHOD or as a default
method name.
The instance specified by key is optional - if
not specified and not a static method invocation, the object at the top of
the context stack is used. The key OptionsHashKeys.CLASS may be used
to invoke a static method of a specific class. By default, the TCCL or the CL
of this helper is used to load the class if needed.
E.g. the following template will invoke
String.replace(CharSequence, CharSequence) method on "foo"
string with paramteres "f" and "b".
{{invoke "f" "b" on="foo" m="replace"}}
In the next example, String.split(String) is invoked, the resulting
array is pushed on the context stack, we iterate over the array and render
values converted to upper case letters.
{{#invoke ":" on="foo:bar" m="split"}}{{#each this}}{{toUpperCase}}{{/each}}{{/invoke}}
It's also possible to invoke a static method:
{{#invoke 'MILLISECONDS' class='java.util.concurrent.TimeUnit' m='valueOf'}}{{invoke 1000L m='toSeconds'}}{{/invoke}}
It might be also useful to access the values of a map with non-string keys:
{{invoke myNonStringKey on=myMap m="get"}}
If no instance is specified and not a static method invocation, the object at the top of the context stack is used:
{{#with item.name}}{{invoke 1 m='substring'}}{{/with}}
| Modifier and Type | Field and Description |
|---|---|
static ConfigurationKey |
METHOD_CACHE_MAX_SIZE_KEY
Limit the size of the cache.
|
HELPER_TAG_TYPESconfiguration| Constructor and Description |
|---|
InvokeHelper() |
InvokeHelper(ClassLoader classLoader) |
InvokeHelper(ClassLoader classLoader,
String defaultMethodName) |
| Modifier and Type | Method and Description |
|---|---|
void |
execute(Options options)
Execute the helper.
|
Set<ConfigurationKey> |
getConfigurationKeys() |
protected Set<String> |
getSupportedHashKeys() |
void |
init()
Can be overridden so that there's no need to call
super.init(Configuration). |
protected int |
numberOfRequiredParameters() |
static InvokeHelper |
of(String defaultMethodName) |
void |
validate(HelperDefinition definition)
Helper should validate the tag definition (e.g. number of parameters)
during compilation and fail fast if necessary.
|
allowedTagTypes, getRequiredHashKeys, numberOfRequiredHashEntriesappend, convertAndAppend, convertValue, isSection, isUnescapeVariable, isVariablecheckNotInitialized, initclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitinitpublic static final ConfigurationKey METHOD_CACHE_MAX_SIZE_KEY
public InvokeHelper()
public InvokeHelper(ClassLoader classLoader)
classLoader - The CL used to load a class for a static method invocationpublic InvokeHelper(ClassLoader classLoader, String defaultMethodName)
classLoader - The CL used to load a class for a static method invocationdefaultMethodName - public static InvokeHelper of(String defaultMethodName)
public void execute(Options options)
Helperpublic void init()
AbstractConfigurationAwaresuper.init(Configuration).init in class AbstractHelperpublic Set<ConfigurationKey> getConfigurationKeys()
protected int numberOfRequiredParameters()
numberOfRequiredParameters in class BasicHelperpublic void validate(HelperDefinition definition)
HelperMustacheException with code
MustacheProblem.COMPILE_HELPER_VALIDATION_FAILURE should be
thrown in case of validation failure occurs.validate in interface Helpervalidate in class BasicHelperprotected Set<String> getSupportedHashKeys()
getSupportedHashKeys in class BasicHelper* to
allow any hash keysCopyright © 2017. All rights reserved.