<?xml version="1.0"?>
<!-- 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. 2011 All Rights Reserved. -->
<project name="org.dita.pdf2.xep">

  <target name="transform.fo2pdf.xep.test-use">
    <condition property="use.xep.pdf.formatter">
      <equals arg1="${pdf.formatter}" arg2="xep"/>
    </condition>
  </target>

  <target name="transform.fo2pdf.xep.init" if="use.xep.pdf.formatter">
    <condition property="use.xep.pdf.formatter">
      <equals arg1="${pdf.formatter}" arg2="xep"/>
    </condition>
    
    <!-- default output format -->
    <condition property="xep.formatter.output-format" value="PDF">
      <not><isset property="xep.formatter.output-format"/></not>
    </condition>
    <!-- output file extension -->
    <condition property="xsl.formatter.ext" value=".ps">
      <and>
        <equals arg1="${xep.formatter.output-format}" arg2="PostScript"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".html">
      <and>
        <equals arg1="${xep.formatter.output-format}" arg2="XHTML"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".AT.xml">
      <and>
        <equals arg1="${xep.formatter.output-format}" arg2="XEP"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <!--condition property="xsl.formatter.ext" value=".AT.xml">
      <and>
        <equals arg1="${xep.formatter.output-format}" arg2="AT"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition-->
    <condition property="xsl.formatter.ext" value=".svg">
      <and>
        <equals arg1="${xep.formatter.output-format}" arg2="SVG"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".xps">
      <and>
        <equals arg1="${xep.formatter.output-format}" arg2="XPS"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".afp">
      <and>
        <equals arg1="${xep.formatter.output-format}" arg2="AFP"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".ppml">
      <and>
        <equals arg1="${xep.formatter.output-format}" arg2="PPML"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
    <condition property="xsl.formatter.ext" value=".pdf">
      <and>
        <equals arg1="${xep.formatter.output-format}" arg2="PDF"/>
        <not><isset property="xsl.formatter.ext"/></not>
      </and>
    </condition>
  </target>

  <!-- run XEP -->
  <target name="transform.fo2pdf.xep" depends="transform.fo2pdf.xep.test-use, transform.fo2pdf.xep.init" if="use.xep.pdf.formatter">
    <property name="xep.dir" value="${fo.lib.dir}/xep"/>
  
    <condition property="xep.config.file" value="${custom.xep.config}">
      <isset property="custom.xep.config"/>
    </condition>
    <condition property="xep.config.file" value="${xep.dir}/xep.xml">
      <not><isset property="custom.xep.config"/></not>
    </condition>
  
    <path id="xep.class.path">
      <fileset dir="${xep.dir}/lib" includes="**/*.jar"/>
      <pathelement location="${fo.lib.dir}/fo.jar"/>
    </path>

    <condition property="xep.failOnError" value="false">
      <not><isset property="xep.failOnError"/></not>
    </condition>
    
    <condition property="outputFile" value="${dita.map.output.dir}/${outputFile.base}${xsl.formatter.ext}">
      <not><isset property="outputFile"/></not>
    </condition>
    
    <java classname="com.idiominc.ws.opentopic.fo.xep.Runner" resultproperty="errCode"
          failonerror="${xep.failOnError}" fork="true" maxmemory="${maxJavaMemory}">
      <jvmarg line="${baseJVMArgLine}"/>
      <arg value="${dita.map.output.dir}/topic.fo"/>
      <arg value="${outputFile}"/>
      <arg value="failOnError=${xep.failOnError}"/>
      <arg value="-${xep.formatter.output-format}"/>
      <classpath refid="xep.class.path"/>
      <sysproperty key="com.renderx.xep.CONFIG" value="${xep.config.file}"/>
    </java>
    <condition property="xepExitedOnError" value="true">
      <not><equals arg1="${errCode}" arg2="0"/></not>
    </condition>
  </target>

</project>
