Package org.omegat.gui.scripting.runner
Class AbstractScriptRunner
java.lang.Object
org.omegat.gui.scripting.runner.AbstractScriptRunner
- Direct Known Subclasses:
StandardScriptRunner
Abstract base class for script runners.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionexecuteScript(String script, ScriptEngine engine, Map<String, Object> additionalBindings) Execute a script with a given engine and bindings.executeScript(String script, ScriptItem item, Map<String, Object> additionalBindings) Execute a script either in string form or, ifscriptis null, as read from the file associated with the suppliedScriptItem.static AbstractScriptRunnerRetrieves the active instance ofAbstractScriptRunner.Retrieves a list of file extensions that are supported by the available script engines.
-
Constructor Details
-
AbstractScriptRunner
public AbstractScriptRunner()
-
-
Method Details
-
executeScript
public String executeScript(String script, ScriptItem item, Map<String, Object> additionalBindings) throws IOException, ScriptExceptionExecute a script either in string form or, ifscriptis null, as read from the file associated with the suppliedScriptItem. The engine is resolved via the filename extension associated withitem(defaults toScriptRunner.DEFAULT_SCRIPT).This is a convenience method for
executeScript(String, ScriptEngine, Map).- Parameters:
script- The script in string form. Can be null.item- The associatedScriptItem. Must not be null. Ifscriptis null, the script content will be read from the associated file. The script engine will be resolved from the filename. The resource bundle associated with theitemwill be included in the bindings asScriptRunner.VAR_RESOURCES.additionalBindings- A map of bindings that will be included along with other bindings- Returns:
- result string.
- Throws:
IOException- when I/O error occurred.ScriptException- when script engine raises error.
-
getManager
-
executeScript
public Object executeScript(String script, ScriptEngine engine, Map<String, Object> additionalBindings) throws ScriptExceptionExecute a script with a given engine and bindings.- Parameters:
script- The script in string formengine- The engineadditionalBindings- A map of bindings that will be included along with other bindings- Returns:
- The evaluation result
- Throws:
ScriptException- when script engine raises error.
-
getAvailableScriptExtensions
Retrieves a list of file extensions that are supported by the available script engines. This method collects all extensions from the script engine factories managed by theScriptEngineManager.- Returns:
- a list of supported script file extensions as strings. The list may be empty if no engines are available or no extensions are defined.
-
getActiveRunner
Retrieves the active instance ofAbstractScriptRunner. If no active runner has been set, this method will initialize a new instance ofStandardScriptRunneras the default active runner.Note: This method returns a shared singleton instance. The returned runner should not be modified or stored beyond its immediate use for script execution.
- Returns:
- the current active
AbstractScriptRunnerinstance. If no instance exists, a newStandardScriptRunneris created and returned. Never returns null.
-