Interface Evaluator

All Known Subinterfaces:
GenerationContext

public interface Evaluator
Evaluator definition for templating engines.
Since:
4.0.17
  • Field Details

    • MATH_CONTEXT_VARIABLE

      static final String MATH_CONTEXT_VARIABLE
      Name of a specific variable holding a mathematical context.
      Since:
      4.1.16
      See Also:
    • GLOBAL_VARIABLE

      static final String GLOBAL_VARIABLE
      Name of specific variable referring to global properties.
      Since:
      4.1.16
      See Also:
    • CLASSLOADER_VARIABLE

      static final String CLASSLOADER_VARIABLE
      Variable name for classloader instance.
      Since:
      4.2.211
      See Also:
    • RESOLUTION_TAGS_VARIABLE

      static final String RESOLUTION_TAGS_VARIABLE
      Variable name for the list of tags (comma separated) to limit the generation to resolutions tagged with one of the specified tags.
      Since:
      5.2.210803
      See Also:
  • Method Details

    • getVariableValue

      Object getVariableValue(String variableName)
      Looks up the value stored for the variable having the given name.
      Parameters:
      variableName - The variable's name.
      Returns:
      The stored value.
      Since:
      4.0.17
    • setVariableValue

      void setVariableValue(String variableName, Object value)
      Stores the given value for the variable with the given name.
      Parameters:
      variableName - The variable's name.
      value - The value to be stored.
      Since:
      4.0.17
    • resolveReference

      Object resolveReference(List<Object> params, Map<String,Object> namedParams) throws Exception
      Resolves a firstspirit reference by the given parameters corresponding to the definition of CMS_REF. If the reference was not resolved, an error message will be logged and an empty result will be returned.
      Parameters:
      params - A list of parameters.
      namedParams - A list of named parameters.
      Returns:
      The referenced element.
      Throws:
      Exception
      Since:
      4.0.17
    • include

      void include(String type, Object toInclude, Map<String,Object> params) throws IOException
      Includes something in the output.
      Parameters:
      type - recognized types are: "file", "url", "jar"
      toInclude - used to determine the source, e.g. treated as file name, File object, ...
      params - recognized parameter keys are: "encoding", "parse", "info"
      Throws:
      IOException - if including the source failed.
      Since:
      4.0.17
    • getAttribute

      Object getAttribute(Object instance, String attributeName) throws Exception
      Reads the value for the named attribute from the given instance.
      Parameters:
      instance - The instance.
      attributeName - The name of the attribute.
      Returns:
      The attribute's value.
      Throws:
      Exception - if accessing the attribute failed for some reason.
      Since:
      4.0.17
    • invokeMethod

      Object invokeMethod(Object instance, String methodName, List<Object> args) throws Exception
      Invokes the named method on the given instance.
      Parameters:
      instance - The instance.
      methodName - The name of the method.
      args - Arguments for the method to be invoked.
      Returns:
      The resulting return value from the method invocation.
      Throws:
      Exception - if invoking the method failed for some reason.
      Since:
      4.0.17
    • print

      void print(Object value) throws IOException
      Print an object instance to the output.
      Parameters:
      value - object
      Throws:
      IOException
      Since:
      4.0.17
    • getContext

      Context getContext()
      Provides the current context object.
      Returns:
      The context.
      Since:
      4.0.17
    • setLocale

      void setLocale(Locale value)
      Defines the locale to be used for further evaluation.
      Parameters:
      value - The locale.
      Since:
      4.2
    • getLocale

      Locale getLocale()
      Provides the currently defined locale.
      Returns:
      The locale.
      Since:
      4.0.17
    • getLocaleKey

      String getLocaleKey()
      A locale key, default value is getLocale().getLanguage().toUpperCase()}.
      Since:
      4.0.17
      See Also:
    • setLocaleKey

      void setLocaleKey(String value)
      Defines the locale key to be used for further evaluation.
      Parameters:
      value - The locale key.
      Since:
      4.2
      See Also:
    • logError

      void logError(String message)
      Logs an error message.
      Parameters:
      message - The error message.
      Since:
      4.0.17
    • logError

      void logError(String message, Throwable throwable)
      Logs an error message and a trace.
      Parameters:
      message - The error message.
      throwable - A throwable.
      Since:
      4.0.17
    • logError

      void logError(int line, int col, String message)
      Logs an error message giving a line and column to locate the cause within the template.
      Parameters:
      line - The line.
      col - The coumn.
      message - The error message.
      Since:
      4.0.17
    • logError

      void logError(int line, int col, String message, Throwable t)
      Logs an error message giving a line and column to locate the cause within the template. Additionally gives a throwable for printing a trace.
      Parameters:
      line - The line.
      col - The coumn.
      message - The error message.
      t - A throwable.
      Since:
      4.0.17
    • logWarning

      void logWarning(String message)
      Logs a warning message.
      Parameters:
      message - The warning message.
      Since:
      4.0.17
    • logInfo

      void logInfo(String message)
      Logs an information message.
      Parameters:
      message - The information message.
      Since:
      4.0.17
    • logDebug

      void logDebug(String message)
      Logs a debug message.
      Parameters:
      message - The debug message.
      Since:
      4.0.17
    • pushContext

      Context pushContext(String name, String info)
      Will push a new context and an info text on the stack
      Parameters:
      name - the name of the new context
      info - the text wich is put on the context stack
      Returns:
      the new top context
      Since:
      4.0.17
      See Also:
    • pushContext

      Context pushContext(String name)
      Will push a new context. See pushContext(Context) for further informations.
      Parameters:
      name - the name of the new context
      Returns:
      the new top context
      Since:
      4.0.17
      See Also:
    • pushContext

      Context pushContext(String name, Object target)
      Will push a new context and set the target object as #this.
      Parameters:
      name - The name of the new context.
      target - The target object the context operates on.
      Returns:
      The new top context.
      Since:
      5.0.100
      See Also:
    • pushContext

      void pushContext(Context context)
      Set a new top context. The implementation will call Context.setParentContext(Context) on the providedcontext object.
      Always use this in a try .. finally block:
       evaluator.pushContext(myContext)  try {      ...  } finally {      evaluator.popContext();  } 
      Parameters:
      context - the new top context, null is not allowed
      Since:
      4.0.17
      See Also:
    • popContext

      Context popContext()
      Provides and pops the current context from this evaluation.
      Returns:
      the actual top context
      Since:
      4.0.17
      See Also:
    • getOut

      Writer getOut()
      Provides a writer to the output.
      Returns:
      A writer.
      Since:
      4.0.17
    • setOut

      void setOut(Writer out)
      Sets the writer for the output.
      Parameters:
      out - A writer.
      Since:
      4.0.17
    • setErrorOut

      void setErrorOut(Writer out)
      Parameters:
      out - A writer.
      Since:
      4.0.17
    • setErrorOut

      void setErrorOut(PrintWriter out)
      Sets the error output writer.
      Parameters:
      out - A writer.
      Since:
      4.0.17
    • print

      void print(Printable template) throws IOException
      Instructs to evaluate and print the given template.
      Parameters:
      template - A template.
      Throws:
      IOException
      Since:
      4.0.17
    • getTemplate

      Printable getTemplate(String type, String name, Map<String,Object> params) throws IOException
      Looks up a variable based on the given type and name and provides a printable template initialized with the given parameters.
      Parameters:
      type - The template type.
      name - The variable name.
      params - The parameters.
      Returns:
      A template or null.
      Throws:
      IOException
      Since:
      4.0.18
    • getStack

      String getStack()
      Provides a textual representation of the current evaluation stack.
      Returns:
      The dumped stack.
      Since:
      4.0.17
    • getTopStackElement

      String getTopStackElement()
      The currently evaluated stack element as string - for debugging.
      Returns:
      The top stack element.
      Since:
      5.0.204
    • setDefaultExpression

      void setDefaultExpression(Object value)
      Sets the default expression to be used for output when some value evaluates to null or undefined.
      Parameters:
      value - The default expression.
      Since:
      4.0.17
    • getDefaultExpression

      Object getDefaultExpression()
      Provides the defined default expression.
      Returns:
      The expression.
      Since:
      4.0.17
    • setMaxStackSize

      void setMaxStackSize(int value)
      Defines the maximum stack size for evaluation.
      Parameters:
      value - The maximum stack size.
      Since:
      4.0.17
    • parse

      TemplateDocument parse(String source)
      Parses the given source text and creates an evaluatable template.
      Parameters:
      source - The source.
      Returns:
      A template.
      Since:
      4.0.17
    • parse

      TemplateDocument parse(Reader source) throws IOException
      Parses the given source and creates an evaluatable template.
      Parameters:
      source - The source.
      Returns:
      A template.
      Throws:
      IOException
      Since:
      4.0.17
    • isDebugging

      boolean isDebugging()
      Indicates, whether this evaluation is operating in debugging mode.
      Returns:
      true, if debugging.
      Since:
      4.0.17