<?xml version="1.0" encoding="UTF-8"?>
<!-- note it is intended that this file be used in a directory above this distribution directory -->
<project name="ivoapub" default="formatdoc">
	<tstamp></tstamp>
	<property name="ivoname" value="ivoapub"/><!-- set this to the nickname of the document -->
     <property name="docversion" value="1.0"/>
     <property name="pubstatus" value="NOTE"/><!-- set to the status of the document WD, PR, REC, NOTE -->
	<property name="docdate"  value="${DSTAMP}"/><!--set this manually when the final publication date is decided-->
     
     <!-- the location of latex/bibtex binaries -->
     <property name="latexlocation" location="/opt/local/bin"/>
     <!-- the location of a binary FOP distribution -->
     <property name="fop.home" value="/opt/packages/fop-1.0"/>

	<!-- ================================= 
          target: createdoc              
         ================================= -->
	<target name="formatdoc" description="update TOC, numbering etc">
   
		<copy file="${ivoname}.html" tofile="${ivoname}-old.html" overwrite="true"/> <!-- for safety in case xslt screws up -->
		<xslt style="ivoadoc/ivoarestructure.xslt" in="${ivoname}.html" out="${ivoname}-new.html" force="true" >
			<factory name="net.sf.saxon.TransformerFactoryImpl" />
			<param name="ivoname" expression="${ivoname}"/> 
               <param name="docversion" expression="${docversion}"/>
               <param name="pubstatus" expression="${pubstatus}"/>
	          <param name="docdate" expression="${docdate}"/>		
         <xmlcatalog>
            <catalogpath><filelist><file name="./ivoadoc/xmlcatalog/catalog.xml"/></filelist></catalogpath>
         </xmlcatalog>
		</xslt>
		<copy file="${ivoname}-new.html" tofile="${ivoname}.html" />
	</target>

	<target name="createPDF">
		<xslt style="ivoadoc/ivoa-fo.xsl" in="${ivoname}.html" out="out.fo" force="true">
			<factory name="net.sf.saxon.TransformerFactoryImpl" />
			<xmlcatalog>
				<catalogpath><filelist><file name="./ivoadoc/xmlcatalog/catalog.xml"/></filelist></catalogpath>
			</xmlcatalog>
		</xslt>
          <echo>applying fop</echo>
		<fop format="application/pdf" 
		        fofile="out.fo"
		        outfile="${ivoname}.pdf" messagelevel="DEBUG"   />
	</target>
	
   <target name="biblio"> 
      <xslt style="ivoadoc/extractcite.xslt" in="${ivoname}.html" out="${ivoname}.aux" force="true"  >
         <factory name="net.sf.saxon.TransformerFactoryImpl" />
         <param name="target" expression="aux"/>
         <xmlcatalog >
            <catalogpath>
               <filelist>
                  <file name="./ivoadoc/xmlcatalog/catalog.xml"/>
               </filelist>
            </catalogpath>
         </xmlcatalog>
      </xslt>
        <exec executable="/opt/local/bin/bibtex">
         <env key="PATH" path="${env.PATH}:${latexlocation}"/>
         <arg   value="${ivoname}" />
        </exec>
        <!-- get rid of some TeXisms  (really need to do the accented characters as well..better to run sed..)-->
       <replaceregexp file="${ivoname}.bbl"
               match="([^/])~"
               replace="\1&amp;nbsp;"
               flags="g"/>

        <echo>Now edit the references into the document from ${ivoname}.bbl</echo>
   </target>
	
   <!-- ================================= 
          target: package              
         ================================= -->
    <target name="package"  description="create a zip file of document and associated files for upload to IVOA site">
      <tstamp></tstamp>
      <copy file="${ivoname}.html" tofile="${pubstatus}-${ivoname}-${docversion}-${DSTAMP}.html"></copy>
      <copy file="${ivoname}.pdf" tofile="${pubstatus}-${ivoname}-${docversion}-${DSTAMP}.pdf"></copy>
      
        <zip destfile="${ivoname}.zip" basedir="${basedir}" includes="${pubstatus}-${ivoname}-${docversion}-${DSTAMP}.html, ${pubstatus}-${ivoname}-${docversion}-${DSTAMP}.pdf, **/*.css,**/*.png,**/*.gif">
         
        </zip>
    </target>
	

	<taskdef name="fop" 
	         classname="org.apache.fop.tools.anttasks.Fop">
	  <classpath>
	    <fileset dir="${fop.home}/lib">
	      <include name="*.jar"/>
	    </fileset>
	    <fileset dir="${fop.home}/build">
	      <include name="fop.jar"/>
           <include name="fop-hyph.jar"/>
	    </fileset>
	  </classpath>
	</taskdef>
</project>