Page 1 of 1

How to use latest Rhino?

Posted: Fri May 06, 2016 6:28 pm
by msklvsk
Oxygen 18.0 uses "Rhino 1.7 release 3 2011 05 09" which is 5 years old and missing all these features&fixes, including ES5 support. What is the best way to run my .js plugin on the latest version of Rhino?

Re: How to use latest Rhino?

Posted: Mon May 09, 2016 10:50 am
by Radu
Hi,

We'll look into updating the Rhino library which comes bundled for Oxygen 18.1.
An Oxygen plugin can also contribute to Oxygen extra JAR libraries:

https://www.oxygenxml.com/doc/versions/ ... lugin.html

with various scopes.
So possibly you could bundle your own "js.jar" with the plugin and refer to it from the plugin.xml like:

Code: Select all

<library name="your_js.jar" scope="globalHighPriority"/>
which might be enough to make your JAR have more high priority than ours.
But I'm not sure if this will work or not, it's possible that the API in the latest js.jar has changed and our Java code needs to be updated in order to be used with the latest library.

Regards,
Radu

Re: How to use latest Rhino?

Posted: Thu May 12, 2016 1:42 pm
by msklvsk
Thanks for the instructions. I've tried to reference new Rhino with scope="globalHighPriority", but Oxygen still used Rhino 1.7.3. Maybe I missed something.
Anyway, I might create a java workspace extension and use whatever scripting engine I want, e.g. Nashorn, which is the successor of Rhino.

Re: How to use latest Rhino?

Posted: Thu May 12, 2016 1:53 pm
by Radu
Hi,

Indeed, you can create your own Java implementation of the Workspace Access plugin extension which delegates to the scripting engine of your choice.
Just to get you started, our implementation looks like this:

Code: Select all

public class WorkspaceAccessOverJSPluginExtension implements WorkspaceAccessPluginExtension{
/**
* Logger for logging.
*/
private static final Logger logger = Logger.getLogger(WorkspaceAccessOverJSPluginExtension.class.getName());

/**
* The JS File
*/
private URL jsFileURL;

/**
* Plugin workspace access.
*/
private StandalonePluginWorkspace pluginWorkspaceAccess;

/**
* Constructor.
* @param jsFileURL URL pointing to the Javascript file.
*/
public WorkspaceAccessOverJSPluginExtension(URL jsFileURL) {
this.jsFileURL = jsFileURL;}

/**
* @see ro.sync.exml.plugin.workspace.WorkspaceAccessPluginExtension#applicationStarted(ro.sync.exml.workspace.api.standalone.StandalonePluginWorkspace)
*/
@Override
public void applicationStarted(final StandalonePluginWorkspace pluginWorkspaceAccess) {
this.pluginWorkspaceAccess = pluginWorkspaceAccess;
callFunction(pluginWorkspaceAccess, "applicationStarted");
}

/**
* Constructor.
*
* @param pluginWorkspaceAccess The plugin workspace access.
* @param functionName The function name
* @return The function return value.
*/
public Object callFunction(StandalonePluginWorkspace pluginWorkspaceAccess, String functionName) {
//Use it
org.mozilla.javascript.Context cx = org.mozilla.javascript.Context.enter();
try{
org.mozilla.javascript.Scriptable globalScope = cx.initStandardObjects();
//EXM-36130 Global field which points to Javascript dir URL.
Object wrappedDispatcher = org.mozilla.javascript.Context.javaToJS(URLUtil.getCanonicalURL(URLUtil.getParentURL(jsFileURL)), globalScope);
org.mozilla.javascript.ScriptableObject.defineProperty(globalScope, "jsDirURL", wrappedDispatcher, org.mozilla.javascript.ScriptableObject.CONST);

// Now evaluate the string we've collected. We'll ignore the result.
cx.evaluateString(globalScope, IOUtil.readURL(jsFileURL, "UTF8").toString(), jsFileURL.toString(), 1, null);

Object fObj = globalScope.get(functionName, globalScope);
org.mozilla.javascript.Function f = (org.mozilla.javascript.Function)fObj;
return f.call(cx, globalScope, globalScope, new Object[]{pluginWorkspaceAccess});
} catch(Exception ex){
logger.error(ex, ex);
pluginWorkspaceAccess.showErrorMessage(ex.getMessage());
} finally{
org.mozilla.javascript.Context.exit();
}
return null;
}

/**
* @see ro.sync.exml.plugin.workspace.WorkspaceAccessPluginExtension#applicationClosing()
*/
@Override
public boolean applicationClosing() {
Object ret = callFunction(pluginWorkspaceAccess, "applicationClosing");
if(ret instanceof Boolean){
return (Boolean) ret;
}
//Alow close operation to continue
return true;
}
}
Regards,
Radu

Re: How to use latest Rhino?

Posted: Thu May 12, 2016 4:17 pm
by msklvsk
Thanks!
Outstanding support.

Re: How to use latest Rhino?

Posted: Fri Oct 28, 2016 11:33 am
by Radu
Hi,

We released Oxygen 18.1 a couple of weeks ago and we updated in it the Rhyno library to version 1.7.7.1.

Regards,
Radu