<?xml version="1.0"?>
<project default="all" basedir=".">

  <xmlcatalog id="DTDs">
    <dtd publicid="-//OASIS//DTD DocBook XML V4.1.2//EN"
         location="docbook/docbookx.dtd"/>
    <dtd publicid="-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
         location="web-app_2_2.dtd"/>
    <dtd publicid="-//Cail Lomecb//DTD Colorer HRC take5//EN"
         location="../2003/hrc.dtd"/>
    <dtd publicid="-//Cail Lomecb//DTD Colorer HRD take5//EN"
         location="../2003/hrd.dtd"/>
    <dtd publicid="-//Cail Lomecb//DTD Colorer CATALOG take5//EN"
         location="../2003/catalog.dtd"/>
  </xmlcatalog>

  <property name='docbook-dir-url' value='file:/${docbook-dir}'/>

  <target name="init">
    <uptodate property="pdf.required" srcfile='hrc-ref.docbook' targetfile="hrc-ref.pdf"/>
    <uptodate property="html.required" srcfile='hrc-ref.docbook' targetfile="index.html"/>

    <available file='${docbook-dir}/template/titlepage.xsl' property='xslt-exists'/>
    <available classname="org.apache.fop.apps.Fop" property='pdf-exists'>
      <classpath>
        <pathelement path="${java.class.path}"/>
        <pathelement location="${fop-dir}/build/fop.jar"/>
        <pathelement location="${fop-dir}/lib/avalon-framework-cvs-20020806.jar"/>
        <pathelement location="${fop-dir}/lib/batik.jar"/>
      </classpath>
    </available>
    <condition property='hrc-ref-available'>
      <and>
        <isset property='xslt-exists'/>
        <isset property='pdf-exists'/>
      </and>
    </condition>

    <antcall target='hrc-ref-check'/>
  </target>

  <target name="hrc-ref-check" unless='hrc-ref-available'>
    <echo>
* ********** WARNING!!! *************
* Can't find hrc-ref generation dependencies.
* Check your paths to the docbook XSL Transformations,
* and to the FOP PDF processor:
*
* DocBook XSL: ${docbook-dir}
* Apache  FOP: ${fop-dir}
*
* If you have these packages, please fix 'build.properties'
* file in colorer root directory and restart building.
* You can ignore this build error, removing 'fail-on-badpaths'
* property from the 'build.properties' file.
    </echo>
    <fail if='fail-on-badpaths'>
******** Build stopped because of bad DocBook XSLT/Apache FOP paths.
    </fail>
  </target>

  <target name="merge">
    <xslt in='hrc-ref.docbook' out='hrc-ref.docbook-merged' style='db-merge.xsl'>
      <xmlcatalog refid="DTDs"/>
    </xslt>
  </target>

  <target name="pdf" if='hrc-ref-available' depends='init, merge' description='Builds PDF presentation' unless='pdf.required'>
    <xslt in='fo-titlepage.tmpl' out='fo-titlepage.xsl' style='${docbook-dir}/template/titlepage.xsl'>
      <xmlcatalog refid="DTDs"/>
    </xslt>

    <copy file='fo-hrc-ref.xsl' tofile='fo-hrc-ref-temporary.xsl' overwrite='true'>
     <filterset>
       <filter token="docbook-dir" value="${docbook-dir-url}"/>
      </filterset>
    </copy>
    <xslt in='hrc-ref.docbook-merged' out='hrc-ref.fo' style='fo-hrc-ref-temporary.xsl'>
      <xmlcatalog refid="DTDs"/>
    </xslt>
    <delete file='fo-hrc-ref-temporary.xsl'/>

    <java classname="org.apache.fop.apps.Fop" fork="true" failonerror='true'>
      <arg value="hrc-ref.fo"/>
      <arg value="hrc-ref.pdf"/>
      <classpath>
        <pathelement path="${java.class.path}"/>
        <pathelement location="${fop-dir}/build/fop.jar"/>
        <pathelement location="${fop-dir}/lib/avalon-framework-cvs-20020806.jar"/>
        <pathelement location="${fop-dir}/lib/batik.jar"/>
      </classpath>
   </java>
  </target>

  <target name="html" if='xslt-exists' depends='init, merge' description='Builds HTML presentation' unless='html.required'>
    <xslt in='html-titlepage.tmpl' out='html-titlepage.xsl' style='${docbook-dir}/template/titlepage.xsl'>
      <xmlcatalog refid="DTDs"/>
    </xslt>
    <copy file='html-hrc-ref.xsl' tofile='html-hrc-ref-temporary.xsl' overwrite='true'>
     <filterset>
       <filter token="docbook-dir" value="${docbook-dir-url}"/>
     </filterset>
    </copy>
    <xslt in='hrc-ref.docbook-merged' out='index.html' style='html-hrc-ref-temporary.xsl'>
      <xmlcatalog refid="DTDs"/>
    </xslt>
    <delete file='html-hrc-ref-temporary.xsl'/>
  </target>

  <target name="zip" description='Creates zip distribution file'>
    <zip destfile="hrc-ref.zip"
         basedir="."
         includes="db*,fo*,html*,hrc-ref.docbook,build.xml"
    />
  </target>

  <target name="all" depends='init, html, pdf, zip' description='Builds all target versions'>
  </target>

  <target name="clean" description='Removes all autogenerated files'>
    <delete>
      <fileset dir='.' includes='hrc-ref.zip,fo-titlepage.xsl,hrc-ref.docbook-merged,hrc-ref.fo,hrc-ref.pdf,html-titlepage.xsl,index.html,*-temporary*'/>
    </delete>
  </target>

</project>
