if (supportsCompilable) {
String cacheKey =
getScriptLanguage()+"#"+
scriptFile.getAbsolutePath()+"#"+
scriptFile.lastModified();
CompiledScript compiledScript =
compiledScriptsCache.get(cacheKey);
if (compiledScript==null) {
synchronized (compiledScriptsCache) {
compiledScript =
compiledScriptsCache.get(cacheKey);
if (compiledScript==null) {
// TODO Charset ?
fileReader = new BufferedReader(new FileReader(scriptFile),
(int)scriptFile.length());
compiledScript =
((Compilable) scriptEngine).compile(fileReader);
compiledScriptsCache.put(cacheKey, compiledScript);
}
}
}
return compiledScript.eval(bindings);
} else {
// TODO Charset ?
fileReader = new BufferedReader(new FileReader(scriptFile),
(int)scriptFile.length());
return scriptEngine.eval(fileReader, bindings);
}
} finally {
IOUtils.closeQuietly(fileReader);
}
} else {
throw new ScriptException("Script file '"+scriptFile.getAbsolutePath()+"' does not exist or is unreadable for element:"+getName());
}
} else if (!StringUtils.isEmpty(getScript())){
if (supportsCompilable && !StringUtils.isEmpty(cacheKey)) {
CompiledScript compiledScript =
compiledScriptsCache.get(cacheKey);
if (compiledScript==null) {
synchronized (compiledScriptsCache) {
compiledScript =
compiledScriptsCache.get(cacheKey);
if (compiledScript==null) {
compiledScript =
((Compilable) scriptEngine).compile(getScript());
compiledScriptsCache.put(cacheKey, compiledScript);
}
}
}
return compiledScript.eval(bindings);
} else {
return scriptEngine.eval(getScript(), bindings);
}
} else {
throw new ScriptException("Both script file and script text are empty for element:"+getName());