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 Details

  • Constructor Details

  • Method Details

    • createInstance

      public static TemplateEngine createInstance(ToolAdapterOperatorDescriptor descriptor, TemplateType templateType, boolean stateful)
      Creates an instance of a template engine.
      Parameters:
      descriptor - The operator descriptor
      templateType - The template type
      stateful - If true, 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 engine
      templateType - 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 processed
      parameters - 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 processed
      parameters - 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.