Package org.codelibs.fess.script.groovy
Class GroovyEngine
java.lang.Object
org.codelibs.fess.script.AbstractScriptEngine
org.codelibs.fess.script.groovy.GroovyEngine
- All Implemented Interfaces:
ScriptEngine
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionEvaluates a Groovy script template with the provided parameters.protected org.codelibs.fess.opensearch.config.exentity.ScheduledJobGets the current scheduled job from the thread-local job runtime.protected StringgetName()Returns the name identifier for this script engine.protected voidlogScriptExecution(String script, String result) Logs script execution to the audit log.Methods inherited from class org.codelibs.fess.script.AbstractScriptEngine
register
-
Constructor Details
-
GroovyEngine
public GroovyEngine()Default constructor for GroovyEngine.
-
-
Method Details
-
evaluate
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
Returns the name identifier for this script engine.- Specified by:
getNamein classAbstractScriptEngine- 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
Logs script execution to the audit log.- Parameters:
script- the script content that was executedresult- the execution result (e.g., "success" or "failure:ExceptionType")
-