new QName(MODULE_NAMESPACE, "path")).getText();
script = new JavaScriptScript(name);
Reader reader;
final String fileName;
ScriptCachingContext sctx;
if (isCustom) {
String filteredPath = filterPath(path);
fileName = modulesDir + File.separator + module.getName() +
File.separator + filterPath(path);
reader = new FileReader(fileName);
int endIndex = filteredPath.lastIndexOf(File.separator);
sctx = new ScriptCachingContext(
String.valueOf(MultitenantConstants.SUPER_TENANT_ID),
'<' + module.getName() + '>',
filteredPath.substring(0, endIndex),
filteredPath.substring(endIndex));
} else {
reader = new InputStreamReader(ModuleManager.class.getClassLoader().getResourceAsStream(path));
fileName = modulesDir + File.separator + name;
int endIndex = path.lastIndexOf('/');
sctx = new ScriptCachingContext(
String.valueOf(MultitenantConstants.SUPER_TENANT_ID),
"<<" + name + ">>",
'/' + path.substring(0, endIndex),
path.substring(endIndex));
}
CacheManager cacheManager = new CacheManager(null);
sctx.setSecurityDomain(new RhinoSecurityDomain() {
@Override
public CodeSource getCodeSource() throws ScriptException {
try {
URL url = new File(fileName).getCanonicalFile().toURI().toURL();
return new CodeSource(url, (Certificate[]) null);
} catch (MalformedURLException e) {
throw new ScriptException(e);
} catch (IOException e) {
throw new ScriptException(e);
}
}
});
sctx.setSourceModifiedTime(1);
Script cachedScript = cacheManager.getScriptObject(reader, sctx);
if (cachedScript == null) {
cacheManager.cacheScript(reader, sctx);
cachedScript = cacheManager.getScriptObject(reader, sctx);