ramblings/oxygen/js-include
Eric van der Vlist eca267f712 Documentation 2021-04-25 14:17:04 +02:00
..
css Copying... 2021-04-25 12:48:11 +02:00
icons Copying... 2021-04-25 12:48:11 +02:00
resources Copying... 2021-04-25 12:48:11 +02:00
schema Copying... 2021-04-25 12:48:11 +02:00
src-java/simple/documentation/framework Copying... 2021-04-25 12:48:11 +02:00
templates Copying... 2021-04-25 12:48:11 +02:00
xsl Copying... 2021-04-25 12:48:11 +02:00
README.md Documentation 2021-04-25 14:17:04 +02:00
catalog.xml Copying... 2021-04-25 12:48:11 +02:00
commons.js Copying... 2021-04-25 12:48:11 +02:00
hello.js Copying... 2021-04-25 12:48:11 +02:00
js-include.xpr Documentation 2021-04-25 14:17:04 +02:00
sdf.framework Documentation 2021-04-25 14:17:04 +02:00
sdf.jar Copying... 2021-04-25 12:48:11 +02:00
sdf_sample.xml Copying... 2021-04-25 12:48:11 +02:00

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. 

# Framework

This directory includes the Oxygen sample framework on which ou can test the debugger but it should work on any framework.