[x3d-public] Problem with conversions to Java, compiling and running generated Java, www.web3d.org/x3d/stylesheets/java/examples

John Carlson yottzumm at gmail.com
Mon Nov 20 14:08:05 PST 2017


Note the extra CDATA section in the generated Java and in the X3D (generated from second Java) below compared to the original above.  I need the later code in order to generate JSON in a test.  We will progress from here to the proper encoding of an MFString in Java.  X3D attached.  Let me know if we need the CDATA strings or if we are taking them out.

HelloWorldProgram.java

                colorTypeConversionScript.setSourceCode("ecmascript:" + "\n"
                                + "\n"
                                + "function " + inputColorFieldName + " (eventValue)" + " // Example source code" + "\n"
                                + "{" + "\n"
                                + "   " + outputColorsFieldName + " = new MFColor(eventValue); // assigning value sends output event" + "\n"
                                + "// Browser.print('" + inputColorFieldName + "=' + eventValue + ', " + outputColorsFieldName + "=' + " + outputColorsFieldName + " + '\\n');\n"
                                + "}");
===========================================================================================================================
HelloWorldProgramOutput.java
      .addChild(new ScriptObject("colorTypeConversionScript").setSourceCode(
"<![CDATA[" + "\n" +
"\n" +
"\n" +
"ecmascript:" + "\n" +
"\n" +
"function colorInput (eventValue) // Example source code" + "\n" +
"{" + "\n" +
"   colorsOutput = new MFColor(eventValue); // assigning value sends output event" + "\n" +
"// Browser.print('colorInput=' + eventValue + ', colorsOutput=' + colorsOutput + '\\n');" + "\n" +
"}" + "\n" + "]]>"
)
============================================================================================================================
temporaryJsonOutputFilePrettyPrint.intermediate.x3d
            <Script DEF='colorTypeConversionScript'>
                <field name='colorInput' accessType='inputOnly' type='SFColor'/>
                <field name='colorsOutput' accessType='outputOnly' type='MFColor'/>
<![CDATA[
<![CDATA[


ecmascript:

function colorInput (eventValue) // Example source code
{
   colorsOutput = new MFColor(eventValue); // assigning value sends output event
// Browser.print('colorInput=' + eventValue + ', colorsOutput=' + colorsOutput + '\n');
}
]]>
]]>
            </Script>

============================================================================================================================
BUILD ERROR:

test-nashorn:
    [javac] Compiling 2 source files to C:\x3d-code\www.web3d.org\x3d\stylesheets\java\classes
     [java] [Fatal Error] temporaryJsonOutputFilePrettyPrint.intermediate.x3d:117:4: The character sequence "]]>" must not appear in content unless used to mark the end of a CDATA section.
     [java] Exception in thread "main" org.web3d.x3d.sai.X3DException: outputFile not writable: C:\x3d-code\www.web3d.org\x3d\stylesheets\temporaryJsonOutputFile.json, org.xml.sax.SAXParseException; systemId: file:/C:/x3d-code/www.web3d.org/x3d/stylesheets/temporaryJsonOutputFilePrettyPrint.intermediate.x3d; lineNumber: 117; columnNumber: 4; The character sequence "]]>" must not appear in content unless used to mark the end of a CDATA section. exception when transforming and creating fileName temporaryJsonOutputFile.json, unable to save result: org.xml.sax.SAXParseException; systemId: file:/C:/x3d-code/www.web3d.org/x3d/stylesheets/temporaryJsonOutputFilePrettyPrint.intermediate.x3d; lineNumber: 117; columnNumber: 4; The character sequence "]]>" must not appear in content unless used to mark the end of a CDATA section.
     [java]     at org.web3d.x3d.jsail.Core.X3DObject.toFileStylesheetConversion(X3DObject.java:955)
     [java]     at org.web3d.x3d.jsail.Core.X3DObject.toFileStylesheetConversion(X3DObject.java:692)
     [java]     at org.web3d.x3d.jsail.Core.X3DObject.toFileJSON(X3DObject.java:1465)
     [java]     at org.web3d.x3d.jsail.Core.X3DObject.toStringJSON(X3DObject.java:1257)
     [java]     at org.web3d.x3d.jsail.Core.X3DObject.toFileJavaScript(X3DObject.java:1352)
     [java]     at org.web3d.x3d.jsail.Core.X3DObject.handleArguments(X3DObject.java:2045)
     [java]     at HelloWorldProgramOutput.main(HelloWorldProgramOutput.java:400)
     [java] Java Result: 1

Potential patch:
$ svn diff X3dToJava.xslt
Index: X3dToJava.xslt
===================================================================
--- X3dToJava.xslt      (revision 26019)
+++ X3dToJava.xslt      (working copy)
@@ -667,12 +667,12 @@
                                          (string-length(normalize-space(text())) > 0)"><!-- TODO restrict to immediate child? -->
                        <xsl:text>.setSourceCode(</xsl:text>
                        <xsl:text>
</xsl:text>
-                       <xsl:text>"<![CDATA[" + "\n" +</xsl:text>
+                       <xsl:text></xsl:text>
                        <xsl:text>
</xsl:text>
                        <xsl:call-template name="stringify-text-lines">
                          <xsl:with-param name="inputString" select="text()"/><!-- TODO restrict to immediate child? might be an issue if field has contained node content and further CDATA text-->
                        </xsl:call-template>
-                       <xsl:text> + "]]>"</xsl:text><!-- end of CDATA block -->
+                       <xsl:text></xsl:text>
                        <xsl:text>
</xsl:text>
                        <xsl:text>)</xsl:text>
                </xsl:if>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20171120/86392f69/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: temporaryJsonOutputFilePrettyPrint.intermediate.x3d
Type: application/octet-stream
Size: 19965 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20171120/86392f69/attachment-0001.obj>


More information about the x3d-public mailing list