Class GroovyEngine

java.lang.Object
org.codelibs.fess.script.AbstractScriptEngine
org.codelibs.fess.script.groovy.GroovyEngine
All Implemented Interfaces:
ScriptEngine

public class GroovyEngine extends AbstractScriptEngine
Groovy script engine implementation that extends AbstractScriptEngine. This class provides support for executing Groovy scripts with parameter binding and DI container integration.

Thread Safety: This class is thread-safe. Each evaluate() call creates a new GroovyShell instance to ensure thread isolation.

Resource Management: GroovyClassLoader instances are properly managed and cleaned up after script evaluation to prevent memory leaks.

  • Constructor Details

    • GroovyEngine

      public GroovyEngine()
      Default constructor for GroovyEngine.
  • Method Details

    • evaluate

      public Object evaluate(String template, Map<String,Object> paramMap)
      Evaluates a Groovy script template with the provided parameters.

      This method creates a new GroovyShell instance for each evaluation to ensure thread safety. The DI container is automatically injected into the binding map as "container" for script access.

      Parameters:
      template - the Groovy script to evaluate (null-safe, returns null if empty)
      paramMap - the parameters to bind to the script (null-safe, treated as empty map if null)
      Returns:
      the result of script evaluation, or null if the template is empty or evaluation fails
      Throws:
      JobProcessingException - if the script explicitly throws this exception (allows scripts to signal job-specific errors that should propagate)
    • getName

      protected String getName()
      Returns the name identifier for this script engine.
      Specified by:
      getName in class AbstractScriptEngine
      Returns:
      "groovy" - the identifier used to register and retrieve this engine
    • getCurrentScheduledJob

      protected org.codelibs.fess.opensearch.config.exentity.ScheduledJob getCurrentScheduledJob()
      Gets the current scheduled job from the thread-local job runtime.
      Returns:
      the scheduled job if available, null otherwise
    • logScriptExecution

      protected void logScriptExecution(String script, String result)
      Logs script execution to the audit log.
      Parameters:
      script - the script content that was executed
      result - the execution result (e.g., "success" or "failure:ExceptionType")