<?xml version="1.0" encoding="UTF-8"?>
<!--
  Copyright (c) 1995-2010 held by the author(s).  All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

    * Redistributions of source code must retain the above copyright
      notice, this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright
      notice, this list of conditions and the following disclaimer
      in the documentation and/or other materials provided with the
      distribution.
    * Neither the names of the Naval Postgraduate School (NPS)
      Modeling Virtual Environments and Simulation (MOVES) Institute
      (http://www.nps.edu and http://www.MovesInstitute.org)
      nor the names of its contributors may be used to endorse or
      promote products derived from this software without specific
      prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
-->

<!-- buildExamplesTemplate.xml is used to produce customized build.xml for each autogenerated X3D example archive build.xml -->

<project name="X3D examples: _archiveName_" default="all" basedir=".">
    <description>Builds and tests the X3D Examples _archiveName_ archive using Ant</description>

    <!-- properties common to all build files, customized for this archive ============================== -->

    <property name="archive.name"                  value="_archiveName_"/>
    <property name="archive.path"                  location="."/>

    <!-- Basic archive has single-section catalog structure, others have 2-section catalog structure  -->
    <property name="numberOfSections"             location="_numberOfSections_"/>
    <property name="subdir"                       location="_subdir_"/>

    <fileset id="x3dScenes" dir="." includes="_x3dScenes_" excludes="_archive/*.*,**/_archive/*.*,_schematron/*.*,**/_schematron/*.*,hide/*.*,**/hide/*.*,InstallingCortonaBrowserAsPowerpointControl_files/*.*,**/build.xml,nbproject/**/*.xml,configuration/**/*.*,**/*Canonical.xml"/>
    <fileset id="xmlFiles"  dir="." includes="_xmlFiles_"  excludes="_archive/*.*,**/_archive/*.*,_schematron/*.*,**/_schematron/*.*,hide/*.*,**/hide/*.*,InstallingCortonaBrowserAsPowerpointControl_files/*.*,**/build.xml,nbproject/**/*.xml,configuration/**/*.*,**/*Canonical.xml"/>

    <!-- properties common to all build files and archives ======================================== -->

    <property environment="env"/>

    <!-- note that Netbeans default path is built in and has to be overridden by going to     -->
    <!-- Netbeans > Tools > Options > Miscellaneous > Ant                                     -->
    <!-- and then pointing to C:\apache-ant-1.8.0 (or somesuch locally installed directory)   -->

    <!-- ANT Contrib archive at http://sourceforge.net/projects/ant-contrib/files    (v1.03b) -->
    <!-- must have ant-contrib-1.03b.jar in ANT_HOME/lib (or else specify path)               -->
    <taskdef resource="net/sf/antcontrib/antlib.xml"/>

    <property name="saxon.dir"        location="C:/java/saxonb9-1-0-6j"/>
    <property name="saxon.jar"           value="saxon9.jar"/>
    <property name="saxononicaSA.dir" location="C:/java/saxonsa9-1-0-6j"/>

    <property name="c14n.dir"            value="../../../tools/canonical/dist/lib"/>
    <property name="c14n.jar"            value="X3dC14n.jar"/>
    <property name="log4j.jar"           value="log4j-1.2.15.jar"/>

    <property name="stylesheet.dir"      value="../../../stylesheets"/>

    <property name="xj3d.dir"            value="C:\auv\AuvWorkbench\lib\xj3d"/>
    <property name="xj3d.jar"            value="xj3d-2.0-nps.jar"/>
    <property name="xj3d.cadfilter.jar"  value="xj3d.cadfilter_2.0.0-nps.jar"/>

    <!-- OASIS XML Catalog standard references
         http://www.oasis-open.org/specs/index.php#xmlcatalogs
         http://www.oasis-open.org/committees/download.php/14810/xml-catalogs.pdf -->
    <xmlcatalog id="X3dCatalog">
        <dtd    publicId="ISO//Web3D//DTD X3D 3.0//EN"                                  location="../../../../specifications/x3d-3.0.dtd"/>
        <dtd    publicId="ISO//Web3D//DTD X3D 3.1//EN"                                  location="../../../../specifications/x3d-3.1.dtd"/>
        <dtd    publicId="ISO//Web3D//DTD X3D 3.2//EN"                                  location="../../../../specifications/x3d-3.2.dtd"/>
        <dtd    publicId="http://www.web3d.org/specifications/x3d-3.0.dtd"              location="../../../../specifications/x3d-3.0.dtd"/>
        <dtd    publicId="http://www.web3d.org/specifications/x3d-3.1.dtd"              location="../../../../specifications/x3d-3.1.dtd"/>
        <dtd    publicId="http://www.web3d.org/specifications/x3d-3.2.dtd"              location="../../../../specifications/x3d-3.2.dtd"/>
        <entity publicId="http://www.web3d.org/specifications/x3d-3.0.xsd"              location="../../../../specifications/x3d-3.0.xsd"/>
        <entity publicId="http://www.web3d.org/specifications/x3d-3.1.xsd"              location="../../../../specifications/x3d-3.1.xsd"/>
        <entity publicId="http://www.web3d.org/specifications/x3d-3.2.xsd"              location="../../../../specifications/x3d-3.2.xsd"/>
        <!-- Transitional DTD, versions 3.0 and 3.1 only -->
        <dtd    publicId="file:///www.web3d.org/TaskGroups/x3d/translation/x3d-3.0.dtd" location="../../../../specifications/x3d-3.0.dtd"/>
        <dtd    publicId="file:///www.web3d.org/TaskGroups/x3d/translation/x3d-3.1.dtd" location="../../../../specifications/x3d-3.1.dtd"/>
    </xmlcatalog>

    <!-- Ant macro definitions common to all build files, customized for this archive ============================== -->

    <!-- excerpted/adapted from "SAXON XSLT Processing with Ant" by James Fuller, http://ablog.apress.com/?p=753 -->
    <macrodef name="Saxon9" description="Invoke XSLT transformation on passed scene using passed stylesheet">
        <attribute name="scene"/>
        <attribute name="stylesheet"/>
        <attribute name="extension"/>
        <attribute name="compiled"/>
        <attribute name="parameterPairs" default=""/>
        <sequential>
            <!-- <echo message="Saxon9 processing @{scene}.@{extension} using @{stylesheet}, compiled=@{compiled}, parameterPairs=@{parameterPairs}"/> -->
            <if>
                <equals arg1="@{compiled}" arg2="true" />
                <then>
                    <java classname="net.sf.saxon.Transform" 
                          classpath="${basedir};${saxon.dir}/${saxon.jar};../../../tools/CreateContentCatalog/lib/resolver.jar"
                          fork="false"
                          failonerror="false">
                        <jvmarg value="-Dxml.catalog.files=C:/www.web3d.org/specifications/OasisXmlCatalogX3D.xml"/>
                        <jvmarg value="-Dxml.catalog.verbosity=4"/>
                        <!--<arg value="-t"/> timing information -->
                        <!-- use the Apache commons resolver for XML Catalog resolution of online DTD, schema addresses
                        http://sourceforge.net/apps/mediawiki/saxon/index.php?title=XML_Catalogs
                        "How to use a catalog file:  Using catalogs with Saxon"
                        http://www.sagehill.net/docbookxsl/UseCatalog.html
                        download resolver.jar from http://xml.apache.org/commons/dist and install into classpath above -->
                        <arg value="-r"/>
                        <arg value="org.apache.xml.resolver.tools.CatalogResolver"/>
                        <arg value="-x"/>
                        <arg value="org.apache.xml.resolver.tools.ResolvingXMLReader"/>
                        <arg value="-y"/>
                        <arg value="org.apache.xml.resolver.tools.ResolvingXMLReader"/>
                        <arg value="-u"/>  <!-- source file name is resolved to a JAXP Source object -->
                        <arg value="-warnings:recover"/> <!-- recover after writing a warning message -->
                        <arg value="-c"/>  <!-- ** compiled stylesheet ** -->
                        <arg value="-o"/>
                        <arg value="@{scene}.@{extension}"/>
                        <arg value="@{scene}.x3d"/> 
                        <arg value="@{stylesheet}"/>
                        <arg value="@{parameterPairs}"/>
                    </java>
                    <echo message="@{scene}"/>
                </then>
                <else>
                    <java classname="net.sf.saxon.Transform"
                          classpath="${basedir};${saxon.dir}/${saxon.jar};../../../tools/CreateContentCatalog/lib/resolver.jar"
                          fork="false"
                          failonerror="false">
                        <jvmarg value="-Dxml.catalog.files=C:/www.web3d.org/specifications/OasisXmlCatalogX3D.xml"/>
                        <jvmarg value="-Dxml.catalog.verbosity=4"/>
                        <!--<arg value="-t"/> timing information -->
                        <!-- use the Apache commons resolver for XML Catalog resolution of online DTD, schema addresses
                        http://sourceforge.net/apps/mediawiki/saxon/index.php?title=XML_Catalogs
                        "How to use a catalog file:  Using catalogs with Saxon"
                        http://www.sagehill.net/docbookxsl/UseCatalog.html
                        download resolver.jar from http://xml.apache.org/commons/dist and install into classpath above -->
                        <arg value="-r"/>
                        <arg value="org.apache.xml.resolver.tools.CatalogResolver"/>
                        <arg value="-x"/>
                        <arg value="org.apache.xml.resolver.tools.ResolvingXMLReader"/>
                        <arg value="-y"/>
                        <arg value="org.apache.xml.resolver.tools.ResolvingXMLReader"/>
                        <arg value="-warnings:recover"/> <!-- recover after writing a warning message -->
                        <arg value="-o"/>
                        <arg value="@{scene}.@{extension}"/>
                        <arg value="@{scene}.x3d"/>
                        <arg value="@{stylesheet}"/>
                        <arg value="@{parameterPairs}"/>
                    </java>
                </else>
            </if>
        </sequential>
    </macrodef>

    <macrodef name="canonicalX3D" description="convert scene.x3d to sceneCanonical.xml">
        <attribute name="scene"/>
        <sequential>
            <java classname="org.web3d.x3d.tools.x3db.X3dCanonicalizer"
                  classpath="${c14n.dir}/${c14n.jar}"
                  fork="false" failonerror="false">
                <!-- TODO:  larger memory setting to avoid heap errors -->
                <jvmarg value="-Xmx256m"/>
                <!--jvmarg value="-XX:MaxDirectMemorySize=500M"/-->
                <jvmarg value="-XX:PermSize=32m"/>
                <jvmarg value="-XX:MaxPermSize=256m"/>
                <arg value="@{scene}.x3d"/>
                <arg value="@{scene}Canonical.xml"/>
            </java>
            <xmlvalidate file="@{scene}Canonical.xml" failonerror="false" warn="true">
                <xmlcatalog refid="X3dCatalog"/>
            </xmlvalidate>
            <!-- save prior version to _archive/ subdirectory, then copy canonicalized version as current version -->
            <copy file="@{scene}.x3d"           todir="_archive/"    overwrite="true" failonerror="true" verbose="true" preservelastmodified="true"/>
            <copy file="@{scene}Canonical.xml" tofile="@{scene}.x3d" overwrite="true" failonerror="true" verbose="true" preservelastmodified="true"/>
        </sequential>
    </macrodef>

    <!-- target tasks common to all build files ===================================================================== -->

    <!-- TODO validate.all, -->
    <target name="all" depends="check.ant.version,clean.backups,clean.duplicates,commonSetup,build,upload" description="clean backups, build, zip and upload this X3D archive">
        <echo message="Copying latest build.out.txt to subdirectory ${archive.name}/_archive/"/>
        <copy file="build.out.txt" todir="_archive/" overwrite="true" failonerror="false"/>
    </target>

    <target name="all.record" description="build all for this X3D archive, record output to file" >
        <tstamp prefix="timestamp"/>
        <property name="build.out.filename" value="build.out.${archive.name}.${timestamp.DSTAMP}.txt"/>
        <delete file="${build.out.filename}"/>
        <echo message="logfile ${build.out.filename}"/>
        <echo message="logfile ${build.out.filename}" file="${build.out.filename}"/>
        <echo message=""       append="true"          file="${build.out.filename}"/>
        <record action="start" append="true"          name="${build.out.filename}"/>
        <antcall target="all"/>
        <record name="build.out.${archive.name}.${timestamp.DSTAMP}.txt" action="stop"/>
    </target>

    <target name="build.record" description="build this X3D archive, record output to file" >
        <tstamp prefix="timestamp"/>
        <property name="build.out.filename" value="build.out.${archive.name}.${timestamp.DSTAMP}.txt"/>
        <delete file="${build.out.filename}"/>
        <echo message="logfile ${build.out.filename}"/>
        <echo message="logfile ${build.out.filename}" file="${build.out.filename}"/>
        <echo message=""       append="true"          file="${build.out.filename}"/>
        <record action="start" append="true"          name="${build.out.filename}"/>
        <antcall target="build"/>
        <record name="build.out.${archive.name}.${timestamp.DSTAMP}.txt" action="stop"/>
    </target>

    <target name="build" depends="check.ant.version,commonSetup,validate.all,processScenes,catalog,zip" description="build this X3D archive" >
    </target>

    <target name="check.ant.version" description="Check for Apache Ant version">
       <echo message="${ant.version}"/>
       <fail message="Build tested with Apache Ant version 1.7 or 1.8">
           <condition>
               <and>
                   <not>
                       <contains string="${ant.version}" substring="1.7"/>
                   </not>
                   <not>
                       <contains string="${ant.version}" substring="1.8"/>
                   </not>
               </and>
           </condition>
       </fail>
    </target>

    <target name="clean.all" depends="clean.duplicates,clean.backups,clean.canonical.xml,clean.html,clean.schematron,clean.SVG,clean.wrl,clean.x3dv,clean.x3db" description="clean out autogenerated files (only)" >
        <echo message="clean/delete autogenerated ${archive.name} catalog pages and files matching *.x3d scenes: *.html *.wrl *.x3db *.x3dv *Canonical.xml"/>
        <!-- delete autogenerated directories, but not _archive directory -->
        <delete dir="_pages"      quiet="true" includeemptydirs="true"/>
        <delete dir="_svg"        quiet="true" includeemptydirs="true"/>
        <delete dir="_schematron" quiet="true" includeemptydirs="true"/>
        <delete verbose="true">
            <fileset dir="." includes="build.out.txt"/>
            <fileset dir="." includes="ContentCatalog*.*"/>
            <fileset dir="." includes="newScene.*"/>
            <fileset dir="." includes="newHtmlPageWithX3dObject.html"/>
            <fileset dir="." includes="newECMAscript.js"/>
            <fileset dir="." includes="newX3dScript.java"/>
            <fileset dir="." includes="HelloWorld.*"/>
            <fileset dir="." includes="earth-topo*.*"/>
            <fileset dir="." includes="*.html" excludes="license.html"/>
            <fileset dir="." includes="*.wrl"/>
            <fileset dir="." includes="*.x3db"/>
            <fileset dir="." includes="*.x3dv"/>
            <fileset dir="." includes="*Canonical.xml"/>
            <fileset dir="." includes="Thumbs.db"/>
            <fileset dir="." includes="*.bak"/>
            <fileset dir="." includes="**/*.$$$$$$"/> <!-- escape $ as $$ -->
        </delete>
        <!-- clean hudson subdirectories -->
        <delete dir="lib"         quiet="false" includeemptydirs="true"/>
        <delete dir="stylesheets" quiet="false" includeemptydirs="true"/>
    </target>

    <target name="clean.archiveSubdirectories" description="clean out duplicates in _archive subdirectories" >
        <echo message="clean/delete backup files for project ${archive.name}"/>
        <delete verbose="true">
            <fileset dir="." includes="**/_archive/*.*"/>
        </delete>
    </target>
    
    <target name="clean.catalog" description="clean out unnecessary backup files (only)" >
        <echo message="clean/delete autogenerated catalog files"/>
        <delete verbose="true">
                <fileset dir="." includes="**/_pages/*.html"/>
                <fileset dir="." includes="**/_svg/*.svg"/>
        </delete>
        <!-- TODO how to remove directories correctly? -->
        <delete dir="**/_pages" verbose="true"/>
        <delete dir="**/_svg"   verbose="true"/>
    </target>
    
    <target name="clean.media" description="clean out large files (warning, this included necessary files for scene operation)" >
        <echo message="clean/delete sound, image and movie files"/>
        <delete verbose="true">
                <fileset dir="." includes="**/*.wav"/>
                <fileset dir="." includes="**/*.gif"/>
                <fileset dir="." includes="**/*.jpg"/>
                <fileset dir="." includes="**/*.mpg"/>
                <fileset dir="." includes="**/*.mov"/>
                <fileset dir="." includes="**/*.ppt"/>
        </delete>
    </target>

    <target name="clean.backups" depends="clean.duplicates" description="clean out unnecessary backup files (only)" >
        <echo message="clean/delete backup files for project ${archive.name}"/>
        <delete verbose="true">
            <fileset dir="." includes="**/_new_pretty_print.html"/>
            <fileset dir="." includes="**/_new_result.wrl"/>
            <fileset dir="." includes="**/_new_result.x3db"/>
            <fileset dir="." includes="**/_new_result.x3dv"/>
            <fileset dir="." includes="**/Thumbs.db"/>
            <fileset dir="." includes="**/*.bak"/>
            <fileset dir="." includes="**/hs_err_pid*.log"/>
            <fileset dir="." includes="**/manifest.mf"/>
            <fileset dir="." includes="**/*.$$$$$$"/> <!-- escape $ as $$ -->
            <fileset dir="." includes="**/*Canonical.x3d"/>
            <fileset dir="." includes="**/*Canonical.x3db"/>
            <fileset dir="." includes="**/*Canonical.x3dv"/>
            <fileset dir="." includes="**/*Canonical.wrl"/>
            <fileset dir="." includes="**/*Canonical.html"/>
        </delete>
    </target>

    <!-- warning!  do not create .x3d file names that end in five or more numeric digits since X3D-Edit uses that as a temporary backup filename -->
    <target name="clean.duplicates" description="clean out duplicate files autogenerated by X3D-Edit, ending with 5 or more numeric values" >
        <echo message="clean/delete duplicate files autogenerated by X3D-Edit ending with 5 or more numeric values (*#####.x3d)"/>
        <echo message="  including files matching *#####.x3d scenes: *.html *.wrl *.x3db *.x3dv *Canonical.xml"/>
        <for param="file.path.name">
            <path>
                <fileset refid="x3dScenes"/>
            </path>
            <sequential>
                <propertyregex
                        property="filename.prefix.duplicate"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)[\\/]([^\n]*[0-9][0-9][0-9][0-9][0-9])(\.x3d|\.x3dv|\.x3db|\.wrl|\.html|Canonical\.xml)"
                        select="\2"/>
                <propertyregex
                        property="relative.path1"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)_archiveName_[\\/]([^\n^\\]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path2"
                        override="true"
                        input="@{file.path.name}"
                        regexp="_regexp2_"
                        select="\3"/>
                <if>
                    <equals arg1="${filename.prefix.duplicate}" arg2="" />
                    <then>
                        <!-- not a duplicate, ignore-->
                    </then>
                    <else>
                    <!--<echo>delete ${relative.path1}/${relative.path2}/${name.short}.html</echo> -->
                        <delete file="${relative.path1}/${relative.path2}/${filename.prefix.duplicate}.x3d"/>
                        <delete file="${relative.path1}/${relative.path2}/${filename.prefix.duplicate}.html"/>
                        <delete file="${relative.path1}/${relative.path2}/${filename.prefix.duplicate}.wrl"/>
                        <delete file="${relative.path1}/${relative.path2}/${filename.prefix.duplicate}.x3db"/>
                        <delete file="${relative.path1}/${relative.path2}/${filename.prefix.duplicate}.x3dv"/>
                        <delete file="${relative.path1}/${relative.path2}/${filename.prefix.duplicate}Canonical.xml"/>
                    </else>
                </if>
            </sequential>
        </for>
    </target>

    <target name="clean.html" description="clean out autogenerated *.html files (only)" >
        <echo message="clean/delete autogenerated files matching *.x3d scenes: *.html "/>
        <for param="file.path.name">
            <path>
                <fileset refid="x3dScenes"/>
            </path>
            <sequential>
                <propertyregex
                        property="name.short"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path1"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)_archiveName_[\\/]([^\n^\\]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path2"
                        override="true"
                        input="@{file.path.name}"
                        regexp="_regexp2_"
                        select="\3"/>
            <!-- <echo>delete ${relative.path1}/${relative.path2}/${name.short}.html</echo> -->
                <delete file="${relative.path1}/${relative.path2}/${name.short}.html"/>
            </sequential>
        </for>
    </target>

    <target name="clean.wrl" description="clean out autogenerated *.wrl files (only)" >
        <echo message="clean/delete autogenerated files matching *.x3d scenes: *.wrl"/>
        <for param="file.path.name">
            <path>
                <fileset refid="x3dScenes"/>
            </path>
            <sequential>
                <propertyregex
                        property="name.short"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path1"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)_archiveName_[\\/]([^\n^\\]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path2"
                        override="true"
                        input="@{file.path.name}"
                        regexp="_regexp2_"
                        select="\3"/>
            <!-- <echo>delete ${relative.path1}/${relative.path2}/${name.short}.wrl</echo> -->
                <delete file="${relative.path1}/${relative.path2}/${name.short}.wrl"/>
            </sequential>
        </for>
    </target>

    <target name="clean.x3db" description="clean out autogenerated *.x3db files" >
        <echo message="clean/delete autogenerated files matching *.x3d scenes: *.x3db"/>
        <delete verbose="true">
            <fileset dir="." includes="**/*.x3db"/>
        </delete>
    </target>

    <target name="clean.x3dv" description="clean out autogenerated *.x3dv files (only)" >
        <echo message="clean/delete autogenerated files matching *.x3d scenes: *.x3dv"/>
        <for param="file.path.name">
            <path>
                <fileset refid="x3dScenes"/>
            </path>
            <sequential>
                <propertyregex
                        property="name.short"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path1"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)_archiveName_[\\/]([^\n^\\]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path2"
                        override="true"
                        input="@{file.path.name}"
                        regexp="_regexp2_"
                        select="\3"/>
            <!-- <echo>delete ${relative.path1}/${relative.path2}/${name.short}.x3dv</echo> -->
                <delete file="${relative.path1}/${relative.path2}/${name.short}.x3dv"/>
            </sequential>
        </for>
    </target>

    <target name="clean.canonical.xml" description="clean out autogenerated *Canonical.xml files (only)" >
        <echo message="clean/delete autogenerated *Canonical.xml files"/>
        <delete verbose="true">
            <fileset dir="." includes="**/*Canonical.xml"/>
        </delete>
    </target>

    <target name="clean.SVG" description="clean out autogenerated *.svg files (only)" >
        <echo message="clean/delete autogenerated files matching *.x3d scenes: _svg/*.svg"/>
        <delete verbose="true">
            <fileset dir=".">
                <include name="*/_svg/*.svg"/>
                <include name="*/*/_svg/*.svg"/>
            </fileset>
        </delete>
    </target>

    <target name="clean.schematron" description="clean out autogenerated schematron validation files (only)" >
        <echo message="clean/delete autogenerated files matching *.x3d scenes: _schematron/*"/>
        <delete verbose="true">
            <fileset dir=".">
                <include name="_schematron/*"/>
                <include name="*/_schematron/*"/>
                <include name="*/*/_schematron/*"/>
            </fileset>
        </delete>
    </target>

    <target name="clean.viewpointImages" description="clean out autogenerated viewpoint image files (only)" >
        <echo message="clean/delete autogenerated viewpoint image files"/>
        <delete verbose="true">
            <fileset dir=".">
                <include name="*/_viewpoints/*.png"/>
                <include name="*/*/_viewpoints/*.png"/>
            </fileset>
        </delete>
     </target>

    <target name="hudson.prepare" description="setup hudson server-side build" depends="">
        <!-- hudson tasks:  hudson.prepare, build -->
        <!-- hudson configuration needs to reset property values to match subdirectories below:
             c14n.dir=lib
             saxon.dir=lib
             xj3d.dir=lib
             stylesheet.dir=stylesheets -->
        <echo message="get local copies of dependency files in order to independently prepare hudson server-side build"/>
        <mkdir dir="stylesheets"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/stylesheets/X3dToXhtml.xslt"
             dest="stylesheets/X3dToXhtml.xslt" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/stylesheets/X3dToXhtml.sxx"
             dest="stylesheets/X3dToXhtml.sxx" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/stylesheets/X3dToX3dvClassicVrmlEncoding.xslt"
             dest="stylesheets/X3dToX3dvClassicVrmlEncoding.xslt" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/stylesheets/X3dToX3dvClassicVrmlEncoding.sxx"
             dest="stylesheets/X3dToX3dvClassicVrmlEncoding.sxx" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/stylesheets/X3dToVrml97.xslt"
             dest="stylesheets/X3dToVrml97.xslt" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/stylesheets/X3dToVrml97.sxx"
             dest="stylesheets/X3dToVrml97.sxx" verbose="true"/>
        <mkdir dir="lib"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/tools/canonical/dist/lib/${c14n.jar}"
             dest="lib/${c14n.jar}" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/tools/canonical/dist/lib/${log4j.jar}"
             dest="lib/${log4j.jar}" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/tools/schematron/bin/${saxon.jar}"
             dest="lib/${saxon.jar}" verbose="true"/>
        <get src="http://xmsf.svn.sourceforge.net/svnroot/xmsf/trunk/AuvWorkbench/lib/xj3d/${xj3d.cadfilter.jar}"
             dest="lib/${xj3d.cadfilter.jar}" verbose="true"/>
    </target>

    <target name="commonSetup" description="Copy setup files from common example-archives parent" >
        <!-- each specific example archive redirects to X3dResources.html (formerly help.html) in parent examples directory due to other relative links there -->
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/_help.redirect.html"
             dest="help.html" verbose="true"/>
        <!-- here is local copy of X3dResources.html as well -->
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/X3dResources.html"
             dest="X3dResources.html" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/X3dSceneAuthoringHints.html"
             dest="X3dSceneAuthoringHints.html" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/license.html"
             dest="license.html" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/license.txt"
             dest="license.txt" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/newHtmlPageWithX3dObject.html"
             dest="newHtmlPageWithX3dObject.html" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/newECMAscript.js"
             dest=".newECMAscript.js" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/newX3dScript.java"
             dest="newX3dScript.java" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/newStylesheet.xslt"
             dest="newStylesheet.xslt" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/images/Help.png"
             dest="Help.png" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/images/NextChapter.png"
             dest="NextChapter.png" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/images/NextPage.png"
             dest="NextPage.png" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/images/PreviousChapter.png"
             dest="PreviousChapter.png" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/images/PreviousPage.png"
             dest="PreviousPage.png" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/images/ThisChapter.png"
             dest="ThisChapter.png" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/images/ToC.png"
             dest="ToC.png" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/images/X3DtextIcon16.png"
             dest="X3DtextIcon16.png" verbose="true"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/images/web3d_logo2.png"
             dest="web3d_logo2.png" verbose="true"/>
    </target>

    <target name="diagnostics" description="Ant diagnostics, shows jars and classpaths">
        <diagnostics/>
    </target>

    <target name="HelloWorld" description="Copy HelloWorld.x3d example from common example-archives parent and convert to other encodings" >
        <delete failonerror="false">
            <fileset dir="." includes="HelloWorld.*"/>
            <fileset dir="." includes="HelloWorldCanonical.*"/>
        </delete>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/earth-topo.jpg"
             dest="earth-topo.jpg"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/earth-topo.png"
             dest="earth-topo.png"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/earth-topo.gif"
             dest="earth-topo.gif"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/earth-topo-small.gif"
             dest="earth-topo-small.gif"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/HelloWorld.tall.png"
             dest="HelloWorld.tall.png"/>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/HelloWorld.x3d"
             dest="HelloWorld.x3d"/>
        <xmlvalidate file="HelloWorld.x3d" failonerror="true" warn="true">
            <xmlcatalog refid="X3dCatalog"/>
        </xmlvalidate>
        <echo message="Convert HelloWorld.x3d to HelloWorld.html using X3dToXhtml.xslt"/>
        <!-- $(SAXON) -t -o HelloWorld.html	HelloWorld.x3d 	../X3dToXhtml.xslt -->
        <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="false">
            <!--<arg value="-t"/> timing information -->
            <arg value="-warnings:recover"/> <!-- recover after writing a warning message -->
            <arg value="-c"/>                   <!-- compiled stylesheet -->
            <arg value="-o"/>
            <arg value="HelloWorld.html"/>
            <arg value="HelloWorld.x3d"/>
            <arg value="${stylesheet.dir}/X3dToXhtml.sxx"/> <!-- compiled stylesheet -->
            <!--<arg value="${stylesheet.dir}/X3dToXhtml.xslt"/> -->
        </java>
        <echo message="Convert HelloWorld.x3d to HelloWorld.wrl using X3dToVrml97.xslt"/>
        <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="false">
            <arg value="-warnings:recover"/>
            <arg value="-c"/>                   <!-- compiled stylesheet -->
            <arg value="-o"/>
            <arg value="HelloWorld.wrl"/>
            <arg value="HelloWorld.x3d"/>
            <arg value="${stylesheet.dir}/X3dToVrml97.sxx"/> <!-- compiled stylesheet -->
            <!--<arg value="${stylesheet.dir}/X3dToVrml97.xslt"/> -->
        </java>
        <echo message="Convert HelloWorld.x3d to HelloWorld.x3dv using X3dToX3dvClassicVrmlEncoding.xslt"/>
        <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="false">
            <arg value="-warnings:recover"/>
            <arg value="-c"/>                   <!-- compiled stylesheet -->
            <arg value="-o"/>
            <arg value="HelloWorld.x3dv"/>
            <arg value="HelloWorld.x3d"/>
            <arg value="${stylesheet.dir}/X3dToX3dvClassicVrmlEncoding.sxx"/> <!-- compiled stylesheet -->
            <!--<arg value="${stylesheet.dir}/X3dToX3dvClassicVrmlEncoding.xslt"/> -->
        </java>
        <echo message="Convert HelloWorld.x3d to HelloWorldCanonical.xml using canonicalX3D"/>
        <!-- canonicalX3D is locally defined macro -->
        <!-- X3dC14n requires full paths to the scene in order to resolve where to put the *Canonical.xml version -->
        <canonicalX3D scene="${basedir}/HelloWorld"/>
        <echo message="Convert HelloWorld.x3d to HelloWorldCanonical.x3db using Xj3D"/>
        <java classname="xj3d.filter.CDFFilter" fork="yes" dir=".">
            <classpath>
                <pathelement path="${classpath}"/>
                <fileset dir="${xj3d.dir}">
                    <include name="${xj3d.jar}"/>
                </fileset>
            </classpath>
            <jvmarg value="-Xmx450M"/>
            <jvmarg value="-Xbootclasspath/p:${xj3d.dir}/bin"/>
            <jvmarg value="-Dsun.java2d.noddraw=true"/>
            <jvmarg value="-Djava.library.path=${xj3d.dir}/bin"/>
            <arg value="Identity"/>
            <arg value="HelloWorld.x3d"/>
            <arg value="HelloWorld.x3db"/>
        </java>
        <copy todir=".." overwrite="true">
            <fileset dir="." includes="HelloWorld.x3dv"/>
            <fileset dir="." includes="HelloWorld.x3db"/>
            <fileset dir="." includes="HelloWorld.wrl"/>
            <fileset dir="." includes="HelloWorld.html"/>
            <fileset dir="." includes="HelloWorldCanonical.xml"/>
        </copy>
    </target>

    <target name="newScene" description="Copy newScene.x3d example from common example-archives parent and convert to other encodings" >
        <delete failonerror="false">
            <fileset dir="." includes="newScene*"/>
        </delete>
        <get src="http://x3d.svn.sourceforge.net/viewvc/x3d/www.web3d.org/x3d/content/examples/newScene.x3d"
             dest="newScene.x3d"/>
        <xmlvalidate file="newScene.x3d" failonerror="true" warn="true">
            <xmlcatalog refid="X3dCatalog"/>
        </xmlvalidate>
        <echo message="Convert newScene.x3d to newScene.html using X3dToXhtml.xslt"/>
        <!-- $(SAXON) -t -o newScene.html	newScene.x3d 	../X3dToXhtml.xslt -->
        <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="false">
            <!--<arg value="-t"/> timing information -->
            <arg value="-warnings:recover"/> <!-- recover after writing a warning message -->
            <arg value="-o"/>
            <arg value="newScene.html"/>
            <arg value="newScene.x3d"/>
            <arg value="${stylesheet.dir}/X3dToXhtml.xslt"/> <!-- regular stylesheet, not compiled by Saxon -->
        </java>
        <echo message="Convert newScene.x3d to newScene.wrl using X3dToVrml97.xslt"/>
        <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="false">
            <arg value="-warnings:recover"/>
            <arg value="-o"/>
            <arg value="newScene.wrl"/>
            <arg value="newScene.x3d"/>
            <arg value="${stylesheet.dir}/X3dToVrml97.xslt"/>
        </java>
        <echo message="Convert newScene.x3d to newScene.x3dv using X3dToX3dvClassicVrmlEncoding.xslt"/>
        <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="false">
            <arg value="-warnings:recover"/>
            <arg value="-o"/>
            <arg value="newScene.x3dv"/>
            <arg value="newScene.x3d"/>
            <arg value="${stylesheet.dir}/X3dToX3dvClassicVrmlEncoding.xslt"/>
        </java>
        <echo message="Convert newScene.x3d to newSceneCanonical.xml using canonicalX3D"/>
        <!-- canonicalX3D is locally defined macro -->
        <canonicalX3D scene="${basedir}/newScene"/>
        <echo message="Convert newScene.x3d to newSceneCanonical.x3db using Xj3D"/>
        <java classname="xj3d.filter.CDFFilter" fork="false" dir=".">
            <classpath>
                <pathelement path="${classpath}"/>
                <fileset dir="${xj3d.dir}">
                    <include name="${xj3d.cadfilter.jar}"/>
                </fileset>
                <fileset dir="${xj3d.dir}">
                    <include name="*.jar"/>
                    <exclude name="xj3d-all_2.0.0.jar"/>
                </fileset>
            </classpath>
            <jvmarg value="-Xmx450M"/>
            <jvmarg value="-Xbootclasspath/p:${xj3d.dir}/bin"/>
            <jvmarg value="-Dsun.java2d.noddraw=true"/>
            <jvmarg value="-Djava.library.path=${xj3d.dir}/bin"/>
            <arg value="Identity"/>
            <arg value="newScene.x3d"/>
            <arg value="newScene.x3db"/>
        </java>
        <copy todir=".." overwrite="true">
            <fileset dir="." includes="newScene.x3dv"/>
            <fileset dir="." includes="newScene.x3db"/>
            <fileset dir="." includes="newScene.wrl"/>
            <fileset dir="." includes="newScene.html"/>
            <fileset dir="." includes="newSceneCanonical.xml"/>
        </copy>
    </target>

    <!-- TODO validate.schema.saxonicaSA, -->
    <target name="validate.all" description="XML well formed, DTD validation for all .x3d examples"
        depends="clean.duplicates,validate.DTD,validate.schematron">
        <echo message="validate using all methods: ${archive.name} archive complete"/>
        <echo message="warning: schema validation of all files is a bit slow and is prone to java.lang.StackOverflowError within Ant"/>
        <!-- TODO
        <antcall target="validate.schema.new"/>
        <antcall target="validate.schema.all"/>
        <antcall target="validate.xmllint"/> 
        -->
    </target>

    <target name="validate.DTD" description="XML well formed, DTD validation for all .x3d examples" >
        <!-- XML well-formed checks -->
        <echo message="XML well-formed check: ${archive.name} build.xml and scenes"/>
        <xmlvalidate failonerror="false" warn="true" lenient="yes" file="build.xml"/>
        <xmlvalidate failonerror="false" warn="true" lenient="yes">
            <!-- only check *.x3d files of interest (and *Canonical.xml versions as a double-check) not grandchild directories holding errors or work in progress -->
            <fileset refid="x3dScenes"/>
            <fileset refid="xmlFiles"/>
            <xmlcatalog refid="X3dCatalog"/>
        </xmlvalidate>
        <!-- X3D DTD validation -->
        <echo message="validate using X3D DTD: ${archive.name} archive"/>
        <xmlvalidate failonerror="false" warn="true">
            <!-- only check *.x3d files of interest (and *Canonical.xml versions as a double-check) not grandchild directories holding errors or work in progress -->
            <fileset refid="x3dScenes"/>
            <fileset refid="xmlFiles"/>
            <xmlcatalog refid="X3dCatalog"/>
        </xmlvalidate>
    </target>

    <target name="validate.schema.all" description="XML validation for all .x3d examples using X3D schema (caution, time consuming)" >
        <!-- X3D schema validation -->
        <echo message="validate using X3D schema: ${archive.name} archive"/>
        <!-- TODO need to try increasing stack space to 16m, fullchecking true results in java.lang.StackOverflowError
        at com.sun.org.apache.xerces.internal.impl.xpath.regex.RegularExpression.matchString(RegularExpression.java:1903) -->
        <schemavalidate lenient="false" failonerror="false" fullchecking="false" warn="true">
            <!-- only check *.x3d files of interest, not grandchild directories holding errors or work in progress -->
            <fileset refid="x3dScenes"/>
            <!-- TODO <fileset refid="xmlFiles"/> -->
            <xmlcatalog refid="X3dCatalog"/>
        </schemavalidate>
    </target>

    <target name="validate.schema.saxonicaSA" description="XML validation for all .x3d examples using X3D schema (caution, time consuming)" >
        <!-- X3D schema validation -->
        <echo message="validate using X3D schema,saxonicaSA: ${archive.name} archive"/>
        <for param="file.path.name">
            <path>
                <fileset refid="x3dScenes"/>
            </path>
            <sequential>
                <echo message="@{file.path.name} validation using X3D schema, saxononicaSA..."/>
                <java classname="com.saxonica.Validate" classpath="${saxononicaSA.dir}/saxon9sa.jar;${saxononicaSA.dir};${saxononicaSA.dir}/saxon-license.lic;." fork="false">
                    <arg value="@{file.path.name}"/>
                </java>
            </sequential>
        </for>
    </target>

    <target name="validate.schema.new" description="XML validation for new or modified .x3d examples using X3D schema" >
        <echo message="validate using X3D schema: ${archive.name} archive, new scenes"/>
        <for param="file.path.name">
            <path>
                <fileset refid="x3dScenes"/>
            </path>
            <sequential>
                <propertyregex
                        property="name.short"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path1"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)_archiveName_[\\/]([^\n^\\]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path2"
                        override="true"
                        input="@{file.path.name}"
                        regexp="_regexp2_"
                        select="\3"/>
                <outofdate>
                    <sourcefiles>
                        <filelist>
                            <file name="@{file.path.name}"/>
                        </filelist>
                    </sourcefiles>
                    <mapper dir="." type="glob" from="*.x3d" to="*Canonical.xml"/>
                    <sequential>
                        <!-- process individual files here -->
                        <echo message="@{file.path.name} validation using X3D schema..."/>
                        <schemavalidate file="@{file.path.name}" lenient="false" failonerror="false" fullchecking="true">
                            <xmlcatalog refid="X3dCatalog"/>
                        </schemavalidate>
                    </sequential>
                </outofdate>
            </sequential>
        </for>
    </target>

    <property name="X3dSchematronValidityChecks" location="../../../tools/schematron/X3dSchematronValidityChecks"/>
    <property name="SvrlReportText"              location="../../../tools/schematron/SvrlReportText"/>

    <target name="validate.schematron" description="validate each .x3d scene using X3D Schematron rules (caution, time consuming" >
        <echo message="validate using X3D Schematron: ${archive.name} archive"/>
        <for param="file.path.name">
            <path>
                <fileset refid="x3dScenes"/>
            </path>
            <sequential>
                <propertyregex
                        property="name.short"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path1"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)_archiveName_[\\/]([^\n^\\]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path2"
                        override="true"
                        input="@{file.path.name}"
                        regexp="_regexp2_"
                        select="\3"/>
                <!-- trace
                <echo></echo>
                <echo>@file.path.name       = @{file.path.name}</echo>
                <echo>$archive.path         = ${archive.path}</echo>
                <echo>$relative.path1       = ${relative.path1}</echo>
                <echo>$relative.path2       = ${relative.path2}</echo>
                <echo>$name.short           = ${name.short}</echo>
                -->
                <outofdate>
                    <sourcefiles>
                        <filelist>
                            <file name="@{file.path.name}"/>
                        </filelist>
                    </sourcefiles>
                    <mapper dir="." type="glob" from="*.x3d" to="_schematron/*.svrl"/>
                    <sequential>
                        <!-- process individual files here -->
                        <echo>@{file.path.name} validation using X3D Schematron rules</echo>
                        <mkdir dir="${archive.path}/${relative.path1}/${relative.path2}/_schematron"/>
                        <!-- regular .xslt stylesheet using Ant task:
                        <xslt basedir="." destdir="." extension=""
                              style="${X3dSchematronValidityChecks}.xslt"
                                 in="@{file.path.name}"
                                out="${archive.path}/${relative.path1}/${relative.path2}/_schematron/${name.short}.svrl">
                            <xmlcatalog refid="X3dCatalog"/>
                        </xslt>
                        <xslt basedir="." destdir="." extension=""
                              style="${SvrlReportText}.xslt"
                                 in="${archive.path}/${relative.path1}/${relative.path2}/_schematron/${name.short}.svrl"
                                out="${archive.path}/${relative.path1}/${relative.path2}/_schematron/${name.short}.svrl.txt">
                            <xmlcatalog refid="X3dCatalog"/>
                        </xslt>
                        -->
                        <!-- compiled .sxx stylesheet using Saxon -->
                        <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="false">
                            <arg value="-warnings:recover"/>
                            <arg value="-c"/>                   <!-- compiled stylesheet -->
                            <arg value="-o"/>
                            <arg value="${archive.path}/${relative.path1}/${relative.path2}/_schematron/${name.short}.svrl"/>
                            <arg value="@{file.path.name}"/>
                            <arg value="${X3dSchematronValidityChecks}.sxx"/>
                        </java>
                        <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="false">
                            <arg value="-warnings:recover"/>
                            <arg value="-c"/>                   <!-- compiled stylesheet -->
                            <arg value="-o"/>
                            <arg value="${archive.path}/${relative.path1}/${relative.path2}/_schematron/${name.short}.svrl.txt"/>
                            <arg value="${archive.path}/${relative.path1}/${relative.path2}/_schematron/${name.short}.svrl"/>
                            <arg value="${SvrlReportText}.sxx"/>
                        </java>
                        <concat>
                            <filelist dir="." files="${archive.path}/${relative.path1}/${relative.path2}/_schematron/${name.short}.svrl.txt"/>
                        </concat>
                    </sequential>
                </outofdate>
            </sequential>
        </for>
    </target>

    <!-- prerequisite:  xmllint installed on system path.  
         provided as part of libxml library, http://xmlsoft.org
         suggested installation for Windows is cygwin, http://cygwin.com -->
    <!-- TODO:  not working
    <target name="validate.xmllint">
        <for param="filenames">
            <path>
                <fileset dir="." includes="**/*.x3d"/>
            </path>
            <sequential>
                <propertyregex
                    property="path.scene"
                    override="true"
                    input="@{filenames}"
                    regexp="([^\n]*)[\\|/][^\\]*\.x3d"
                    select="\1"/>
                <propertyregex
                    property="filename.prefix"
                    override="true"
                    input="@{filenames}"
                    regexp="([^\\]*\\)*([^\n]*)\.x3d"
                    select="\2"/>
                <echo>Processing ${path.scene}/${filename.prefix}.x3d with xmllint</echo>
                <exec executable="xmllint">
                    <arg value="- -valid"/>
                    <arg value="- -noout"/>
                    <arg value="- -dtdvalid  file:///cygdrive/c/www.web3d.org/specifications/x3d-3.2.dtd"/>
                    <arg value="${path.scene}/${filename.prefix}.x3d"/>
                </exec>
            </sequential>
        </for>
    </target>
    -->

    <target name="refresh" depends="clean.backups,clean.duplicates,validate.DTD,commonSetup,processScenes,catalog,zip,upload" description="quick master refresh of all .x3d examples:  processScenes and upload" >
        <echo message="${archive.name} refresh complete."/>
    </target>

    <!-- TODO:  subversion update, potentially will need to deconflict naming of tasks -->
    <target name="update.subversion.draft" depends="clean.backups,clean.duplicates,commonSetup,processScenes" description="update online versions for all .x3d examples" >
        <!-- subversion task here -->
        <echo message="${archive.name} update complete."/>
    </target>

    <target name="upload" description="upload all x3d examples and archive files, including .zip" >
        <ant dir=".." target="sftp.uploadExampleUpdates.${archive.name}"/>
        <echo message="${archive.name} upload complete."/>
    </target>

    <target name="upload.scenes" depends="clean.duplicates,clean.backups" description="upload scenes in examples archive (overwrite previous versions), do not upload .zip" >
        <ant dir=".." target="sftp.uploadExampleUpdates.${archive.name}.scenes"/>
        <echo message="${archive.name} upload.scenes complete."/>
    </target>

    <target name="upload.zip" description="upload .zip examples archive (overwrite previous version)" >
        <ant dir=".." target="sftp.uploadExampleUpdates.${archive.name}.zip"/>
        <echo message="${archive.name}.zip upload complete."/>
    </target>

    <target name="processScenes" depends="clean.duplicates,processScenes.canonicalX3D,validate.DTD,processScenes.X3DtoVRML97,processScenes.X3dToXhtml,processScenes.X3dToX3dvClassicVrmlEncoding,processScenes.X3dToX3dbCompressedBinaryEncoding" description="process all scenes with all conversion tasks">
        <!-- processScenes.canonicalX3D occurs first because it replaces original .x3d scene -->
        <!-- this task depends on other tasks to look through the directories, only updating as needed -->
        <!-- processScenes.captureViewpoints can't be included until viewpoint naming is predictable and globbable -->
        <echo message="${archive.name} processScenes complete."/>
    </target>

    <target name="processScenes.X3dToXhtml" description="convert each .x3d scene to pretty-print .html version" >
        <for param="file.path.name">
            <path>
                <fileset refid="x3dScenes"/>
            </path>
            <sequential>
                <propertyregex
                        property="name.short"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path1"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)_archiveName_[\\/]([^\n^\\]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path2"
                        override="true"
                        input="@{file.path.name}"
                        regexp="_regexp2_"
                        select="\3"/>
                <!-- trace
                <echo></echo>
                <echo>@file.path.name       = @{file.path.name}</echo>
                <echo>$archive.path         = ${archive.path}</echo>
                <echo>$relative.path1       = ${relative.path1}</echo>
                <echo>$relative.path2       = ${relative.path2}</echo>
                <echo>$name.short           = ${name.short}</echo>
                -->
                <outofdate>
                    <sourcefiles>
                        <filelist>
                            <file name="@{file.path.name}"/>
                        </filelist>
                    </sourcefiles>
                    <mapper dir="." type="glob" from="*.x3d" to="*.html"/>
                    <sequential>
                        <!-- process individual files here -->
                        <echo>${archive.path}/${relative.path1}/${relative.path2}/${name.short}.x3d processing with X3dToXhtml stylesheet</echo>
                        <!-- Saxon9 is locally defined macro -->
                        <Saxon9 scene="${relative.path1}/${relative.path2}/${name.short}" stylesheet="${stylesheet.dir}/X3dToXhtml.sxx" extension="html" compiled="true" parameterPairs="linkImages=true"/>
                    </sequential>
                </outofdate>
            </sequential>
        </for>
        <!-- clean up erroneous namespace artifacts -->
        <replace dir="." token=' xmlns=""' value="">
            <include name="**/*.svg"/>
        </replace>
    </target>

    <target name="processScenes.X3DtoVRML97" description="convert each .x3d scene to .wrl VRML97 version" >
        <for param="file.path.name">
            <path>
                <fileset refid="x3dScenes"/>
            </path>
            <sequential>
                <propertyregex
                        property="name.short"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path1"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)_archiveName_[\\/]([^\n^\\]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path2"
                        override="true"
                        input="@{file.path.name}"
                        regexp="_regexp2_"
                        select="\3"/>
                <!-- trace
                <echo></echo>
                <echo>@file.path.name       = @{file.path.name}</echo>
                <echo>$archive.path         = ${archive.path}</echo>
                <echo>$relative.path1       = ${relative.path1}</echo>
                <echo>$relative.path2       = ${relative.path2}</echo>
                <echo>$name.short           = ${name.short}</echo>
                -->
                <outofdate>
                    <sourcefiles>
                        <filelist>
                            <file name="@{file.path.name}"/>
                        </filelist>
                    </sourcefiles>
                    <mapper dir="." type="glob" from="*.x3d" to="*.wrl"/>
                    <sequential>
                        <!-- process individual files here -->
                        <echo>${archive.path}/${relative.path1}/${relative.path2}/${name.short}.x3d processing with X3dToVrml97 stylesheet</echo>
                        <!-- Saxon9 is locally defined macro -->
                        <Saxon9 scene="${relative.path1}/${relative.path2}/${name.short}" stylesheet="${stylesheet.dir}/X3dToVrml97.sxx" extension="wrl" compiled="true"/>
                    </sequential>
                </outofdate>
            </sequential>
        </for>
    </target>

    <target name="processScenes.X3dToX3dvClassicVrmlEncoding">
        <for param="file.path.name">
            <path>
                <fileset refid="x3dScenes"/>
            </path>
            <sequential>
                <propertyregex
                        property="name.short"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path1"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)_archiveName_[\\/]([^\n^\\]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path2"
                        override="true"
                        input="@{file.path.name}"
                        regexp="_regexp2_"
                        select="\3"/>
                <!-- trace
                <echo></echo>
                <echo>@file.path.name       = @{file.path.name}</echo>
                <echo>$archive.path         = ${archive.path}</echo>
                <echo>$relative.path1       = ${relative.path1}</echo>
                <echo>$relative.path2       = ${relative.path2}</echo>
                <echo>$name.short           = ${name.short}</echo>
                -->
                <outofdate>
                    <sourcefiles>
                        <filelist>
                            <file name="@{file.path.name}"/>
                        </filelist>
                    </sourcefiles>
                    <mapper dir="." type="glob" from="*.x3d" to="*.x3dv"/>
                    <sequential>
                        <!-- process individual files here -->
                        <echo>${archive.path}/${relative.path1}/${relative.path2}/${name.short}.x3d processing with X3dToX3dvClassicVrmlEncoding stylesheet</echo>
                        <!-- Saxon9 is locally defined macro -->
                        <Saxon9 scene="${relative.path1}/${relative.path2}/${name.short}" stylesheet="${stylesheet.dir}/X3dToX3dvClassicVrmlEncoding.sxx" extension="x3dv" compiled="true"/>
                    </sequential>
                </outofdate>
            </sequential>
        </for>
    </target>

    <target name="processScenes.X3dToX3dbCompressedBinaryEncoding" description="convert each .x3d scene to .x3db Compressed Binary Encoding version" >
        <for param="file.path.name">
            <path>
                <fileset refid="x3dScenes"/>
            </path>
            <sequential>
                <propertyregex
                        property="name.short"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path1"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)_archiveName_[\\/]([^\n^\\]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path2"
                        override="true"
                        input="@{file.path.name}"
                        regexp="_regexp2_"
                        select="\3"/>
                <!-- trace
                <echo></echo>
                <echo>@file.path.name       = @{file.path.name}</echo>
                <echo>$archive.path         = ${archive.path}</echo>
                <echo>$relative.path1       = ${relative.path1}</echo>
                <echo>$relative.path2       = ${relative.path2}</echo>
                <echo>$name.short           = ${name.short}</echo>
                -->
                <outofdate>
                    <sourcefiles>
                        <filelist>
                            <file name="@{file.path.name}"/>
                        </filelist>
                    </sourcefiles>
                    <mapper dir="." type="glob" from="*.x3d" to="*.x3db"/>
                    <sequential>
                        <!-- process individual files here -->
                        <echo>${archive.path}/${relative.path1}/${relative.path2}/${name.short}.x3d processing with Xj3D for .x3db binary compression</echo>
                        <!-- Xj3D converter tends to lock up Netbeans unless forked -->
                        <java classname="xj3d.filter.CDFFilter" fork="false" dir=".">
                            <classpath>
                                <pathelement path="${classpath}"/>
                                <fileset dir="${xj3d.dir}">
                                    <include name="${xj3d.cadfilter.jar}"/>
                                </fileset>
                                <fileset dir="${xj3d.dir}">
                                    <include name="xj3d-all_2.0.0.jar"/>
                                </fileset>
                            </classpath>
                            <jvmarg value="-Xmx450M"/>
                            <jvmarg value="-Xbootclasspath/p:${xj3d.dir}/bin"/>
                            <jvmarg value="-Dsun.java2d.noddraw=true"/>
                            <jvmarg value="-Djava.library.path=${xj3d.dir}/bin"/>
                            <arg value="Identity"/>
                            <arg value="${relative.path1}/${relative.path2}/${name.short}.x3d"/>
                            <arg value="${relative.path1}/${relative.path2}/${name.short}.x3db"/>
                        </java>
                    </sequential>
                </outofdate>
            </sequential>
        </for>
    </target>
<!--
original .x3db converter.sh invocation Xj3D SEP 2008 release:
java  -Xmx450M -Xbootclasspath/p:./bin -Dsun.java2d.noddraw=true -Djava.library.path=./bin 
-classpath .;"%Xj3D_HOME%"/apps/cadfilter/${xj3d.cadfilter.jar};"%Xj3D_HOME%"/jars/xj3d-all_2.0.0.jar xj3d.cadfilter.CDFFilter Identity %1 %2 %3 %4 %5 %6

problems and fixes documented in http://bugzilla.xj3d.org/show_bug.cgi?id=510
-->

    <target name="processScenes.captureViewpoints" description="use Xj3D to create snapshot pictures of each viewpoint">
        <for param="file.path.name">
            <path>
                <fileset refid="x3dScenes"/>
            </path>
            <sequential>
                <propertyregex
                        property="name.short"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path1"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)_archiveName_[\\/]([^\n^\\]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path2"
                        override="true"
                        input="@{file.path.name}"
                        regexp="_regexp2_"
                        select="\3"/>
                <!-- trace
                <echo></echo>
                <echo>@file.path.name       = @{file.path.name}</echo>
                <echo>$archive.path         = ${archive.path}</echo>
                <echo>$relative.path1       = ${relative.path1}</echo>
                <echo>$relative.path2       = ${relative.path2}</echo>
                <echo>$name.short           = ${name.short}</echo>
                -->
                <outofdate>
                    <sourcefiles>
                        <filelist>
                            <file name="${archive.path}/${relative.path1}/${relative.path2}/${name.short}.x3d"/>
                        </filelist>
                    </sourcefiles>
                    <!-- TODO:  targetfiles match not working.  note viewpoint image names are variations on the filename -->
                    <targetfiles>
                        <pathelement path="${archive.path}/${relative.path1}/${relative.path2}/_viewpoints/${name.short}.x3d.*.png"/>
                    </targetfiles>
                    <!--
                     outputsources="@{file.path.name}" outputtargets="${relative.path1}/${relative.path2}/_viewpoints/${name.short}.x3d.*.png"
                    <mapper dir="." type="glob" from="*.x3d" to="_viewpoints/*.png"/>
                    -->
                    <sequential>
                        <!-- process individual files here -->
                        <echo>${archive.path}/${relative.path1}/${relative.path2}/${name.short}.x3d processing with Xj3D -captureViewpoints</echo>
                        <mkdir dir="${relative.path1}/${relative.path2}/_viewpoints"/>
                        <java classname="xj3d.browser.Xj3DBrowser" fork="yes" dir=".">
                            <classpath>
                                <pathelement path="${classpath}"/>
                                <fileset dir="${xj3d.dir}/apps/browser">
                                    <include name="xj3d.browser_2.0.0.jar"/>
                                </fileset>
                                <fileset dir="${xj3d.dir}">
                                    <include name="*.jar"/>
                                    <exclude name="xj3d-all.jar"/>
                                </fileset>
                            </classpath>
                            <jvmarg value="-Xmx450M"/>
                            <jvmarg value="-Dsun.java2d.noddraw=true"/>
                            <jvmarg value="-Djava.library.path=${xj3d.dir}/bin"/>
                            <jvmarg value="-Xbootclasspath/p:${xj3d.dir}/bin"/>
                            <arg value="-captureViewpoints"/>
                            <arg value="${relative.path1}/${relative.path2}/${name.short}.x3d"/>
                        </java>
                        <!-- Xj3D leaves images in same directory as file, rather than launch directory, and so move them to _viewpoints directory.  -->
                        <move todir="${relative.path1}/${relative.path2}/_viewpoints" verbose="true">
                                <fileset dir="${relative.path1}/${relative.path2}">
                                    <include name="${name.short}.x3d.*.png"/>
                                </fileset>
                        </move>
                    </sequential>
                </outofdate>
            </sequential>
        </for>
    </target>

    <target name="canonicalScenesX3dToXml" description="save each canonicalized filename.x3d as filenameCanonical.xml">
        <for param="filenames">
            <path>
                <fileset dir="." includes="**/*Canonical.x3d"/>
            </path>
            <sequential>
                <propertyregex
                    property="filename.prefix"
                    override="true"
                    input="@{filenames}"
                    regexp="([^\\]*\\){6}([^\n]*)Canonical\.x3d"
                    select="\2"/>
                <echo>Moving ${filename.prefix}Canonical.x3d to ${filename.prefix}Canonical.xml</echo>
                <move file="${filename.prefix}Canonical.x3d" tofile="${filename.prefix}Canonical.xml"/>
            </sequential>
        </for>
    </target>

    <!-- TODO:  XMLUnit test comparing Filename.x3d to FilenameCanonical.xml -->
    <target name="processScenes.canonicalX3D" description="generate canonical X3D form" depends="clean.duplicates">
        <for param="file.path.name">
            <path>
                <fileset refid="x3dScenes"/>
            </path>
            <sequential>
                <propertyregex
                        property="name.short"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path1"
                        override="true"
                        input="@{file.path.name}"
                        regexp="([^\n]*)_archiveName_[\\/]([^\n^\\]*)[\\/]([^\n]*)\.x3d"
                        select="\2"/>
                <propertyregex
                        property="relative.path2"
                        override="true"
                        input="@{file.path.name}"
                        regexp="_regexp2_"
                        select="\3"/>
                <!-- trace
                <echo></echo>
                <echo>@file.path.name       = @{file.path.name}</echo>
                <echo>$archive.path         = ${archive.path}</echo>
                <echo>$relative.path1       = ${relative.path1}</echo>
                <echo>$relative.path2       = ${relative.path2}</echo>
                <echo>$name.short           = ${name.short}</echo>
                -->
                <outofdate>
                    <sourcefiles>
                        <filelist>
                            <file name="@{file.path.name}"/>
                        </filelist>
                    </sourcefiles>
                    <mapper dir="." type="glob" from="*.x3d" to="*Canonical.xml"/>
                    <sequential>
                        <copy file="@{file.path.name}" toFile="${archive.path}/${relative.path1}/${relative.path2}/${name.short}Canonical.xml"/> <!-- verbose="true" -->
                        <echo>@{file.path.name} processed with org.web3d.x3d.tools.x3db.X3dCanonicalizer</echo>
                        <!-- canonicalX3D is locally defined macro -->
                        <canonicalX3D scene="${archive.path}/${relative.path1}/${relative.path2}/${name.short}"/>
                        <!-- check XML header and DOCTYPE -->
                        <echo message="X3dDoctypeChecker ${archive.path}/${relative.path1}/${relative.path2}/${name.short}.x3d"/>
                        <java classname="org.web3d.x3d.tools.X3dDoctypeChecker" classpath="${c14n.dir}/${c14n.jar}">
                            <arg value="${archive.path}/${relative.path1}/${relative.path2}/${name.short}.x3d"/>
                            <!-- <arg value="-verbose"/> -->
                        </java>
                    </sequential>
                </outofdate>
            </sequential>
        </for>
    </target>
    
    <target name="X3dToXhtml.xsltNative" description="pretty print all .x3d examples as .html" >
        <xslt destdir="." style="${stylesheet.dir}/X3dToXhtml.xslt" force="true">
            <include name="_subdir_/*.x3d"/>
            <mapper type="glob" from="*.x3d" to="*.html"/>
            <xmlcatalog refid="X3dCatalog"/>
        </xslt>
    </target>

    <!-- warning:  xalan crashes Netbeans 5.0 completely without leaving a trace -->
    <target name="X3dToVrml97.xsltNative" description="convert all .x3d examples to .wrl" >
        <xslt destdir="." style="${stylesheet.dir}/X3dToVrml97.xslt" force="true">
            <include name="_subdir_/*.x3d"/>
            <mapper type="glob" from="*.x3d" to="*.wrl"/>
            <xmlcatalog refid="X3dCatalog"/>
        </xslt>
    </target>

    <!-- Xalan throws exception but then continues to completion:
         java.lang.ClassCastException: com.sun.org.apache.xalan.internal.xsltc.compiler.Variable  -->
    <target name="X3dToX3dvClassicVrmlEncoding.xsltNative" description="convert all .x3d examples to .x3dv" >
        <xslt destdir="." style="${stylesheet.dir}/X3dToX3dvClassicVrmlEncoding.xslt" force="true">
            <classpath path="${cp}"/>
            <include name="_subdir_/*.x3d"/>
            <mapper type="glob" from="*.x3d" to="*.x3dv"/>
            <xmlcatalog refid="X3dCatalog"/>
        </xslt>
    </target>

    <path id="project-classpath">
        <pathelement location="."/>
        <pathelement location="../../../tools/CreateContentCatalog/CreateContentCatalog.jar"/>
        <pathelement location="../../../tools/canonical/lib/log4j-1.2.15.jar"/>
        <!-- ensure system JAVA_HOME points to JDK -->
        <pathelement location="${java.home}/lib/rt.jar"/>
        <!--
            <fileset dir="${env.JWSDP_HOME}/jaxp/lib" includes="*.jar"/>
            <pathelement location="${jaxp.apis}/jaxp-api.jar"/>
            <pathelement location="${jaxp.lib}/sax.jar"/>
            <pathelement location="${jaxp.lib}/dom.jar"/>
            <pathelement location="${jaxp.lib}/xercesImpl.jar"/>
            <pathelement location="${jaxp.lib}/xalan.jar"/>
            <pathelement location="${samples.build.dir}/"/>
            -->
    </path>

    <target name="catalog" 
            depends="catalog.builder,catalog.generateHtmlPages,catalog.generateXMLSpyProject" 
            description="generate catalog, XMLSPY project and HTML pages">
        <!-- revalidate when complete so that any error messages are easily visible -->
        <xmlvalidate file="ContentCatalog${archive.name}.xml" failonerror="true"  warn="true" lenient="yes"/>
        <xmlvalidate file="ContentCatalog${archive.name}.xml" failonerror="false" warn="true"/>
    </target>

    <target name="catalog.builder" depends="clean.duplicates" description="generate HTML and XMLSPY catalogs">
        <!-- TODO: modify filenames by adding timestamp -->
        <copy todir="_archive" verbose="true">
            <fileset dir=".." includes="ContentCatalog${archive.name}.xml,ContentCatalogExamples${archive.name}.spp"/>
        </copy>
        
        <!-- Will be over-ridden if called from catalog.server -->
        <property name="local.dtd" value="-localDTD"/>
        <java classname="ContentCatalogBuilder" fork="yes">
            <classpath refid="project-classpath"/>
            <arg value="${local.dtd}"/>
            <arg value="../${archive.name}"/>
            
            <!-- larger memory setting to avoid heap errors
            <jvmarg value="-XX:MaxDirectMemorySize=500M"/> -->
            <jvmarg value="-Xmx450M"/>
            <jvmarg value="-XX:PermSize=32m"/>
            <jvmarg value="-XX:MaxPermSize=256m"/>
        </java>
        <move file="ContentCatalog.xml" tofile="ContentCatalog${archive.name}.xml" overwrite="true" failonerror="false" verbose="true"/>
        <echo message="check well-formedness and validate ContentCatalog${archive.name}.xml"/>
        <xmlvalidate file="ContentCatalog${archive.name}.xml" failonerror="true"  warn="true" lenient="yes"/>
        <xmlvalidate file="ContentCatalog${archive.name}.xml" failonerror="false" warn="true"/>
    </target>

    <target name="catalog.generateHtmlPages" description="generate HTML pages for entire catalog">
        <echo message="check well-formedness ../../../tools/CreateContentCatalog/CreateContentCatalogPages.xslt"/>
        <xmlvalidate file="../../../tools/CreateContentCatalog/CreateContentCatalogPages.xslt" failonerror="true" warn="true" lenient="yes"/>

        <echo message="generate complete set of HTML pages for ${archive.name} examples archive"/>
        <!-- cd    ../examples/; pwd; $(SAXON) -t ContentCatalog.xml $(CONTENT_DRIVE)/$(CONTENT_DIR)/../tools/CreateContentCatalog/CreateContentCatalogPages.xslt -->
        <!-- TODO: Xj3D -captureViewpoint option, selectively adding corresponding links in output HTML -->
        <java classname="net.sf.saxon.Transform" classpath="${saxon.dir}/${saxon.jar};." fork="false">
            <arg value="-t"/>  <!-- timing information -->
            <arg value="-warnings:recover"/> <!-- recover after writing a warning message -->
            <arg value="ContentCatalog${archive.name}.xml"/>
            <arg value="../../../tools/CreateContentCatalog/CreateContentCatalogPages.xslt"/>
        </java>
    </target>
        
  <!-- Warning:  the next two tasks are only used on subversion servers or by other people building catalogs
         who are not under local version control for CreateContentCatalog -->
    <target name="catalog.retrieve.CreateContentCatalog.jar"
        description="retrieve CreateContentCatalog.jar from SourceForge subversion to support local build">
        <get src="http://x3d.svn.sourceforge.net/viewvc/*checkout*/x3d/www.web3d.org/x3d/tools/CreateContentCatalog/CreateContentCatalog.jar" 
             dest="../../../tools/CreateContentCatalog/CreateContentCatalog.jar"/>
        <copy toDir="${basedir}" 
              file="../../../tools/CreateContentCatalog/CreateContentCatalog.jar"/>
    </target>

    <target name="catalog.server" 
            depends="catalog.retrieve.CreateContentCatalog.jar" 
            description="utility task for subversion server-side regeneration of content catalog">
       <antcall target="catalog.builder" inheritAll="true">
           <param name="local.dtd" value=""/>
       </antcall>            
    </target>

    <target name="catalog.generateXMLSpyProject" description="generate XMLSPY catalog">
        <echo message="check well-formedness ../../../stylesheets/ContentCatalogToXmlSpyProject.xslt"/>
        <xmlvalidate file="../../../stylesheets/ContentCatalogToXmlSpyProject.xslt" failonerror="true" warn="true" lenient="yes"/>
        <echo message="generate XML Spy catalog ContentCatalog${archive.name}.spp"/>
        <xslt   in="ContentCatalog${archive.name}.xml"
                out="ContentCatalog${archive.name}.spp"
                style="../../../stylesheets/ContentCatalogToXmlSpyProject.xslt"
                reloadstylesheet="yes" force="yes">
            <classpath path="${cp}"/>
        </xslt>
        <echo message="validate ContentCatalog${archive.name}.spp"/>
        <xmlvalidate file="ContentCatalog${archive.name}.spp" failonerror="false" warn="true" lenient="yes"/>
    </target>

    <target name="zip" depends="clean.backups,clean.duplicates" description="generate .zip distribution">
        <property name="zipFileName" value="../X3dExamples${archive.name}.zip"/>
        <!-- TODO:  figure out
        <if>
            <equals arg1="${archive.name}" arg2="Savage">
                <move file="Documents and Settings/All Users/Start Menu/Programs/X3D Extensible 3D Graphics/Savage Modeling Analysis Language (SMAL) metadata.lnk"/>
                <echo message="SavageLinks found"/>
            </equals>
        </if>
        -->
        <zip destfile="${zipFileName}" >
            <zipfileset dir="../.." prefix="www.web3d.org/x3d/content/">
                <include name="icons/*.*"/>
                <include name="images/x3d2-s.gif"/>
                <include name="images/web3d_logo2.png"/>
                <include name="../tools/CreateContentCatalog/ContentCatalog.dtd"/>
                <exclude name="CVS/*"/>
                <exclude name=".svn/*"/>
                <exclude name="_new*.*"/>
                <exclude name="*.bak"/>
                <exclude name="Thumbs.db"/>
                <exclude name="*.$$$$$$"/>
                <exclude name="**/*.$$$$$$"/><!-- escape $ as $$ -->
                <!-- TODO:  debug _archive filters -->
                <exclude name="_archive/*"/>
                <exclude name="**/_archive"/>
                <exclude name="**/_archive/*"/>
                <exclude name="_schematron"/>
                <exclude name="**/_schematron"/>
                <exclude name="**/_schematron/*"/>
                <exclude name="hide/*"/>
                <exclude name="**/hide"/>
                <exclude name="**/hide/*"/>
                <exclude name="nbproject/*"/>
                <exclude name="**/nbproject/*"/>
                <exclude name="**/CVS/*"/>
                <exclude name="**/.svn/*"/>
                <exclude name="**/_new*.*"/>
                <exclude name="**/*.bak"/>
                <exclude name="**/Thumbs.db"/>
            </zipfileset>
            <zipfileset dir="../../../../.." prefix="">
                <include name="index${archive.name}.localRedirect.html"/>
            </zipfileset>
            <zipfileset dir=".." prefix="www.web3d.org/x3d/content/examples/">
                <exclude name="index*Redirect.html"/>
                <include name="images/*.*"/>
                <include name="*.xml"/>
                <include name="Makefile"/>
                <include name="*.html"/>
                <include name="license.*"/>
                <include name="Hello*.*"/>
                <include name="earth-topo*.*"/>
                <include name="newScene.*"/>
                <include name="newHtmlPageWithX3dObject.html"/>
                <include name="newEcmascript.js"/>
                <include name="newX3dScript.java"/>
                <include name="*.x3d"/>
                <include name="*.xml"/>
                <include name="*.html"/>
                <include name="*.wrl"/>
                <include name="*.x3dv"/>
                <include name="*.gif"/>
                <include name="*.jpg"/>
                <include name="*.png"/>
                <include name="*.txt"/>
                <include name="*.pdf"/>
                <include name="*.ppt"/>
                <include name="_pages/*.html"/>
                <include name="_svg/*.svg"/>
                <exclude name="CVS/*"/>
                <exclude name=".svn/*"/>
                <exclude name="_new*.*"/>
                <exclude name="*.bak"/>
                <exclude name="Thumbs.db"/>
                <exclude name="*.$$$$$$"/>
                <exclude name="**/*.$$$$$$"/><!-- escape $ as $$ -->
                <exclude name="_archive/*"/>
                <exclude name="**/_archive"/>
                <exclude name="**/_archive/*"/>
                <exclude name="_schematron"/>
                <exclude name="**/_schematron"/>
                <exclude name="**/_schematron/*"/>
                <exclude name="hide/*"/>
                <exclude name="**/hide"/>
                <exclude name="**/hide/*"/>
                <exclude name="nbproject/*"/>
                <exclude name="**/nbproject/*"/>
                <exclude name="**/CVS/*"/>
                <exclude name="**/.svn/*"/>
                <exclude name="**/_new*.*"/>
                <exclude name="**/*.bak"/>
                <exclude name="**/Thumbs.db"/>
                <exclude name="Savage/SoundEffects/SavageSoundReadme.html"/>
            </zipfileset>
            <!-- windows shortcuts for this archive, no longer included
            <zipfileset dir="../../../../..">
                <include name="Documents and Settings/All Users/Start Menu/Programs/X3D Extensible 3D Graphics/X3D Examples/${archive.name} examples.lnk"/>
                <include name="WINDOWS/Start Menu/Programs/X3D Extensible 3D Graphics/X3D Examples/${archive.name} examples.lnk"/>
                <include name="WINDOWS/Profiles/All Users/Start Menu/Programs/X3D Extensible 3D Graphics/X3D Examples/${archive.name} examples.lnk"/>
                <include name="WINNT/Profiles/All Users/Start Menu/Programs/X3D Extensible 3D Graphics/X3D Examples/${archive.name} examples.lnk"/>
            </zipfileset>
            -->
            <zipfileset dir="." prefix="www.web3d.org/x3d/content/examples/${archive.name}/">
                <include name="*.xml"/>
                <include name="*.spp"/>
                <include name="Makefile"/>
                <include name="*.html"/>
                <include name="license.*"/>
                <include name="Hello*.*"/>
                <include name="earth-topo*.*"/>
                <include name="newScene.*"/>
                <include name="*/**"/> <!-- all subdirectories -->
                <!-- intermediate directories on 2-level archives hold nothing but directories, no files to match -->
                <include          name="*.x3d"/>
                <include name="_subdir_/*.x3d"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.js"/>
                <include name="_subdir_/*.js"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.xml"/>
                <include name="_subdir_/*.xml"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.dtd"/>
                <include name="_subdir_/*.dtd"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.xsd"/>
                <include name="_subdir_/*.xsd"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.html"/>
                <include name="_subdir_/*.html"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.wrl"/>
                <include name="_subdir_/*.wrl"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.x3dv"/>
                <include name="_subdir_/*.x3dv"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.gif"/>
                <include name="_subdir_/*.gif"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.jpg"/>
                <include name="_subdir_/*.jpg"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.png"/>
                <include name="_subdir_/*.png"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.txt"/>
                <include name="_subdir_/*.txt"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.pdf"/>
                <include name="_subdir_/*.pdf"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.ppt"/>
                <include name="_subdir_/*.ppt"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.mpg"/>
                <include name="_subdir_/*.mpg"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.mpeg"/>
                <include name="_subdir_/*.mpeg"/><!-- ${numberOfSections} level down only -->
                <include          name="*.xls"/>
                <include name="_subdir_/*.xls"/><!-- ${numberOfSections} level down only -->
                <include          name="*.wmv"/>
                <include name="_subdir_/*.wmv"/> <!-- ${numberOfSections} level down only -->
                <include          name="*.au"/>
                <include name="_subdir_/*.au"/>  <!-- ${numberOfSections} level down only -->
                <!-- autogenerated html-catalog content -->
                <include name="_pages/*.html"/>
                <include   name="*/_pages/*.html"/>
                <include name="*/*/_pages/*.html"/>
                <include     name="_svg/*.svg"/>
                <include   name="*/_svg/*.svg"/>
                <include name="*/*/_svg/*.svg"/>
                <exclude name="_new*.*"/>
                <exclude name="*.bak"/>
                <exclude name="Thumbs.db"/>
                <exclude name="*.$$$$$$"/>
                <exclude name="**/*.$$$$$$"/><!-- escape $ as $$ -->
                <exclude name="_archive/*"/>
                <exclude name="**/_archive"/>
                <exclude name="**/_archive/*"/>
                <exclude name="_schematron"/>
                <exclude name="**/_schematron"/>
                <exclude name="**/_schematron/*"/>
                <exclude name="nbproject/*"/>
                <exclude name="**/nbproject/*"/>
                <exclude name="CVS/*"/>
                <exclude name="**/CVS/*"/>
                <exclude name=".svn/*"/>
                <exclude name="**/.svn/*"/>
                <exclude name="**/_new*.*"/>
                <exclude name="**/*.bak"/>
                <exclude name="**/Thumbs.db"/>
                <exclude name="SoundEffects/**/*.*"/><!-- Savage archive -->
            </zipfileset>
        </zip>
        <!--  TODO: fix <length>
        <length file="${zipFileName}" property="${zipFileName}.length" />
        <echo>${zipFileName} length="${zipFileName}.length</echo> -->
        <echo>${zipFileName} complete</echo>
    </target>

    <!-- TODO:  targets for timestamp, makeWindowsShortcuts, others from Makefile -->

    <!--
    <path id="classpath">
        <fileset dir="${saxon.dir}" includes="*.jar"/>
    </path>
    <property name="cp" location="${classpath}"/>
    <target name="newScene.error" description="Copy newScene.x3d example from common example-archives parent and convert to other encodings.  Warning:  does not override Xalan in Netbeans and fails." >
        <echo>xslt classpath=${cp}</echo>
        <delete>
            <fileset dir="." includes="newScene.*"/>
        </delete>
        <copy todir=".">
            <fileset dir=".." includes="newScene.x3d"/>
        </copy>
        <xmlvalidate file="newScene.x3d" failonerror="true" warn="true"/>
        <xslt in="newScene.x3d" out="newScene.html" style="${stylesheet.dir}/X3dToXhtml.xslt"  reloadstylesheet="yes">
                <classpath path="${cp}"/>
        </xslt>
        <xslt in="newScene.x3d" out="newScene.wrl"  style="${stylesheet.dir}/X3dToVrml97.xslt" reloadstylesheet="yes">
                <classpath path="${cp}"/>
        </xslt>
        <xslt in="newScene.x3d" out="newScene.x3dv" style="${stylesheet.dir}/X3dToX3dvClassicVrmlEncoding.xslt" reloadstylesheet="yes" basedir="." processor="trax" destdir="." >
                <classpath path="${saxon.dir}/${saxon.jar}"/>
        </xslt>
    </target>
-->

</project>
