How to use latest Rhino?

Post here questions and problems related to oXygen frameworks/document types.
msklvsk
Posts: 9
Joined: Wed May 04, 2016 2:53 pm

How to use latest Rhino?

Post 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?
Radu
Posts: 9046
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to use latest Rhino?

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
msklvsk
Posts: 9
Joined: Wed May 04, 2016 2:53 pm

Re: How to use latest Rhino?

Post 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.
Radu
Posts: 9046
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to use latest Rhino?

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
msklvsk
Posts: 9
Joined: Wed May 04, 2016 2:53 pm

Re: How to use latest Rhino?

Post by msklvsk »

Thanks!
Outstanding support.
Radu
Posts: 9046
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to use latest Rhino?

Post 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
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply