Class TemplateEngine<C>
- java.lang.Object
-
- org.esa.snap.core.gpf.descriptor.template.TemplateEngine<C>
-
public abstract class TemplateEngine<C> extends Object
A template engine represents an abstraction over concrete scripting engines. The currently supported scripting engines are Apache Velocity and Javascript.
-
-
Field Summary
Fields Modifier and Type Field Description protected TemplateContext<C>
context
protected TemplateContext<C>
lastContext
protected ToolAdapterOperatorDescriptor
operatorDescriptor
-
Constructor Summary
Constructors Modifier Constructor Description protected
TemplateEngine(ToolAdapterOperatorDescriptor descriptor)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static TemplateEngine
createInstance(ToolAdapterOperatorDescriptor descriptor, TemplateType templateType)
Creates an instance of a template engine, of the given type, for the given descriptor.static TemplateEngine
createInstance(ToolAdapterOperatorDescriptor descriptor, TemplateType templateType, boolean stateful)
Creates an instance of a template engine.abstract String
execute(Template template, Map<String,Object> parameters)
Processes the given template.TemplateContext<C>
getContext()
Returns the last execution context.List<String>
getLines(Template template, Map<String,Object> parameters)
Returns the contents of the processed template as a list of strings (lines).Path
getTemplateBasePath()
Returns the absolute path of the template file.abstract TemplateType
getType()
Returns the type of the template.abstract void
parse(Template template)
Parses the given template without processing it.
-
-
-
Field Detail
-
operatorDescriptor
protected ToolAdapterOperatorDescriptor operatorDescriptor
-
context
protected TemplateContext<C> context
-
lastContext
protected TemplateContext<C> lastContext
-
-
Constructor Detail
-
TemplateEngine
protected TemplateEngine(ToolAdapterOperatorDescriptor descriptor)
-
-
Method Detail
-
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
public abstract void parse(Template template) throws TemplateException
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
public abstract TemplateType getType()
Returns the type of the template. Can be either TemplateType.VELOCITY or TemplateType.JAVASCRIPT
-
getContext
public TemplateContext<C> 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 TemplateException
Processes 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 TemplateException
Returns 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
public Path getTemplateBasePath()
Returns the absolute path of the template file.
-
-