Class AbstractScriptRunner

java.lang.Object
org.omegat.gui.scripting.runner.AbstractScriptRunner
Direct Known Subclasses:
StandardScriptRunner

public abstract class AbstractScriptRunner extends Object
Abstract base class for script runners.
  • Constructor Details

    • AbstractScriptRunner

      public AbstractScriptRunner()
  • Method Details

    • executeScript

      public String executeScript(String script, ScriptItem item, Map<String,Object> additionalBindings) throws IOException, ScriptException
      Execute a script either in string form or, if script is null, as read from the file associated with the supplied ScriptItem. The engine is resolved via the filename extension associated with item (defaults to ScriptRunner.DEFAULT_SCRIPT).

      This is a convenience method for executeScript(String, ScriptEngine, Map).

      Parameters:
      script - The script in string form. Can be null.
      item - The associated ScriptItem. Must not be null. If script is 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 the item will be included in the bindings as ScriptRunner.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

      public ScriptEngineManager getManager()
    • executeScript

      public Object executeScript(String script, ScriptEngine engine, Map<String,Object> additionalBindings) throws ScriptException
      Execute a script with a given engine and bindings.
      Parameters:
      script - The script in string form
      engine - The engine
      additionalBindings - A map of bindings that will be included along with other bindings
      Returns:
      The evaluation result
      Throws:
      ScriptException - when script engine raises error.
    • getAvailableScriptExtensions

      public List<String> 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 the ScriptEngineManager.
      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

      public static AbstractScriptRunner getActiveRunner()
      Retrieves the active instance of AbstractScriptRunner. If no active runner has been set, this method will initialize a new instance of StandardScriptRunner as 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 AbstractScriptRunner instance. If no instance exists, a new StandardScriptRunner is created and returned. Never returns null.