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

  <target name="dita2wordrtf"
    depends="build-init, preprocess, map2wordrtf, topic2wordrtf">
  </target>

  <target name="topic2wordrtf" if="noMap">
    <antcall target="dita.topic.rtf">
      <param name="input"
        value="${dita.temp.dir}${file.separator}${user.input.file}" />
      <param name="output"
        value="${dita.map.output.dir}${file.separator}${dita.topic.filename.root}.rtf" />
    </antcall>
    <antcall target="escapeUnicode">
      <param name="input" value="${dita.map.output.dir}${file.separator}${dita.topic.filename.root}.rtf"/>
      <param name="output" value="${dita.map.output.dir}${file.separator}${dita.topic.filename.root}"/>
    </antcall>
  </target>
  
  <target name="map2wordrtf" unless="noMap">
    <antcall target="dita.map.rtf">
      <param name="input"
        value="${dita.temp.dir}${file.separator}${user.input.file}" />
      <param name="output"
        value="${dita.map.output.dir}${file.separator}${dita.map.filename.root}.rtf" />
    </antcall>
    <antcall target="escapeUnicode">
      <param name="input" value="${dita.map.output.dir}${file.separator}${dita.map.filename.root}.rtf"/>
      <param name="output" value="${dita.map.output.dir}${file.separator}${dita.map.filename.root}"/>
    </antcall>
  </target>

  <!-- Build RTF from DITA -->
  <target name="dita.topic.rtf">
    <condition property="args.xsl"
      value="${dita.script.dir}${file.separator}dita2rtf.xsl">
      <not>
        <isset property="args.xsl" />
      </not>
    </condition>
    <dirname file="${output}" property="dita.rtf.outputdir" />
    <xslt processor="trax" in="${input}" out="${output}"
      classpathref="dost.class.path"
      style="${args.xsl}">
      <param name="DRAFT" expression="${args.draft}" if="args.draft" />
      <param name="OUTPUTDIR" expression="${dita.rtf.outputdir}" />
      <!--<xmlcatalog refid="dita.catalog" />-->
    </xslt>
  </target>

  <target name="dita.map.rtf">
    <condition property="args.xsl"
      value="${dita.script.dir}${file.separator}dita2rtf.xsl">
      <not>
        <isset property="args.xsl" />
      </not>
    </condition>
    <dirname file="${output}" property="dita.rtf.outputdir" />
    <xslt processor="trax" in="${input}"
      out="${dita.temp.dir}${file.separator}${dita.map.filename.root}_MERGED.xml"
      classpathref="dost.class.path"
      style="${dita.script.dir}${file.separator}topicmerge.xsl">
      <!--<xmlcatalog refid="dita.catalog" />-->
    </xslt>
    <xslt processor="trax"
      in="${dita.temp.dir}${file.separator}${dita.map.filename.root}_MERGED.xml"
      classpathref="dost.class.path"
      out="${output}" style="${args.xsl}">
      <param name="DRAFT" expression="${args.draft}" if="args.draft" />
      <param name="OUTPUTDIR" expression="${dita.rtf.outputdir}" />
      <!--<xmlcatalog refid="dita.catalog" />-->
    </xslt>
  </target>

  <!-- added by Alan on Date: 2009-10-21 for RTF output encoding problem-->
  <target name="escapeUnicode">
    <pipeline message="Escape Unicode" module="EscapeUnicode">
      <param name="input" value="${input}"/>
      <param name="output" value="${output}"/>
    </pipeline>
    <move file="${output}" tofile="${input}" overwrite="true"/>
    <delete file="${output}"/>
  </target>
</project>
