[x3d-public] Proceeding with calling javascript in X3DJSAIL jar (but I think weshould do it outside the jar first)

John Carlson yottzumm at gmail.com
Mon Dec 18 02:02:19 PST 2017


I believe everything in the nashorn folder (see zip from prior message), except for examples, should be put in the X3DJSAIL jars.  Please make nashorn a top folder in the jar. Let me know when you have done so, so I can start work.

John
Sent from Mail for Windows 10

From: John Carlson
Sent: Monday, December 18, 2017 4:52 AM
To: x3d-public at web3d.org; Don Brutzman
Subject: Proceeding with calling javascript in X3DJSAIL jar (but I think weshould do it outside the jar first)

1. We need to figure out if load() will work with items inside a jar. If not, we may have to put a lot of stuff in X3DJSAIL.
2. Require() can pull stuff out of the classpath, if programmed right. We should look into making sure we can load items from classpath in jvm-npm.js which implements require().  I may have removed that feature, not sure.  Download a new version with $ npm install jvm-npm –save then copy jvm-npm.js out of node_modules.
3. Ideally, we can remove the script from java/build.xml and call X3DJSAIL directly. See following patch

John

$ svn diff CreateX3dSceneAccessInterfaceJava.xslt
Index: CreateX3dSceneAccessInterfaceJava.xslt
===================================================================
--- CreateX3dSceneAccessInterfaceJava.xslt      (revision 26074)
+++ CreateX3dSceneAccessInterfaceJava.xslt      (working copy)
@@ -3736,7 +3736,7 @@
                        bufferedWriter = Files.newBufferedWriter(intermediateJSFilePath, charset);
                        String tmpStr = "load('nashorn/jvm-npm.js');\nload('nashorn/repeatPolyfill.js');\nvar xmldom = require('nashorn/node_modules/xmldom');\nvar DOMParser = xmldom.DOMParser;\nvar XMLSerializer = new xmldom.XMLSerializer();\nvar DOMImplementation = new xmldom.DOMImplementation();\n";
                        bufferedWriter.write(tmpStr, 0, tmpStr.length());
-                       tmpStr = "var json = "+outputSceneText+";\nvar version = json['X3D']['@version'];\nvar docType = DOMImplementation.createDocumentType('X3D', 'ISO//Web3D//DTD X3D '+version+'//EN', 'http://www.web3d.org/specifications/x3d-'+version+'.dtd', null);\nvar document = DOMImplementation.createDocument(null, 'X3D', docType);\nvar mapToMethod = require('nashorn/node/mapToMethod.js');\n var mapToMethod2 = require('nashorn/node/mapToMethod2.js');\n var fieldTypes = require('nashorn/node/fieldTypes.js');\n load('nashorn/node/X3DJSONLD.js');\n load('nashorn/node/JavaScriptSerializer.js');\n var child = CreateElement('X3D');\n ConvertToX3DOM(json, '', child, 'flipper.json');\n print('Returning with', child);\n var output = new JavaScriptSerializer().serializeToString(json, child, '"+outputFilePath+"', mapToMethod, fieldTypes);\n var FileWriter = Java.type('java.io.FileWriter');\n var fw = new FileWriter('"+fileName+"');\n fw.write(output);\n fw.close();\n";
+                       tmpStr = "var json = "+outputSceneText+";\nvar version = json['X3D']['@version'];\nvar docType = DOMImplementation.createDocumentType('X3D', 'ISO//Web3D//DTD X3D '+version+'//EN', 'http://www.web3d.org/specifications/x3d-'+version+'.dtd', null);\nvar document = DOMImplementation.createDocument(null, 'X3D', docType);\nvar mapToMethod = require('nashorn/node/mapToMethod.js');\n var mapToMethod2 = require('nashorn/node/mapToMethod2.js');\n var fieldTypes = require('nashorn/node/fieldTypes.js');\n load('nashorn/node/X3DJSONLD.js');\n load('nashorn/node/JavaScriptSerializer.js');\n var child = CreateElement('X3D');\n ConvertToX3DOM(json, '', child, 'flipper.json');\n print('Returning with', child);\n var output = new JavaScriptSerializer().serializeToString(json, child, '"+fileName+"', mapToMethod, fieldTypes);\n var FileWriter = Java.type('java.io.FileWriter');\n var fw = new FileWriter('"+fileName+"');\n fw.write(output);\n fw.close();\n";
                        bufferedWriter.write(tmpStr, 0, tmpStr.length());
                        bufferedWriter.close(); // ensure file writing is complete
                 }
@@ -3745,10 +3745,9 @@
                        throw new X3DException("IOException when creating intermediateJSFileName " + intermediateJSFileName +
                                ", unable to save file: " + exception);
                 }
-/*
                 try {
                        ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn");
-                       engine.eval("load('"+intermediateJSFilePath+"');");
+                       engine.eval("load('"+intermediateJSFileName+"');");
                        if (ConfigurationProperties.isDeleteIntermediateFiles()) // clean up when done
                                intermediateJSFilePath.toFile().deleteOnExit();
                                           engine.eval("print('Hello World!');");
@@ -3758,7 +3757,6 @@
                        throw new X3DException(errorNotice + "ScriptException when processing fileName " + intermediateJSFilePath +
                                ", unable to save result: " + exception);
                 }
-*/
                 return outputFilePath.toFile(); // success
        }


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20171218/ffe81fc4/attachment-0001.html>


More information about the x3d-public mailing list