<?xml version="1.0" encoding="utf-8"?>
<project basedir="." default="dist" name="teitoepub">
  <!--
	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.
	
	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public
	License along with this library; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
	
        Id: $Id: build-to.xml 11958 2013-04-16 13:58:39Z rahtz $
        Copyright: 2011, TEI Consortium<
-->
  <!--
 Convert TEI documents into ePUB files.
 -->
  <!-- Path to TEI XML file. -->
  <property name="verbose" value="false"/>
  <property name="inputFile" value=""/>
  <!-- Path where the output ePUB file will be saved. -->
  <property name="outputFile" value=""/>
  <!-- which profile -->
  <property name="profile" value="default"/>
  <property name="catalogfile" value="../catalog.xml"/>
  <!-- where does oxygen keep stuff -->
  <property name="oxygenlib" value=""/>
  <property name="profiledir" value="../profiles"/>
  <!-- which profile -->
  <property name="profile" value="default"/>
  <!-- Stylesheet for transformation -->
  <property name="teitoepub" value="${profiledir}/${profile}/epub/to.xsl"/>
  <property name="listgraphics" value="../tools/makegraphicsanttask.xsl"/>
  <dirname property="outputDir" file="${outputFile}"/>
  <dirname property="inputDir" file="${inputFile}"/>
  <tempfile property="temp.file" destDir="${java.io.tmpdir}" prefix="build"/>
  <dirname property="outputTempDir" file="${temp.file}/ant"/>
  <path id="classpath">
    <pathelement path="${java.class.path}"/>
  </path>
  <import file="../odds2/build-to.xml"/>
  <macrodef name="buildepub">
    <attribute name="in"/>
    <attribute name="inDir"/>
    <attribute name="out"/>
    <sequential>
      <!-- The transformation for EPUB output. -->
      <echo level="info">XSLT generate ePub files in @{tempdir}</echo>
      <xslt force="yes" style="${teitoepub}" in="${outputTempDir}/tmp2.xml" out="${outputTempDir}/OPS/index.html">
        <factory name="net.sf.saxon.TransformerFactoryImpl"/>
        <classpath location="${oxygenlib}/saxon9ee.jar"/>
        <param name="directory" expression="file:///${outputTempDir}"/>
        <param name="inputDir" expression="@{inDir}/"/>
        <param name="fixgraphicsurl" expression="true"/>
        <!-- supply unique URN for ebook-->
        <param name="uid" expression="${uid}" if="uid"/>
        <!-- set splitting level-->
        <param name="splitLevel" expression="${splitLevel}" if="splitLevel"/>
        <!-- supply name of publisher for ebook-->
        <param name="publisher" expression="${publisher}" if="publisher"/>
        <!-- supply subject/category for ebook-->
        <param name="subject" expression="${subject}" if="subject"/>
        <!-- supply name of JPEG file for ebook cover-->
        <param name="coverimage" expression="${coverimage}" if="coverimage"/>
        <!-- supply name of CSS file-->
        <param name="cssFile" expression="${cssFile}" if="cssFile"/>
        <!-- name of media overlay file -->
        <param name="mediaoverlay" expression="${mediaoverlay}" if="mediaoverlay"/>
        <!-- file per page -->
        <param name="filePerPage" expression="${filePerPage}" if="filePerPage"/>
        <!-- epub viewport -->
        <param name="viewPortHeight" expression="${viewPortHeight}" if="viewPortHeight"/>
        <param name="viewPortWidth" expression="${viewPortWidth}" if="viewPortWidth"/>
        <!-- supply name of language-->
        <param name="lang" expression="${lang}" if="lang"/>
        <!-- emit some diagnostics"-->
        <param name="debug" expression="${debug}" if="debug"/>
        <!-- be verbose-->
        <param name="verbose" expression="${verbose}" if="verbose"/>
        <!-- disable compression on the output ZIP -->
        <param name="nocompress" expression="${nocompress}" if="nocompress"/>
      </xslt>
      <echo level="info">Get names of graphics files and write an ant  task</echo>
      <xslt force="yes" style="${listgraphics}" in="${outputTempDir}/tmp2.xml" out="${outputTempDir}/copy.xml">
        <factory name="net.sf.saxon.TransformerFactoryImpl"/>
        <classpath location="${oxygenlib}/saxon9ee.jar"/>
        <param name="outputDir" expression="${outputTempDir}"/>
        <param name="inputDir" expression="@{inDir}"/>
        <param name="mediaDir" expression="OPS/media"/>
        <param name="mediaoverlay" expression="${mediaoverlay}" if="mediaoverlay"/>
        <param name="filePerPage" expression="${filePerPage}" if="filePerPage"/>
      </xslt>
      <echo level="info">Copy image files</echo>
      <ant antfile="${outputTempDir}/copy.xml"/>
      <echo level="info">ZIP: put files from ${outputTempDir} together into @{out}</echo>
      <delete file="@{out}"/>
      <zip destfile="@{out}" basedir="${outputTempDir}" compress="true" excludes="mimetype,tmp1.xml,tmp2.xml,copy.xml"/>
      <zip destfile="@{out}" basedir="${outputTempDir}" includes="mimetype" update="true" keepcompression="true" compress="false"/>
    </sequential>
  </macrodef>
  <target name="dist" depends="setup,odd,notodd,go,cleanup"/>
  <target name="setup">
    <mkdir dir="${outputTempDir}"/>
  </target>
  <target name="cleanup" unless="${debug}">
    <delete dir="${outputTempDir}"/>
  </target>
  <target name="go">
    <buildepub in="${outputTempdir}/tmp2.xml" inDir="${inputDir}" out="${outputFile}"/>
  </target>
</project>
