45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
/*
|
|
* Global object.
|
|
*
|
|
* This object can't be initialized when common.js is first read since the authorAccess object isn't available yet
|
|
*
|
|
*/
|
|
|
|
/*
|
|
* Shortcuts (aka imports)
|
|
*/
|
|
out = Packages.java.lang.System.out;
|
|
CommonsOperationsUtil = Packages.ro.sync.ecss.extensions.commons.operations.CommonsOperationsUtil;
|
|
|
|
|
|
/*
|
|
* Function require
|
|
*
|
|
*/
|
|
require = function (filepath) {
|
|
|
|
// Check if the object has been initialized
|
|
if (Object.keys(require).length == 0) {
|
|
var currentPath = CommonsOperationsUtil.expandAndResolvePath(authorAccess, 'commons.js');
|
|
require.urisStack =[currentPath];
|
|
require.urisSet = {
|
|
};
|
|
require.urisSet[currentPath] = true;
|
|
}
|
|
|
|
var currentFilePath = require.urisStack[require.urisStack.length - 1];
|
|
var currentURI = new java.net.URI(currentFilePath);
|
|
var targetURI = currentURI.resolve(filepath);
|
|
filepath = targetURI.toString();
|
|
if (require.urisSet[filepath] == undefined) {
|
|
require.urisStack.push(filepath);
|
|
require.urisSet[filepath] = true;
|
|
var uri = new java.net.URI(filepath);
|
|
out.println('Including ' + uri.toString());
|
|
var text = new java.lang.String(java.nio.file.Files.readAllBytes(java.nio.file.Paths. get (targetURI)));
|
|
text = String(text);
|
|
eval(text);
|
|
require.urisStack.pop();
|
|
}
|
|
}
|