<?xml version="1.0" encoding="utf-8"?>
<project basedir="." default="dist" name="xlsxtei">
  <!--
	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-from.xml 9316 2011-09-13 08:06:05Z rahtz $
        Copyright: 2011, TEI Consortium<
-->
  <!--
 Convert xlsx files to TEI documents.
 -->
  <!-- Path to xlsx file. -->
  <property name="inputFile" value=""/>
  <!-- Path where the output TEI file will be saved. -->
  <property name="outputFile" value=""/>
  <!-- which profile -->
  <property name="profile" value="default"/>
  <!-- which language -->
  <property name="lang" value="en"/>
  <property name="catalogfile" value="../catalog.xml"/>
  <!-- where does oxygen keep stuff -->
  <property name="oxygenlib" value=""/>
  <!-- Stylesheet for transformation -->
  <property name="xlsxtoTEI" value="${profiledir}/${profile}/xlsx/from.xsl"/>
  <dirname property="inputFileDir" file="${inputFile}"/>
  <dirname property="outputDir" file="${outputFile}"/>
  <property name="outputTempDir" value="${outputDir}/temp-dir-for-ant"/>
  <path id="classpath">
    <pathelement path="${java.class.path}"/>
  </path>
  <target name="setup">
    <!-- Recreate temporary output directory -->
    <delete dir="${outputTempDir}"/>
    <mkdir dir="${outputTempDir}"/>
  </target>
  <target name="dist" depends="convert,mediadir.check,picturecopy,cleanup"/>
  <target name="convert" depends="setup">
    <echo>Convert using ${xlsxtoTEI}</echo>
    <unzip src="${inputFile}" dest="${outputTempDir}"/>
    <xslt force="yes" style="${xlsxtoTEI}" in="${outputTempDir}/_rels/.rels" out="${outputFile}">
      <xmlcatalog>
        <catalogpath>
          <pathelement location="$catalogfile"/>
        </catalogpath>
      </xmlcatalog>
      <factory name="net.sf.saxon.TransformerFactoryImpl"/>
      <param name="workDir" expression="file:///${outputTempDir}"/>
      <param name="inputDir" expression="${inputFileDir}"/>
    </xslt>
  </target>
  <target name="mediadir.check">
    <condition property="mediadir.exists">
      <available file="${outputTempDir}/word/media" type="dir"/>
    </condition>
  </target>
  <target name="picturecopy" if="${mediadir.exists}">
    <mkdir dir="${outputDir}/media"/>
    <move todir="${outputDir}/media" overwrite="true">
      <fileset dir="${outputTempDir}/word/media"/>
    </move>
  </target>
  <target name="cleanup" unless="debug">
    <delete dir="${outputTempDir}"/>
  </target>
</project>
