<?xml version="1.0" encoding="UTF-8"?>
<!-- Apache Ant script to build spec.
     Philippe Le Hegaret, W3C -->
      
<project name="TimedText" default="main" basedir=".">
    <path id="saxon8.classpath">
        <pathelement location="saxon8/saxon8.jar"/>
    </path>
    <property name="htmlOutputDir" value="./"/>
    <property name="stylesheet" value="xmlspec-ttaf1-dfxp.xsl"/>
    <property name="glossary" value="extract-glist.xsl"/>
	<property name="generateBPlist" value="generateBPlist.xsl"/>
    <property name="diffformat" value="diffspec.xsl"/>
    <property name="last-public-draft" value="20070706"/>
    
    <property name="jing.jar" value="${basedir}/jing/jing.jar"/>
    <property name="rnc.dir" value="${basedir}/rnc"/>
    <property name="rnc.schema" value="${rnc.dir}/ttaf1-dfxp.rnc"/>
    <property name="profiles.dir" value="${basedir}/profiles"/>

    <patternset id="escapable">
      <include name="examples/*.xml"/>
      <include name="rnc/*.rnc"/>
      <include name="xsd/*.xsd"/>
      <include name="profiles/*.xml"/>
    </patternset>

    <patternset id="escaped">
      <include name="examples/*.esc"/>
      <include name="rnc/*.esc"/>
      <include name="xsd/*.esc"/>
      <include name="profiles/*.esc"/>
    </patternset>

    <target name="clean-escapes" description="Clean escaped entites.">
      <delete quiet="true">
	<fileset dir="${basedir}">
	  <patternset refid="escaped"/>
	</fileset>
      </delete>
    </target>

    <target name="clean" depends="clean-escapes">
        <delete quiet="true" file="ttaf1-dfxp.html"/>
    </target>

    <target name="validate-schema-rnc" description="Validates DFXP's RNC Schema.">
        <java fork="true" jar="${jing.jar}" dir="${rnc.dir}">
            <arg value="-c"/>
            <arg value="ttaf1-dfxp.rnc"/>
        </java>
    </target>

    <target name="validate-profile-transformation" description="Validates transformation profile.">
        <java fork="true" jar="${jing.jar}">
            <arg value="-c"/>
            <arg value="${rnc.schema}"/>
            <arg value="${profiles.dir}/dfxp-presentation.xml"/>
        </java>
    </target>

    <target name="validate-profile-presentation" description="Validates presentation profile.">
        <java fork="true" jar="${jing.jar}">
            <arg value="-c"/>
            <arg value="${rnc.schema}"/>
            <arg value="${profiles.dir}/dfxp-presentation.xml"/>
        </java>
    </target>

    <target name="validate-profile-full" description="Validates full profile.">
        <java fork="true" jar="${jing.jar}">
            <arg value="-c"/>
            <arg value="${rnc.schema}"/>
            <arg value="${profiles.dir}/dfxp-full.xml"/>
        </java>
    </target>

    <target name="validate-profiles"
	    depends="validate-profile-transformation,validate-profile-presentation,validate-profile-full"/>

    <target name="validate-xsl" description="Validates all XML files.">
        <xmlvalidate lenient="true">
            <fileset dir="." includes="*.xsl"/>
        </xmlvalidate>
    </target>

    <target name="validate-svg" description="Validates all SVG files.">
        <xmlvalidate lenient="false" warn="yes">
            <fileset dir="." includes="*.svg"/>
        </xmlvalidate>
    </target>

    <target name="build-escapes" description="Generate escaped entites.">
      <apply executable="sed">
        <arg value="-f"/>
        <arg value="escape.sed"/>
	<fileset dir="${basedir}">
	  <patternset refid="escapable"/>
	</fileset>
	<redirector>
	  <outputmapper>
    	    <mapper type="glob" from="*" to="*.esc"/>
	  </outputmapper>
	</redirector>
      </apply>
    </target>

    <target name="validate-tt-specs" description="Validates all Timed Text spec files."
        depends="build-escapes">
        <xmlvalidate lenient="false" warn="yes" file="ttaf1-dfxp.xml"/>
    </target>

    <target name="validate" depends="validate-xsl,validate-svg,validate-tt-specs,validate-schema-rnc,validate-profiles"/>

    <target name="updateAcks"
        description="Update acknowledgements. Before running this, 
	update ackcurrent.xml via  and ackold.xml
	via http://www.w3.org/2000/09/dbwg/details?group=34314&amp;former=1&amp;public=1 .">
        <get src="http://www.w3.org/2000/09/dbwg/details?group=34314&amp;public=1" dest="ackcurrent.xml"/>
        <get src="http://www.w3.org/2000/09/dbwg/details?group=34314&amp;former=1&amp;public=1" dest="ackold.xml"/>
        <java fork="true" classname="net.sf.saxon.Transform">
            <classpath refid="saxon8.classpath"/>
            <arg value="-o"/>
            <arg value="acknowledgements-current.txt"/>
            <arg value="ackcurrent.xml"/>
            <arg value="generate-acknowledgements.xsl"/>
            <arg value="participating=1"/>
        </java>
        <java fork="true" classname="net.sf.saxon.Transform">
            <classpath refid="saxon8.classpath"/>
            <arg value="-o"/>
            <arg value="acknowledgements-old.txt"/>
            <arg value="ackold.xml"/>
            <arg value="generate-acknowledgements.xsl"/>
            <arg value="participating=0"/>
        </java>
    </target>

    <target name="html" description="Transforms xml into html.">
        <echo>Generating ttaf1-dfxp.html</echo>
        <java fork="true" classname="net.sf.saxon.Transform">
            <classpath refid="saxon8.classpath"/>
            <arg value="-o"/>
            <arg value="${htmlOutputDir}ttaf1-dfxp.html"/>
            <arg value="ttaf1-dfxp.xml"/>
            <arg value="${stylesheet}"/>
            <arg value="showAssertions=true"/>
        </java>    
    </target>

    <path id="diffmk.classpath">
        <pathelement location="${basedir}/diffmk.jar"/>
        <pathelement location="${basedir}/DiffMk.properties"/>
    </path>
    <target name="generateXMLdiff">
  <java classname="com.sun.xtc.diffmk.DiffMk" fork="true">
            <arg value="-doctype"/>
            <arg value="xmlspec"/>
            <arg value="-diff"/>
            <arg value="both"/>
            <arg value="-words"/>
            <arg value="tt-tr${last-public-draft}.xml"/>
            <arg value="ttaf1-dfxp.xml"/>
            <arg value="tt-diff${last-public-draft}.xml"/>
            <classpath path="diffmk.jar:DiffMk.properties"> </classpath>
        </java>
    </target>
    <target name="generateHTMLdiff">
        <java fork="true" classname="net.sf.saxon.Transform">
            <classpath refid="saxon8.classpath"/>
            <arg value="-o"/>
            <arg value="${htmlOutputDir}tt-diff${last-public-draft}.html"/>
            <arg value="tt-diff${last-public-draft}.xml"/>
            <arg value="diffspec.xsl"/>
        </java>
    </target>

    <target name="postprocess-diff">
      <java fork="true" classname="net.sf.saxon.Transform">
            <classpath refid="saxon8.classpath"/>
            <arg value="-o"/>
            <arg value="temp-tt-diff${last-public-draft}.xml"/>
            <arg value="tt-diff${last-public-draft}.xml"/>
            <arg value="diff-postprocess.xsl"/>
        </java>
        <copy tofile="tt-diff${last-public-draft}.xml"
            file="temp-tt-diff${last-public-draft}.xml" overwrite="true"/>
        <delete file="temp-tt-diff${last-public-draft}.xml"/>
    </target>

    <target name="diff" depends="generateXMLdiff, postprocess-diff, generateHTMLdiff"/>

    <target name="changelog" description="Update the CVS change log to be added into the specification">
      <!--        <cvschangelog destfile="changelog.xml"/> -->
      <get src="http://www.w3.org/2000/06/webdata/xslt?xslfile=http%3A%2F%2Fwww.w3.org%2F2008%2F05%2Fcvswebrss.xsl&amp;xmlfile=http%3A%2F%2Fcgi.w3.org%2Fcgi-bin%2Ftidy%3FdocAddr%3Dhttp%253A%252F%252Fdev.w3.org%252Fcvsweb%252F2008%252Fws%252Ftt%252Fttaf1-dfxp.xml%26forceXML%3Don" dest="changelog.xml"/>
    </target>

    <target name="generate" description="Generate the specification without updating changelog and acknowledgments sections"
	    depends="validate-tt-specs,html">
      <echo>WARNING: changelog.xml and acknowledgments.xml MAY be out of date. Use "main" target if necessary.</echo>
    </target>
    
    <target name="main" description="Generate the specification for a CVS commit"
	    depends="changelog,validate-tt-specs,html">
<!--	    depends="updateAcks,changelog,validate-tt-specs,html"> -->
      <echo>ttaf1-dfxp.html is ready for CVS commit</echo>
      <echo>Use target "generate" to avoid regenerating changelog.xml and acknowledgments.xml</echo>
    </target>

</project>

