<!-- 
  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 Shawn McKenzie, 2007. All Rights Reserved.

  UPDATES:
    20110817 RDA: Several changes:
        * Use property dita.plugin.com.sophos.tocjs.dir (remove hard-coded demo/ dir)
        * Original design only works if $output.file is set in an Ant file, and
          if XHTML is created independently. Refactoring to use that original
          processing when $output.file is specified; otherwise:
          1) Return HTML files along with navigation
          2) Return default frameset (with name based on map name)
          3) Set $output.file to a default value of toctree.js
          4) Return supporting JS and CSS files for the default frameset
  *-->
<project>

  <target name="dita2tocjs" depends="dita-preprocess, tocjsInit, map2tocjs, topic2tocjs, tocjsDefaultOutput">
  </target>

  <target name="tocjsInit">
      <condition property="dita.plugin.com.sophos.tocjs.copydefaults" value="true">
          <not>
              <isset property="output.file" />
          </not>
      </condition>
      <condition property="output.file" value="${output.dir}${file.separator}toctree.js">
          <not>
              <isset property="output.file" />
          </not>
      </condition>
  </target>

  <target name="topic2tocjs" if="noMap" depends="dita-preprocess">
    <antcall target="dita.map.tocjs">
      <!-- No real support for tocjs on a single topic, only for map -->
    </antcall>
    <echo>The TocJS output type only supports ditamap files as input.</echo>
  </target>

  <target name="map2tocjs" unless="noMap" depends="dita-preprocess">
    <antcall target="dita.map.tocjs">
      <param name="input" value="${dita.temp.dir}${file.separator}${user.input.file}"/>
    </antcall>
  </target>

  <target name="dita.map.tocjs" description="generate merged for tocjs">
    <xslt processor="trax" in="${input}" out="${output.file}"
      style="${dita.plugin.com.sophos.tocjs.dir}/xsl/tocjs.xsl">
      <param name="contentwin" expression="${content.frame}" if="content.frame"/>
      <param name="ditaext" expression="${dita.extname}"/>
      <param name="htmlext" expression="${out.ext}"/>
    </xslt>
  </target>

  <target name="tocjsDefaultOutput" 
          if="dita.plugin.com.sophos.tocjs.copydefaults">
      <!-- Create usable output for people trying tocjs for the first time -->
      <antcall target="tocjsDefaultXhtmlOutput"/>
      <antcall target="tocjsDefaultFrameset"/>
      <!-- Copy default JS and related files -->
      <copy todir="${output.dir}"><fileset
          dir="${dita.plugin.com.sophos.tocjs.dir}${file.separator}basefiles"><include name="**/*"/></fileset></copy>
  </target>

  <target name="tocjsDefaultXhtmlOutput" depends="dita.map.xhtml, copy-revflag, copy-css , dita.topics.xhtml, dita.inner.topics.xhtml, dita.outer.topics.xhtml">
      <!-- Preprocess has already completed based on original dependencies;
           this target continues to XHTML for default output. Seems very 
           indirect way to create the XHTML, so would like something better,
           but do not want to add new XHTML processing for people using
           the original dita2tocjs target. -->
  </target>

  <target name="tocjsDefaultFrameset" if="dita.plugin.com.sophos.tocjs.copydefaults">
      <!-- Create the default frameset itself -->
      <condition property="out.ext" value=".html">
          <not>
              <isset property="out.ext" />
          </not>
      </condition>
      <xslt processor="trax"
		basedir="${dita.temp.dir}"
		destdir="${output.dir}"
        includesfile="${dita.temp.dir}${file.separator}${user.input.file.listfile}"
        extension="${out.ext}"
		style="${dita.plugin.com.sophos.tocjs.dir}${file.separator}xsl${file.separator}frameset.xsl">
  	    <excludesfile name="${dita.temp.dir}${file.separator}${resourceonlyfile}" if="resourceonlyfile"/>
        <param name="DITAEXT" expression="${dita.ext}" if="dita.ext"/>
        <param name="OUTEXT" expression="${out.ext}" if="out.ext"/>
        <param name="CSSPATH" expression="${CSSPATH}" if="csspath"/>
      </xslt>
  </target>

</project>
