src/main/java/org/folio/rest/service/ScriptEngineService.java
public void registerScript(String extension, String name, String script)
      throws ScriptException, IOException, ScriptEngineUnsupported, NoSuchMethodException, ScriptEngineLoadFailed {
    if (!SCRIPT_ENGINE_TYPES.containsValue(extension)) {
      throw new ScriptEngineUnsupported(extension);
    }

    Optional<ScriptEngine> maybeScriptEngine = Optional.ofNullable(scriptEngines.get(extension));

    if (!maybeScriptEngine.isPresent()) {
      ScriptEngine newEngine = scriptEngineManager.getEngineByExtension(extension);

      if (newEngine == null) {
        throw new ScriptEngineLoadFailed(extension);
      }

      scriptEngines.put(extension, newEngine);

      if (SCRIPT_ENGINE_TYPES.containsValue(extension)) {
        newEngine.eval(loadScript(UTILS_PREFIX + extension));
      }

      maybeScriptEngine = Optional.of(newEngine);
    }

    ScriptEngine scriptEngine = maybeScriptEngine.get();
    String scriptFunctionName = name;
    scriptEngine.eval(
        String.format(loadScript(ENGINE_PREFIX + extension), scriptFunctionName, preprocessScript(script, extension)));
  }
/**
   * Register a script for later execution.
   *
   * @param extension The extension of the language associated with the desired
   *                  engine.
   * @param name      The name of the script function to execute.
   * @param script    The code associated with the given language that will be
   *                  executed when the script engine for the given extension is
   *                  run.
   * @throws ScriptException
   *
   * @throws IOException
   * @throws ScriptEngineUnsupported
   * @throws NoSuchMethodException
   * @throws ScriptEngineLoadFailed
   */
Register a script for later execution.
@param extension The extension of the language associated with the desired
engine.
@param name      The name of the script function to execute.
@param script    The code associated with the given language that will be
executed when the script engine for the given extension is
run.


Register a script for later execution . @param extension The extension of the language associated with the desired engine . @param name The name of the script function to execute . @param script The code associated with the given language that will be executed when the script engine for the given extension is run .
public void registerScript(String extension, String name, String script)
      throws ScriptException, IOException, ScriptEngineUnsupported, NoSuchMethodException, ScriptEngineLoadFailed {
    if (!SCRIPT_ENGINE_TYPES.containsValue(extension)) {
      throw new ScriptEngineUnsupported(extension);
    }
    Optional<ScriptEngine> maybeScriptEngine = Optional.ofNullable(scriptEngines.get(extension));
    if (!maybeScriptEngine.isPresent()) {
      ScriptEngine newEngine = scriptEngineManager.getEngineByExtension(extension);
      if (newEngine == null) {
        throw new ScriptEngineLoadFailed(extension);
      }
      scriptEngines.put(extension, newEngine);
      if (SCRIPT_ENGINE_TYPES.containsValue(extension)) {
        newEngine.eval(loadScript(UTILS_PREFIX + extension));
      }
      maybeScriptEngine = Optional.of(newEngine);
    }
    ScriptEngine scriptEngine = maybeScriptEngine.get();
    String scriptFunctionName = name;
    scriptEngine.eval(
        String.format(loadScript(ENGINE_PREFIX + extension), scriptFunctionName, preprocessScript(script, extension)));
  }
public void registerScript ( String extension , String name , String script ) throws ScriptException , IOException , ScriptEngineUnsupported , NoSuchMethodException , ScriptEngineLoadFailed { if ( ! SCRIPT_ENGINE_TYPES . containsValue ( extension ) ) { throw new ScriptEngineUnsupported ( extension ) ; } Optional < ScriptEngine > maybeScriptEngine = Optional . ofNullable ( scriptEngines . get ( extension ) ) ; if ( ! maybeScriptEngine . isPresent ( ) ) { ScriptEngine newEngine = scriptEngineManager . getEngineByExtension ( extension ) ; if ( newEngine == null ) { throw new ScriptEngineLoadFailed ( extension ) ; } scriptEngines . put ( extension , newEngine ) ; if ( SCRIPT_ENGINE_TYPES . containsValue ( extension ) ) { newEngine . eval ( loadScript ( UTILS_PREFIX + extension ) ) ; } maybeScriptEngine = Optional . of ( newEngine ) ; } ScriptEngine scriptEngine = maybeScriptEngine . get ( ) ; String scriptFunctionName = name ; scriptEngine . eval ( String . format ( loadScript ( ENGINE_PREFIX + extension ) , scriptFunctionName , preprocessScript ( script , extension ) ) ) ; }
Register a script for later execution.
Register a script for later execution .