<project name="buildChunkedHTML" default="checkifuptodate">
  <!-- PARAMETERS
    item      - The identification name of the item.
    inputdir  - The directory where the item's source xml is located.
    outputdir - The directory where one desires the output html to go.
    graphics.prefix - The prefix to where callout graphics and admonitions are located, e.g (../../)
  -->
  <target name="buildChunkedHTML" if="requires.build" description="Builds HTML output for an item">
    <!-- Load in properties -->
    <loadproperties srcFile="ant.properties"/>
    <available file="${inputdir}/files" type="dir" property="files.available"/>

    <!-- Make the output directory -->
    <mkdir dir="${outputdir}"/>

    <!-- Copy any necessary files -->
    <antcall target="copyfiles"/>

    <!-- Resolve any xincludes -->
    <exec executable="xmllint">
      <arg line="--xinclude" /> 
      <arg line="${inputdir}/${item}.xml" /> 
      <arg line="-o ${src}/${item}.xml" /> 
    </exec>

    <exec executable="java">
      <arg line="-Djavax.xml.parsers.DocumentBuilderFactory=org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/>
      <arg line="-Djavax.xml.parsers.SAXParserFactory=org.apache.xerces.jaxp.SAXParserFactoryImpl"/>
      <arg line="-Djavax.xml.transform.TransformerFactory=com.icl.saxon.TransformerFactoryImpl"/>
      <arg line="com.icl.saxon.StyleSheet"/>
      <arg line="-x com.sun.resolver.tools.ResolvingXMLReader"/>
      <arg line="${src}/${item}.xml"/>
      <arg line="${xhtml.chunked.output.stylesheet}"/>
      <arg line="base.dir=&quot;${outputdir}/segmentedhtml/&quot;"/>
      <arg line="admon.graphics.path=&apos;${graphics.prefix}images/&apos;"/>
      <arg line="callout.graphics.path=&apos;${graphics.prefix}images/callouts/&apos;"/>
    </exec>

    <!--
    <exec executable="xsltproc">

       XXX remove % between - and - before stringparam below if uncomment
      <arg line="-%-stringparam admon.graphics.path ${graphics.prefix}images/"/>
      <arg line="-%-stringparam callout.graphics.path ${graphics.prefix}images/callouts/"/>
      <arg line="-%-stringparam base.dir ${outputdir}/segmentedhtml/"/>
      <arg line="${xhtml.chunked.output.stylesheet}"/>
      <arg line="${src}/${item}.xml"/>
    </exec>
    -->

    <!-- cleanup -->
    <delete file="${src}/${item}.xml"/>
  </target>

  <target name="copyfiles" if="files.available" description="Copies needed files">
    <echo>Copying required files for ${item} from ${inputdir} to ${outputdir}</echo>
    <copy todir="${outputdir}/segmentedhtml/files"><fileset dir="${inputdir}/files"/></copy>
  </target>

  <target name="checkifuptodate" description="Checks if this project is uptodate and source is available">
    <condition property="requires.build">
      <and>
        <available file="${inputdir}/${item}.xml"/>
        <or>
          <not><available file="${outputdir}/${item}.xml"/></not>
          <uptodate targetfile="${inputdir}/${item}.xml" srcfile="${outputdir}/${item}.xml"/>
        </or>
      </and>
    </condition>
    <antcall target="buildChunkedHTML"/>
  </target>
</project>

