Class TemplateEngine<C>
java.lang.Object
org.esa.snap.core.gpf.descriptor.template.TemplateEngine<C>
A template engine represents an abstraction over concrete scripting engines.
The currently supported scripting engines are Apache Velocity and Javascript.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected TemplateContext<C> protected TemplateContext<C> protected ToolAdapterOperatorDescriptor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic TemplateEnginecreateInstance(ToolAdapterOperatorDescriptor descriptor, TemplateType templateType) Creates an instance of a template engine, of the given type, for the given descriptor.static TemplateEnginecreateInstance(ToolAdapterOperatorDescriptor descriptor, TemplateType templateType, boolean stateful) Creates an instance of a template engine.abstract StringProcesses the given template.Returns the last execution context.Returns the contents of the processed template as a list of strings (lines).Returns the absolute path of the template file.abstract TemplateTypegetType()Returns the type of the template.abstract voidParses the given template without processing it.
-
Field Details
-
operatorDescriptor
-
context
-
lastContext
-
-
Constructor Details
-
TemplateEngine
-
-
Method Details
-
createInstance
public static TemplateEngine createInstance(ToolAdapterOperatorDescriptor descriptor, TemplateType templateType, boolean stateful) Creates an instance of a template engine.- Parameters:
descriptor- The operator descriptortemplateType- The template typestateful- Iftrue, the scripting engine will be singleton-like.- Returns:
- the template engine
-
parse
Parses the given template without processing it. This method should be used for verifying the syntactical correctness of the template.- Parameters:
template- The template to parse- Throws:
TemplateException- in case of an exception during parsing of the template
-
getType
Returns the type of the template. Can be either TemplateType.VELOCITY or TemplateType.JAVASCRIPT -
getContext
Returns the last execution context. The execution context would contain transformed parameter values. -
createInstance
public static TemplateEngine createInstance(ToolAdapterOperatorDescriptor descriptor, TemplateType templateType) Creates an instance of a template engine, of the given type, for the given descriptor.- Parameters:
descriptor- The descriptor for which to create the enginetemplateType- The template type- Returns:
- An instance of a template engine
-
execute
public abstract String execute(Template template, Map<String, Object> parameters) throws TemplateExceptionProcesses the given template.- Parameters:
template- The template to be processedparameters- Parameters to be passed to the template.- Returns:
- If everything ok, the transformed template
- Throws:
TemplateException- in case of an exception during processing of the template
-
getLines
public List<String> getLines(Template template, Map<String, Object> parameters) throws TemplateExceptionReturns the contents of the processed template as a list of strings (lines).- Parameters:
template- The template to be processedparameters- Parameters to be passed to the template engine- Returns:
- A list of strings representing the lines of the processed template
- Throws:
TemplateException- in case of an exception during processing of the template
-
getTemplateBasePath
Returns the absolute path of the template file.
-