<?xml version="1.0" encoding="UTF-8"?>
<!-- This file is part of the DITA Open Toolkit project hosted on 
     Sourceforge.net. See the accompanying license.txt file for 
     applicable licenses.-->
<!-- (c) Copyright IBM Corp. 2006 All Rights Reserved. -->
<project name="dita2odt">
	
  <property name="odt.suffix" value=".odt" />
  <condition property="args.odt.include.rellinks" value="none">
     <not><isset property="args.odt.include.rellinks"></isset></not>
  </condition>
	
  
<!--  
  <target name="dita2odt"
    depends="build-init, preprocess, map2odt, topic2odt,
  	dita.topic.odt.stylesfile, dita.map.odt.stylesfile, dita.out.odt.manifest.file, 
  	dita.odt.package.topic, dita.odt.package.map, clean-up-out-dir">
  </target>
-->
  <condition property="odt.dir" value="xsl/xslodt">
	    <not>
	      <isset property="odt.dir"/>
	    </not>
  </condition>
	
  <target name="set_odt_output_tempdir">
    <condition property="odt.output.tempdir" value="${dita.map.output.dir}/temp">
      <not>
        <isset property="odt.output.tempdir"/>
      </not>
    </condition>
    
    <copy todir="${odt.output.tempdir}">
      <fileset dir="${dita.map.output.dir}">
        <exclude name="**/*.list"/>
        <exclude name="**/*.log"/>
        <exclude name="**/*.temp"/>
        <exclude name="**/*.properties"/>
        <exclude name="**/*.odt"/>
        <exclude name="temp/**"/>
      </fileset>
    </copy>
    
  </target>
	
  
  <target name="clean_output_tempdir" unless="$flag">
    <delete failonerror="yes" includeemptydirs="true" dir="${odt.output.tempdir}" />   
  </target>		
	
	
  <target name="dita2odt"
    depends="build-init, preprocess, set_odt_output_tempdir, dita.odt.package.topic, dita.odt.package.map, move-output-file, clean_output_tempdir">
  </target>
  
  <target name="map2odt" unless="noMap">
    <antcall target="dita.map.odt">
      <param name="input"
        value="${dita.temp.dir}${file.separator}${user.input.file}" />
      <param name="output"
        value="${odt.output.tempdir}${file.separator}content.xml" />
    </antcall>
  </target>
  	
  <target name="topic2odt" if="noMap">
    <antcall target="dita.topic.odt">
      <param name="input"
        value="${dita.temp.dir}${file.separator}${user.input.file}" />
      <param name="output"
        value="${odt.output.tempdir}${file.separator}content.xml" />
    </antcall>
  </target>

  <!-- Build odt content.xml from DITA -->
  <target name="dita.map.odt" description="Build odt content.xml file">
  	
    <condition property="args.xsl"
      value="${dita.script.dir}${file.separator}dita2odt.xsl">
      <not>
        <isset property="args.xsl" />
      </not>
    </condition>
    <dirname file="${output}" property="dita.odt.outputdir" />
  	<!--create topic merge file -->  	
  	<dirname property="dita.temp.dir.fullpath" file="${dita.temp.dir}${file.separator}dummy.file"/>
  	<pipeline message="topicmerge" module="TopicMerge"
  	              inputmap="${dita.temp.dir.fullpath}${file.separator}${user.input.file}"
  	              tempdir="${dita.temp.dir.fullpath}">
      <param name="output" location="${dita.temp.dir.fullpath}${file.separator}${dita.map.filename.root}_MERGED.xml"/>
      <param name="style" location="${dita.dir}/${odt.dir}/common/topicmerge.xsl"/>
  	</pipeline>
  	<!--create content.xml -->
  	<!--Change path of ${dita.input.valfile} into url-->
  	<makeurl file="${dita.input.valfile}" property="dita.input.valfile.url" validate="no"/>
    <xslt processor="trax" basedir="${dita.temp.dir}"
      in="${dita.temp.dir}${file.separator}${dita.map.filename.root}_MERGED.xml"
      classpathref="dost.class.path"
      out="${output}" style="${args.xsl}" 
      filenameparameter="FILENAME"
      filedirparameter="FILEDIR">
      <param name="BASEDIR" expression="${basedir}"/>
      <param name="TEMPDIR" expression="${dita.temp.dir}"/>
      <param name="DITAEXT" expression="${dita.ext}" if="dita.ext" />
      <param name="DRAFT" expression="${args.draft}" if="args.draft" />
      <param name="FILTERFILE" expression="${dita.input.valfile.url}" if="dita.input.valfile" />
      <param name="OUTPUTDIR" expression="${dita.odt.outputdir}" />
      <param name="disableRelatedLinks" expression="${args.odt.include.rellinks}"/>
      <param name="INDEXSHOW" expression="${args.indexshow}" if="args.indexshow"/>
      <param name="DBG" expression="${args.debug}" if="args.debug"/>
      <param name="ODTIMGEMBED" expression="${args.odt.img.embed}" if="args.odt.img.embed"/>
      <xmlcatalog refid="dita.catalog"/>
    </xslt>
  </target>
  
  <target name="dita.topic.odt" description="Build odt content.xml file">
    <condition property="args.xsl"
      value="${dita.script.dir}${file.separator}dita2odt.xsl">
      <not>
        <isset property="args.xsl" />
      </not>
    </condition>
    <dirname file="${output}" property="dita.odt.outputdir" />
  	<!--Change path of ${dita.input.valfile} into url-->
  	<makeurl file="${dita.input.valfile}" property="dita.input.valfile.url" validate="no"/>
    <xslt processor="trax" in="${input}" out="${output}" basedir="${dita.temp.dir}"
      classpathref="dost.class.path"
      style="${args.xsl}"
      filenameparameter="FILENAME"
      filedirparameter="FILEDIR">
      <param name="BASEDIR" expression="${basedir}"/>
      <param name="TEMPDIR" expression="${dita.temp.dir}"/>
      <param name="DITAEXT" expression="${dita.ext}" if="dita.ext" />
      <param name="DRAFT" expression="${args.draft}" if="args.draft" />
      <param name="FILTERFILE" expression="${dita.input.valfile.url}" if="dita.input.valfile" />
      <param name="OUTPUTDIR" expression="${dita.odt.outputdir}" />
      <param name="disableRelatedLinks" expression="${args.odt.include.rellinks}"/>
      <param name="INDEXSHOW" expression="${args.indexshow}" if="args.indexshow"/>
      <param name="DBG" expression="${args.debug}" if="args.debug"/>
      <param name="ODTIMGEMBED" expression="${args.odt.img.embed}" if="args.odt.img.embed"/>
      <xmlcatalog refid="dita.catalog"/>
    </xslt>
  </target>
      	
  <target name="dita.topic.odt.stylesfile"
    description="Build odt styles.xml file" if="noMap">
    <xslt processor="trax"
      in="${dita.temp.dir}${file.separator}${user.input.file}"
      out="${odt.output.tempdir}${file.separator}styles.xml"
      classpathref="dost.class.path"
      style="${dita.script.dir}${file.separator}xslodt${file.separator}dita2odtstyles.xsl">
      <xmlcatalog refid="dita.catalog"/>
    </xslt>
  </target>
	
  <target name="dita.map.odt.stylesfile"
    description="Build odt styles.xml file" unless="noMap">
    <xslt processor="trax"
      in="${dita.temp.dir}${file.separator}${dita.map.filename.root}_MERGED.xml"
      out="${odt.output.tempdir}${file.separator}styles.xml"
      classpathref="dost.class.path"
      style="${dita.script.dir}${file.separator}xslodt${file.separator}dita2odtstyles.xsl">
      <xmlcatalog refid="dita.catalog"/>
    </xslt>
  </target>
	
  <target name="dita.out.odt.manifest.file"
    description="Build odt manifest.xml file">
    <xslt processor="trax"
      in="${dita.temp.dir}${file.separator}${user.input.file}"
      out="${odt.output.tempdir}${file.separator}META-INF${file.separator}manifest.xml"
      classpathref="dost.class.path"
      style="${dita.script.dir}${file.separator}xslodt${file.separator}dita2odtmanifest.xsl">
      <xmlcatalog refid="dita.catalog"/>
    </xslt>
   </target>
   
   <target name="dita.odt.package.topic" if="noMap" depends="topic2odt,
  	dita.topic.odt.stylesfile, dita.out.odt.manifest.file"
     description="Package into odt file">
     <zip destfile="${odt.output.tempdir}/${dita.topic.filename.root}${odt.suffix}"
       basedir="${odt.output.tempdir}" 
	   		excludes="**/*.list, **/*.log, **/*.temp, **/*.properties, **/*.odt">
	   	</zip>
   </target>
   <target name="dita.odt.package.map" unless="noMap" depends="map2odt, 
  	dita.map.odt.stylesfile, dita.out.odt.manifest.file"
    description="Package into odt file">
     <zip destfile="${odt.output.tempdir}/${dita.map.filename.root}${odt.suffix}"
       basedir="${odt.output.tempdir}"
	   		excludes="**/*.list, **/*.log, **/*.temp, **/*.properties, **/*.odt"/>
   </target>

  <target name="move-output-file">
    <move todir="${dita.map.output.dir}">
      <fileset dir="${odt.output.tempdir}">
        <include name="**/*.list"/>
        <include name="**/*.log"/>
        <include name="**/*.temp"/>
        <include name="**/*.properties"/>
        <include name="**/*.odt"/>
      </fileset>
    </move>
    <available property="flag" file="${odt.output.tempdir}" type="dir"/>
  </target>
  
</project>
