[x3d-public] speaking of saxon: X3D XSLT Java Javascript; running Javascript from within Java

Don Brutzman brutzman at nps.edu
Mon Dec 5 23:03:05 PST 2016


[cc: x3d-public with permission]

interesting, thanks for summary of how you perform .x3d to .json conversions, John.

On 12/1/2016 2:09 AM, yottzumm at gmail.com wrote:
> Here’s how I run Saxon from JavaScript to convert XML to JSON:
>
> 1.        Use the npm module, java, version 0.8.0 on Windows and Mac.
>
> 2.       I have a program, convert.js which converts a list of files from XML to JSON, here https://github.com/coderextreme/X3DJSONLD/blob/master/convert.js
>
> 3.       Convert.js calls allsaxon.js here https://github.com/coderextreme/X3DJSONLD/blob/master/allsaxon.js

in effect this looks like a shell script, reaching out to operating system to invoke & run Java.

> 4.       Allsaxon.js uses the npm module to call RunSaxon.java https://github.com/coderextreme/X3DJSONLD/blob/master/RunSaxon.java
>
> 5.       RunSaxon.java calls the net.sf.saxon.Transform.main() with each file with the stylesheet, https://github.com/coderextreme/X3DJSONLD/blob/master/X3dToJson.xslt (thanks!)

and away you go, using the XSLT stylesheet to transform lots of .x3d into corresponding lots of .json.

> So we could probably implement a JavaScript SAI on top of Java as well.  I am not sure who would use it, maybe Xj3D.

Hmmm, different but also very interesting.

If we had JavaScript functionality runnable with the X3D Java Scene Access Interface (SAI) library, maybe could run a ScriptObject inside an X3DObject scene graph when executing standalone or on a server.

Looks like Xj3D uses Rhino.
http://svn.xj3d.org/xj3d_code/tags/VERSION-2-0-M9/HowToInstall.html

https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino
"Rhino is an open-source implementation of JavaScript written entirely in Java. It is typically embedded into Java applications to provide scripting to end users. It is embedded in J2SE 6 as the default Java scripting engine."

https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Download_Rhino
Rhino 1.7.7.1 release date 2016-02-01

Also found:
"Oracle Nashorn: A Next-Generation JavaScript Engine for the JVM" by Julien Ponge
Originally published in the January/February 2014 issue of Java Magazine.
http://www.oracle.com/technetwork/articles/java/jf14-nashorn-2126515.html

"Until Java SE 7, JDKs shipped with a JavaScript scripting engine based on Mozilla Rhino. Java SE 8 will instead ship with a new engine called Oracle Nashorn, which is based on JSR 292 and invokedynamic. It provides better compliance with the ECMA normalized JavaScript specification and better runtime performance through /invokedynamic/-bound call sites."

Also found it already installed on my system, invoked on command line:  jjs -help

Of course you have shown node.js is an excellent javascript environment  Very powerful.  Learned that nashorn is another standalone javascript engine - commonly available (if not commonly known) wherever Java is installed. A current article:

"Running Node.js on the JVM"
Ian Bull, Aug 9th, 2016
http://eclipsesource.com/blogs/2016/07/20/running-node-js-on-the-jvm/

Anyway, back to running Javascript within Java.  If we can run X3D Java SAI programs on a headless client/server that might also include runnable javascript Script nodes, is that something useful?

Not sure if this is a meaningful path, but it might be.  also might be helpful to a Java-based graphics application that already "runs its own way" but wants to add X3D capabilities.

all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman



More information about the x3d-public mailing list