Eric van der Vlist 6ef9b48568 | ||
---|---|---|
.. | ||
css | ||
icons | ||
resources | ||
schema | ||
src-java/simple/documentation/framework | ||
templates | ||
xsl | ||
README.md | ||
catalog.xml | ||
commons.js | ||
hello.js | ||
js-include.xpr | ||
sdf.framework | ||
sdf.jar | ||
sdf_sample.xml |
README.md
Including scripts within Oxygen JS Operations
Another limitation of the JS operation is that a single "globals.js" file is loaded before the execution of javascript operation.
This rambling proposes a way to include other scripts at runtime.
Installation
To do so, add this function to your commons.js file:
include = function (filepath, isAbsolute) {
if (isAbsolute === undefined || isAbsolute == false) {
filepath = Packages.ro.sync.ecss.extensions.commons.operations.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);
}
}
And use the include() function it in the script parameter of the JS operation:
doOperation = function () {
include('hello.js');
hello();
}
Limitations
The function needs an authorAccess variable in order to resolve relative URIs and this variable is only available in the scope of the doOperation function. This means that you can't use it outside of this function call, like, for instance, in the global scope of the common.js script.
See also
Framework
This directory includes the Oxygen sample framework on which ou can test this technique but it should work on any framework.