<?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="dita2troff" default="dita2troff">
  <property name="transtype" value="troff"/>
    
  <import file="build_init.xml" />
  <import file="build_preprocess.xml" />

  <target name="dita2troff"
    depends="build-init, preprocess, dita.topic.troff, dita.inner.topic.troff, dita.outer.topic.troff">
  </target>

  <target name="dita.topic.troff" unless="noTopic" if="old.transform"
    description="Build troff output from dita inner and outer topics,which will adjust the directory.">
    <!-- step 1 -->
    <xslt processor="trax" basedir="${dita.temp.dir}"
      destdir="${output.dir}" includes="${fullditatopiclist} ${chunkedtopiclist}"
      extension="${dita.ext}"
      classpathref="dost.class.path"
      style="${dita.script.dir}${file.separator}dita2troff-step1-shell.xsl">
      <param name="DITAEXT" expression="${dita.ext}" if="dita.ext" />
    </xslt>

    <!-- step 2 -->
    <xslt processor="trax" basedir="${dita.map.output.dir}" destdir="${dita.map.output.dir}"
      includes="${fullditatopiclist} ${chunkedtopiclist}" extension=".cli"
      classpathref="dost.class.path"
      style="${dita.script.dir}${file.separator}dita2troff-step2-shell.xsl">
      <param name="DITAEXT" expression="${dita.ext}" if="dita.ext" />
    </xslt>
  </target>
  
  <!--The new solution which divides the whole process into the inner and outer steps  -->
    <target name="dita.inner.topic.troff" unless="noTopic" if="inner.transform"
    description="Build troff output from inner dita topics">
    <!-- step 1 -->
    <xslt processor="trax" basedir="${dita.temp.dir}"
      destdir="${output.dir}" includes="${fullditatopiclist} ${chunkedtopiclist}"
      extension="${dita.ext}"
      classpathref="dost.class.path"
      style="${dita.script.dir}${file.separator}dita2troff-step1-shell.xsl">
      <param name="DITAEXT" expression="${dita.ext}" if="dita.ext" />
      <!--New,To generate&copy all dita files in the inputmap.dir,not all files in dita.temp.dir -->
      <mapper type="regexp" 
        from="^(${tempdirToinputmapdir.relative.value})(.*?)(\.(xml|dita))$$" 
        to="\2${dita.ext}"/>
    </xslt>
	<echo>the ditmapoutputdir is ${dita.map.output.dir}</echo>
    <!-- step 2 -->
    <xslt processor="trax" basedir="${output.dir}" destdir="${output.dir}"
      includes="${fullditatopiclist} ${chunkedtopiclist}" extension=".cli"
      classpathref="dost.class.path"
      style="${dita.script.dir}${file.separator}dita2troff-step2-shell.xsl">
      <param name="DITAEXT" expression="${dita.ext}" if="dita.ext" />
      <mapper type="regexp" 
        from="^(${tempdirToinputmapdir.relative.value})(.*?)(\.(xml|dita))$$" 
        to="\2\.cli"/>
    </xslt>
  </target>
  
  <!--requirement 2-->
  <!--if the outditafileslist is empty ,do not execute the outer transformation-->
  <target name="checkouterTransform">
  	<condition property="outer.transform">
  		<and>
  			<equals arg1="${generate.copy.outer}" arg2="2"></equals>
  			<and>
  				<isset property="outditafileslist"/>
  				<not>
  					<equals arg1="" arg2="${outditafileslist}"/>
  				</not>
  			</and>
  		</and>
	</condition>	
  </target>	
  
  <target name="dita.outer.topic.troff" unless="noTopic" if="outer.transform"  depends="checkouterTransform"
    description="Build troff output from outer dita topics">
    <!-- step 1 -->
    <xslt processor="trax" basedir="${dita.temp.dir}"
      destdir="${output.dir}" includes="${outditafileslist}"
      extension="${dita.ext}"
      classpathref="dost.class.path"
      style="${dita.script.dir}${file.separator}dita2troff-step1-shell.xsl">
      <param name="DITAEXT" expression="${dita.ext}" if="dita.ext" />
    </xslt>

    <!-- step 2 -->
    <xslt processor="trax" basedir="${output.dir}" destdir="${output.dir}${file.separator}${uplevels}"
      includes="${outditafileslist}" extension=".cli"
      classpathref="dost.class.path"
      style="${dita.script.dir}${file.separator}dita2troff-step2-shell.xsl">
      <param name="DITAEXT" expression="${dita.ext}" if="dita.ext" />
    </xslt>
  </target>
</project>
