From 004754280a9f63a17c648d14455bb41c07d68b4d Mon Sep 17 00:00:00 2001
From: Don Brutzman <brutzman@nps.edu>
Date: Sun, 14 Jun 2020 18:02:01 -0700
Subject: [PATCH] more consistent invocation of saxon, avoiding timing for
 brevity; processScenes.X3dTidy now includes more complete validation to help
 deconflict false positives and incorrect corrections

---
 build.xml | 89 +++++++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 73 insertions(+), 16 deletions(-)

diff --git a/build.xml b/build.xml
index 0539146bed..eadb05570c 100644
--- a/build.xml
+++ b/build.xml
@@ -419,7 +419,7 @@ Key references:
             <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="${fork}">
                 <!-- https://www.saxonica.com/documentation9.5/using-xsl/commandline.html -->
                     <arg value="-warnings:recover"/> <!-- recover after writing a warning message -->
-                    <arg value="-t"/> <!-- saxon version and timing information -->
+                    <!-- <arg value="-t"/> saxon version and timing information -->
                     <arg value="-s:@{scene}.x3d"/>
                     <arg value="-o:@{scene}Tidy.x3d"/>
                     <arg value="-xsl:${stylesheet.dir}/X3dTidy.xslt"/> <!--  regular stylesheet -->
@@ -453,6 +453,10 @@ Key references:
                 <attribute name="http://xml.org/sax/features/namespaces" value="true"/>
                 -->
             </xmlvalidate>
+            <echo message="check schema validation of X3dTidy canonicalized form"/>
+            <schemavalidate file="@{scene}TidyCanonical.xml" failonerror="false" fullchecking="false" lenient="false" warn="true">
+                <xmlcatalog refid="X3dCatalog"/>
+            </schemavalidate>
             <length property="@{scene}.length"          file="@{scene}.x3d"/>
             <length property="@{scene}Tidy.length" file="@{scene}TidyCanonical.xml"/>
             <!-- copy scenes even if length is unchanged since some modifications may have occurred, identical files are recognized as such by subversion -->
@@ -1532,7 +1536,7 @@ ignoreSetupDownloadErrors=true
         <echo message="found ${saxon.dir}/${saxon.jar}: ${saxon.found}"/>
     </target>
 
-    <target name="get.X3DJSAIL.update" description="get latest X3DJSAIL update" >
+    <target name="get.X3DJSAIL.update.online" description="get latest X3DJSAIL update" >
         <echo message="get latest X3DJSAIL update from https://www.web3d.org/specifications/java/X3DJSAIL.html"/>
         <get src="https://www.web3d.org/specifications/java/jars/${jsai.full.archive.jar.name}"
             dest="lib/" verbose="true" ignoreerrors="false"/>
@@ -1540,6 +1544,14 @@ ignoreSetupDownloadErrors=true
         <echo>Download complete, lib/${jsai.full.archive.jar.name} size ${jsai.full.archive.jar.length} bytes</echo>
     </target>
 
+    <target name="get.X3DJSAIL.update.local" description="get latest X3DJSAIL update" >
+        <echo message="get latest X3DJSAIL update from https://www.web3d.org/specifications/java/X3DJSAIL.html"/>
+        <copy file="${x3djsail.stylesheets.dir}/${jsai.full.archive.jar.name}"
+             todir="lib/" verbose="true"/>
+        <length property="jsai.full.archive.jar.length" file="lib/${jsai.full.archive.jar.name}"/>
+        <echo>File copy complete, lib/${jsai.full.archive.jar.name} size ${jsai.full.archive.jar.length} bytes</echo>
+    </target>
+
     <target name="get.slideshowTools" description="retrieve slideshow package"> <!-- unless="${ignoreSetupDownloadErrors}" -->
         <echo message="Retrieve open-source google slideshow package https://code.google.com/archive/p/slideshow"/>
         <property name="mootools.zip" value="Slideshow-1.3.2.110508.zip"/>
@@ -1625,7 +1637,7 @@ ignoreSetupDownloadErrors=true
         <!-- note reordering of parameters for source, output contrary to Saxon documentation! -->
         <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="${fork}">
             <arg value="-warnings:recover"/> <!-- recover after writing a warning message -->
-            <arg value="-t"/> <!-- saxon version and timing information -->
+            <!-- <arg value="-t"/> saxon version and timing information -->
             <arg value="-s:HelloWorld.x3d"/>
             <arg value="-o:HelloWorld.html"/>
             <arg value="-xsl:${stylesheet.dir}/X3dToXhtml.xslt"/>
@@ -1633,7 +1645,7 @@ ignoreSetupDownloadErrors=true
         <echo message="Convert HelloWorld.x3d to HelloWorldX_ITE.html using X3dToX3dom.xslt stylesheet"/>
         <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="${fork}">
             <arg value="-warnings:recover"/> <!-- recover after writing a warning message -->
-            <arg value="-t"/> <!-- saxon version and timing information -->
+            <!-- <arg value="-t"/> saxon version and timing information -->
             <arg value="-s:HelloWorld.x3d"/>
             <arg value="-o:HelloWorldX_ITE.html"/>
             <arg value="-xsl:${stylesheet.dir}/X3dToX3dom.xslt"/>
@@ -1645,7 +1657,7 @@ ignoreSetupDownloadErrors=true
         <echo message="Convert HelloWorld.x3d to HelloWorldX3dom.xhtml using X3dToX3dom.xslt stylesheet"/>
         <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="${fork}">
             <arg value="-warnings:recover"/> <!-- recover after writing a warning message -->
-            <arg value="-t"/> <!-- saxon version and timing information -->
+            <!-- <arg value="-t"/> saxon version and timing information -->
             <arg value="-s:HelloWorld.x3d"/>
             <arg value="-o:HelloWorldX3dom.xhtml"/>
             <arg value="-xsl:${stylesheet.dir}/X3dToX3dom.xslt"/>
@@ -1653,7 +1665,7 @@ ignoreSetupDownloadErrors=true
         <echo message="Convert HelloWorld.x3d to HelloWorld.wrl using X3dToVrml97.xslt stylesheet"/>
         <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="${fork}">
             <arg value="-warnings:recover"/>
-            <arg value="-t"/> <!-- saxon version and timing information -->
+            <!-- <arg value="-t"/> saxon version and timing information -->
             <arg value="-s:HelloWorld.x3d"/>
             <arg value="-o:HelloWorld.wrl"/>
             <arg value="-xsl:${stylesheet.dir}/X3dToVrml97.xslt"/>
@@ -1661,7 +1673,7 @@ ignoreSetupDownloadErrors=true
         <echo message="Convert HelloWorld.x3d to HelloWorld.x3dv using X3dToX3dvClassicVrmlEncoding.xslt stylesheet"/>
         <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="${fork}">
             <arg value="-warnings:recover"/>
-            <arg value="-t"/> <!-- saxon version and timing information -->
+            <!-- <arg value="-t"/> saxon version and timing information -->
             <arg value="-s:HelloWorld.x3d"/>
             <arg value="-o:HelloWorld.x3dv"/>
             <arg value="-xsl:${stylesheet.dir}/X3dToX3dvClassicVrmlEncoding.xslt"/>
@@ -1809,7 +1821,7 @@ ignoreSetupDownloadErrors=true
         <!-- note reordering of parameters for source, output contrary to Saxon documentation! -->
         <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="${fork}">
             <arg value="-warnings:recover"/> <!-- recover after writing a warning message -->
-            <arg value="-t"/> <!-- saxon version and timing information -->
+            <!-- <arg value="-t"/> saxon version and timing information -->
             <arg value="-s:newScene.x3d"/>
             <arg value="-o:newScene.html"/>
             <arg value="-xsl:${stylesheet.dir}/X3dToXhtml.xslt"/>
@@ -1817,7 +1829,7 @@ ignoreSetupDownloadErrors=true
         <echo message="Convert newScene.x3d to newSceneX_ITE.html using X3dToX3dom.xslt stylesheet in X_ITE mode"/>
         <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="${fork}">
             <arg value="-warnings:recover"/> <!-- recover after writing a warning message -->
-            <arg value="-t"/> <!-- saxon version and timing information -->
+            <!-- <arg value="-t"/> saxon version and timing information -->
             <arg value="-s:newScene.x3d"/>
             <arg value="-o:newSceneX_ITE.html"/>
             <arg value="-xsl:${stylesheet.dir}/X3dToX3dom.xslt"/>
@@ -1829,7 +1841,7 @@ ignoreSetupDownloadErrors=true
         <echo message="Convert newScene.x3d to newSceneX3dom.xhtml using X3dToX3dom.xslt stylesheet in default mode"/>
         <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="${fork}">
             <arg value="-warnings:recover"/> <!-- recover after writing a warning message -->
-            <arg value="-t"/> <!-- saxon version and timing information -->
+            <!-- <arg value="-t"/> saxon version and timing information -->
             <arg value="-s:newScene.x3d"/>
             <arg value="-o:newSceneX3dom.xhtml"/>
             <arg value="-xsl:${stylesheet.dir}/X3dToX3dom.xslt"/>
@@ -1837,7 +1849,7 @@ ignoreSetupDownloadErrors=true
         <echo message="Convert newScene.x3d to newScene.wrl using X3dToVrml97.xslt regular stylesheet"/>
         <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="${fork}">
             <arg value="-warnings:recover"/>
-            <arg value="-t"/> <!-- saxon version and timing information -->
+            <!-- <arg value="-t"/> saxon version and timing information -->
             <arg value="-s:newScene.x3d"/>
             <arg value="-o:newScene.wrl"/>
             <arg value="-xsl:${stylesheet.dir}/X3dToVrml97.xslt"/>
@@ -2922,7 +2934,7 @@ ignoreSetupDownloadErrors=true
         </touch>
     </target>
 
-    <target name="processScenes.touch.X3dScenes" description="update timestamp on X3D scenes to allow reshooting images and processing scenes">
+    <target name="processScenes.touch.X3dModels" description="update timestamp on X3D scenes to allow reshooting images and processing scenes">
         <for param="file.path.name">
             <path>
                 <fileset refid="x3dScenes"/>
@@ -3123,7 +3135,7 @@ TODO:  fix Xj3D from launching window, instead perform offline rendering while h
     <target name="processScenes.captureImages"
           description="Utilize Xj3D's Replica class to create thumbnails and viewpoint images for each scene for use as icons, triggered by html timestamp, then updates html">
         <echo message="Utilize Xj3D's Replica class to create thumbnails and viewpoint images for each scene for use as icons, triggered by html timestamp, then updates html"/>
-        <echo message="Optional prerequisite: touch.X3dScenes or clean.htmlPrettyPrintPages prior to reshooting all images"/>
+        <echo message="Optional prerequisite: processScenes.touch.X3dModels or clean.htmlPrettyPrintPages prior to reshooting all images"/>
         <echo message="Rework usually minimized by only regenerating images for each triggering .html change as needed."/>
         <echo message="processScenes.captureImages depends on local Xj3D installation available, current directory xj3d.dir=${xj3d.dir}"/>
         <echo message="   -Djava.library.path=${xj3d.dir.jars}/../${native.library.path}"/>
@@ -3497,7 +3509,7 @@ app.replica.args=-mode scene -mipmaps -antialias 8 -anisotropicDegree 16 -verbos
         <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="false" failonerror="false">
             <arg value="-dtd:off"/> <!-- TODO problem with different relative directories while invoking under jenkins -->
             <arg value="-warnings:recover"/> <!-- recover after writing a warning message -->
-            <arg value="-t"/> <!-- saxon version and timing information -->
+            <!-- <arg value="-t"/> saxon version and timing information -->
             <arg value="-s:ContentCatalog${archive.name}.xml"/>
             <arg value="-xsl:${CreateContentCatalog.dir}/CreateContentCatalogPages.xslt"/>
             <!-- passed parameters, can also be locally set value in CatalogManager.properties -->
@@ -3801,12 +3813,17 @@ app.replica.args=-mode scene -mipmaps -antialias 8 -anisotropicDegree 16 -verbos
                 <!-- no need to keep TIdy examples in archive -->
                 <include name="**/_archive/*Tidy.*"/>
                 <include name="**/_archive/*TidyCanonical.xml"/>
+                <exclude name="**/build.*Tidy*.log"/>
+                <exclude name="**/build.*Tidy*.txt"/>
             </fileset>
         </delete>
     </target>
 
-    <target name="processScenes.X3dTidy" description="Apply x3D-Tidy.xslt to clean up X3D scene errors (when .x3d is more recent than .html)" depends="clean.X3dTidy,clean.duplicates">
-        <echo message="Apply X3D-Tidy.xslt to clean up X3D scene errors (when .x3d is more recent than .html)"/>
+    <target name="processScenes.X3dTidy.all" description="Apply X3dTidy.xslt to clean up X3D scene problems (when .x3d is more recent than .html)"
+         depends="clean.X3dTidy,clean.duplicates,processScenes.touch.X3dModels,processScenes.X3dTidy"/>
+
+    <target name="processScenes.X3dTidy" description="Apply X3dTidy.xslt to clean up X3D scene errors (when .x3d is more recent than .html)" depends="clean.X3dTidy,clean.duplicates">
+        <echo message="Apply X3dTidy.xslt to clean up X3D scene errors (when .x3d is more recent than .html)"/>
         <echo message="Verifying Apache Ant XML Catalog resolver classpath: ${resolver.dir}/resolver.jar (${resolver.jar.length} bytes)"/>
         <for param="file.path.name">
             <path>
@@ -3847,6 +3864,36 @@ app.replica.args=-mode scene -mipmaps -antialias 8 -anisotropicDegree 16 -verbos
                     </sourcefiles>
                     <mapper dir="." type="glob" from="*.x3d" to="*.html"/>
                     <sequential>
+                        <echo message="check well-formedness of original model..."/>
+                        <xmlvalidate file="@{file.path.name}.x3d" failonerror="false" warn="true" lenient="true"/>
+                        <echo message="check DTD validation  of original model..."/>
+                        <xmlvalidate file="@{file.path.name}.x3d" failonerror="false" warn="true">
+                            <xmlcatalog refid="X3dCatalog"/>
+                        </xmlvalidate>
+                        <echo message="check schema validation of original model..."/>
+                        <schemavalidate file="@{file.path.name}.x3d" failonerror="false" fullchecking="false" lenient="false" warn="true">
+                            <xmlcatalog refid="X3dCatalog"/>
+                        </schemavalidate>
+                        <echo message="check schematron validation of original model..."/>
+                        <!-- process individual files here.  show full path to facilitate user loading, editing of reported files -->
+                        <mkdir dir="${archive.path}/${relative.path1}/${relative.path2}/_schematron"/>
+                        <echo>@{file.path.name} validation using X3D Schematron rules</echo>
+                        <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="false">
+                            <arg value="-warnings:recover"/>
+                            <arg value="-s:@{file.path.name}"/>
+                            <arg value="-o:${relative.path1}/${relative.path2}/_schematron/${name.short}.svrl"/> <!-- ${archive.path}/ -->
+                            <arg value="-xsl:${X3dSchematronValidityChecks.dir}/${X3dSchematronValidityChecks}.xslt"/>
+                        </java>
+                        <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="false">
+                            <arg value="-warnings:recover"/>
+                            <arg value="-s:${relative.path1}/${relative.path2}/_schematron/${name.short}.svrl"/>
+                            <arg value="-o:${relative.path1}/${relative.path2}/_schematron/${name.short}.svrl.txt"/> <!-- ${archive.path}/ -->
+                            <arg value="-xsl:${X3dSchematronValidityChecks.dir}/${SvrlReportText}.xslt"/>
+                        </java>
+                        <concat>
+                            <filelist dir="." files="${relative.path1}/${relative.path2}/_schematron/${name.short}.svrl.txt"/>
+                        </concat>
+                        <echo message="next check X3dTidy..."/>
                         <if>
                             <or>
                                 <equals arg1="${name.short}" arg2="QuadTreeExamples"></equals>
@@ -3867,6 +3914,16 @@ app.replica.args=-mode scene -mipmaps -antialias 8 -anisotropicDegree 16 -verbos
                                 <X3dTidy scene="${relative.path1}/${relative.path2}/${name.short}" title="${name.short}"/>
                             </else>
                         </if>
+                        <echo message="check well-formedness of X3dTidy form:"/>
+                        <xmlvalidate file="${relative.path1}/${relative.path2}/${name.short}.x3d" failonerror="false" warn="true" lenient="true"/>
+                        <echo message="check DTD validation  of X3dTidy form"/>
+                        <xmlvalidate file="${relative.path1}/${relative.path2}/${name.short}.x3d" failonerror="false" warn="true">
+                            <xmlcatalog refid="X3dCatalog"/>
+                        </xmlvalidate>
+                        <echo message="check schema validation of X3dTidy form"/>
+                        <schemavalidate file="${relative.path1}/${relative.path2}/${name.short}.x3d" failonerror="false" fullchecking="false" lenient="false" warn="true">
+                            <xmlcatalog refid="X3dCatalog"/>
+                        </schemavalidate>
                     </sequential>
                 </outofdate>
             </sequential>
-- 
GitLab