return executeScript(script, functionName, scriptContext, args);
}
}
String fileExtension = getFileExtension(filePath);
ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByExtension(fileExtension);
if (engine == null) {
throw new IllegalArgumentException("The script type is not supported for location: " + filePath);
}
if (Debug.verboseOn()) {
Debug.logVerbose("Begin processing script [" + filePath + "] using engine " + engine.getClass().getName(), module);
}
engine.setContext(scriptContext);
URL scriptUrl = FlexibleLocation.resolveLocation(filePath);
FileReader reader = new FileReader(new File(scriptUrl.getFile()));
Object result = engine.eval(reader);
if (UtilValidate.isNotEmpty(functionName)) {
try {
Invocable invocableEngine = (Invocable) engine;
result = invocableEngine.invokeFunction(functionName, args == null ? EMPTY_ARGS : args);
} catch (ClassCastException e) {
throw new ScriptException("Script engine " + engine.getClass().getName() + " does not support function/method invocations");
}
}
return result;
}