55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
/*
|
|
* Global object.
|
|
*
|
|
* This object can't be initialized when common.js is first read since the authorAccess object isn't available yet.
|
|
*
|
|
* For the same reason, include() and require() *cannot* be called from here.
|
|
*
|
|
*/
|
|
|
|
/*
|
|
* Shortcuts (aka imports)
|
|
*/
|
|
out = Packages.java.lang.System.out;
|
|
CommonsOperationsUtil = Packages.ro.sync.ecss.extensions.commons.operations.CommonsOperationsUtil;
|
|
|
|
/*
|
|
* Function include
|
|
*
|
|
*/
|
|
include = function (filepath) {
|
|
out.println('include("' + filepath + '")');
|
|
filepath = CommonsOperationsUtil.expandAndResolvePath(authorAccess, filepath);
|
|
var text = new java.lang.String(java.nio.file.Files.readAllBytes(java.nio.file.Paths. get (java.net.URI(filepath))));
|
|
text = String(text);
|
|
eval(text);
|
|
}
|
|
|
|
|
|
/*
|
|
* Function require
|
|
*
|
|
*/
|
|
require = function (filepath) {
|
|
out.println('require("' + 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;
|
|
include(filepath);
|
|
require.urisStack.pop();
|
|
}
|
|
} |