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

    <target name="dita2javahelp"
            unless="noMap"
        depends="build-init, preprocess, copy-css, 
                     dita.topics.html, dita.inner.topics.html, dita.outer.topics.html">
          <antcall target="dita.map.javahelp"></antcall>
          <antcall target="compile.Java.Help"></antcall>
    </target>

    <target name="dita.map.javahelp"
            depends="dita.map.javahelp.init, dita.map.javahelp.toc, 
        						 dita.map.javahelp.map, dita.map.javahelp.set, dita.map.javahelp.index,
                                 dita.out.map.javahelp.toc, dita.out.map.javahelp.map, 
                                 dita.out.map.javahelp.set, dita.out.map.javahelp.index">
    </target>

    <target name="dita.map.javahelp.init"
            description="Init properties for JavaHelp">
        <basename property="dita.map.toc.root"
                  file="${dita.input.filename}"
                  suffix=".ditamap" />
        <condition property="args.javahelp.toc" value="${dita.map.toc.root}">
            <not>
                <isset property="args.javahelp.toc" />
            </not>
        </condition>
        <condition property="out.ext" value=".html">
            <not>
                <isset property="out.ext" />
            </not>
        </condition>
        <condition property="args.javahelp.map" value="${dita.map.toc.root}">
            <not>
                <isset property="args.javahelp.map" />
            </not>
        </condition>
        <condition property="args.javahelp.helpset"
                   value="${dita.resource.dir}${file.separator}helpset.hs">
            <not>
                <isset property="args.javahelp.helpset" />
            </not>
        </condition>
    </target>

    <target name="dita.map.javahelp.toc"
            depends="dita.map.javahelp.init" if="old.transform"
            description="Build JavaHelp TOC file">
        <xslt processor="trax"
              basedir="${dita.temp.dir}"
              destdir="${output.dir}"
              includesfile="${dita.temp.dir}${file.separator}${user.input.file.listfile}"
              classpathref="dost.class.path"
              style="${dita.script.dir}${file.separator}map2javahelptoc.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" />
            <mapper type="glob"
                    from="*${dita.input.filename}"
                    to="*${args.javahelp.toc}.xml" />
        </xslt>
    </target>
    
    <target name="dita.out.map.javahelp.toc"
        depends="dita.map.javahelp.init" if="inner.transform"
        description="Build JavaHelp TOC file">
        <xslt processor="trax"
            basedir="${dita.temp.dir}"
            destdir="${output.dir}"
            includesfile="${dita.temp.dir}${file.separator}${user.input.file.listfile}"
            classpathref="dost.class.path"
            style="${dita.script.dir}${file.separator}map2javahelptoc.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" />
            <mapper type="glob"
                from="${user.input.file}"
                to="${args.javahelp.toc}.xml" />
        </xslt>
    </target>

    <target name="dita.map.javahelp.map"
            depends="dita.map.javahelp.init" if="old.transform"
            description="Build JavaHelp Map file">
        <xslt processor="trax"
              basedir="${dita.temp.dir}"
              destdir="${output.dir}"
              includesfile="${dita.temp.dir}${file.separator}${user.input.file.listfile}"
              classpathref="dost.class.path"
              style="${dita.script.dir}${file.separator}map2javahelpmap.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" />
            <mapper type="glob"
                    from="*${dita.input.filename}"
                    to="*${args.javahelp.map}.jhm" />
        </xslt>
    </target>
    
    <target name="dita.out.map.javahelp.map"
        depends="dita.map.javahelp.init" if="inner.transform"
        description="Build JavaHelp Map file">
        <xslt processor="trax"
            basedir="${dita.temp.dir}"
            destdir="${output.dir}"
            includesfile="${dita.temp.dir}${file.separator}${user.input.file.listfile}"
            classpathref="dost.class.path"
            style="${dita.script.dir}${file.separator}map2javahelpmap.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" />
            <mapper type="glob"
                from="${user.input.file}"
                to="${args.javahelp.map}.jhm" />
        </xslt>
    </target>

    <target name="dita.map.javahelp.set"
            depends="dita.map.javahelp.init, dita.map.javahelp.map" if="old.transform"
            description="Build JavaHelp Set file">
        <xslt processor="trax"
              basedir="${dita.temp.dir}"
              destdir="${output.dir}"
              includesfile="${dita.temp.dir}${file.separator}${user.input.file.listfile}"
              classpathref="dost.class.path"
              style="${dita.script.dir}${file.separator}map2javahelpset.xsl">
        	<excludesfile name="${dita.temp.dir}${file.separator}${resourceonlyfile}" if="resourceonlyfile"/>
            <param name="javahelpmap" expression="${args.javahelp.map}" />
            <param name="javahelptoc" expression="${args.javahelp.toc}" />
        	<param name="basedir" expression="${basedir}"/>
        	<param name="outputdir" expression="${output.dir}"/>
        	<!--param name="outputdir" expression="${dita.dir}${file.separator}${output.dir}${file.separator}" /-->
            <mapper type="glob"
                    from="*${dita.input.filename}"
                    to="*${dita.map.toc.root}_helpset.hs" />
        </xslt>
    </target>
    
    <target name="dita.out.map.javahelp.set"
        depends="dita.map.javahelp.init, dita.out.map.javahelp.map" if="inner.transform"
        description="Build JavaHelp Set file">
        <xslt processor="trax"
            basedir="${dita.temp.dir}"
            destdir="${output.dir}"
            includesfile="${dita.temp.dir}${file.separator}${user.input.file.listfile}"
            classpathref="dost.class.path"
            style="${dita.script.dir}${file.separator}map2javahelpset.xsl">
        	<excludesfile name="${dita.temp.dir}${file.separator}${resourceonlyfile}" if="resourceonlyfile"/>
            <param name="javahelpmap" expression="${args.javahelp.map}" />
            <param name="javahelptoc" expression="${args.javahelp.toc}" />
        	<param name="basedir" expression="${basedir}"/>
        	<param name="outputdir" expression="${output.dir}"/>
        	<!--param name="outputdir" expression="${dita.dir}${file.separator}${output.dir}${file.separator}" /-->
            <mapper type="glob"
                from="${user.input.file}"
                to="${dita.map.toc.root}_helpset.hs" />
        </xslt>
    </target>

    <target name="dita.map.javahelp.index" if="old.transform"
            description="Build JavaHelp Index file">
        <pipeline message="Extract index term."
                  module="IndexTermExtract"
                  basedir="${basedir}"
                  tempdir="${dita.temp.dir}"
                  inputmap="${user.input.file}">
          <param name="output" location="${output.dir}${file.separator}${user.input.file}"/>
          <param name="targetext" value=".html"/>
          <param name="indextype" value="javahelp"/>
          <param name="encoding" value="${args.dita.locale}" if="args.dita.locale"/>
        </pipeline>
    </target>
    
    <target name="dita.out.map.javahelp.index" if="inner.transform"
        description="Build JavaHelp Index file">
        <pipeline message="Extract index term."
            module="IndexTermExtract"
            basedir="${basedir}"
            tempdir="${dita.temp.dir}"
            inputmap="${user.input.file}">
          <param name="output" location="${output.dir}${file.separator}${dita.map.filename.root}.xml"/>
          <param name="targetext" value=".html"/>
          <param name="indextype" value="javahelp"/>
          <param name="encoding" value="${args.dita.locale}" if="args.dita.locale"/>
        </pipeline>
    </target>

    <target name="compile.Java.Help"
            if="env.JHHOME"
            description="Compile Java Help output">
        <!-- delete 'JavaHelpSearch' directory before compiling. -->
        <condition property="compile.dir" value="${dita.map.output.dir}">
            <isset property="old.transform"/>
        </condition>
        <condition property="compile.dir" value="${output.dir}">
            <isset property="inner.transform"/>
        </condition>
        <delete dir="${compile.dir}${file.separator}JavaHelpSearch" />
        <java jar="${env.JHHOME}${file.separator}javahelp${file.separator}bin${file.separator}jhindexer.jar"
              fork="true"
              dir="${compile.dir}">
            <arg value="." />
        </java>
    </target>

    <!-- depecrated: keep for back-compatibility, will be remvoed in a later release -->
    <target name="dita.topics.javahelp" depends="dita.topics.html" />

</project>
