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

    <target name="dita2htmlhelp"
            unless="noMap"
    	depends="build-init, preprocess, copy-css, 
                     dita.topics.html, dita.inner.topics.html, dita.outer.topics.html">
        <antcall target="dita.map.htmlhelp"></antcall>
    	
        <antcall target="dita.htmlhelp.convertlang"></antcall>
		
    	<antcall target="compile.HTML.Help"></antcall>
    </target>

    <target name="dita.map.htmlhelp"
        depends="dita.map.htmlhelp.init, dita.map.htmlhelp.hhp, dita.map.htmlhelp.hhc, dita.map.htmlhelp.hhk, dita.out.map.htmlhelp.hhp, dita.out.map.htmlhelp.hhc, dita.out.map.htmlhelp.hhk">
    </target>

    <target name="dita.map.htmlhelp.init"
            description="Init properties for HTMLHelp">
        <condition property="out.ext" value=".html">
            <not>
                <isset property="out.ext" />
            </not>
        </condition>
    </target>

    <target name="dita.map.htmlhelp.hhp"
            depends="dita.map.htmlhelp.init" if="old.transform"
            description="Build HTMLHelp HHP file">
        <xslt processor="trax"
              basedir="${dita.temp.dir}"
              destdir="${output.dir}"
              includesfile="${dita.temp.dir}${file.separator}${user.input.file.listfile}"
              extension=".hhp"
              classpathref="dost.class.path"
              style="${dita.script.dir}${file.separator}map2hhp.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="HHCNAME" expression="${dita.map.filename.root}.hhc" />
            <param name="INCLUDEFILE"
                   expression="${args.htmlhelp.includefile}"
                   if="args.htmlhelp.includefile" />
        </xslt>
    </target>
    
    <target name="dita.out.map.htmlhelp.hhp"
        depends="dita.map.htmlhelp.init" if="inner.transform"
        description="Build HTMLHelp HHP 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}map2hhp.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="HHCNAME" expression="${dita.map.filename.root}.hhc" />
            <param name="INCLUDEFILE"
                expression="${args.htmlhelp.includefile}"
                if="args.htmlhelp.includefile" />
            <mapper type="glob" from="${user.input.file}" to="${dita.map.filename.root}.hhp"/>
        </xslt>
    </target>

    <target name="dita.map.htmlhelp.hhc"
            depends="dita.map.htmlhelp.init" if="old.transform"
            description="Build HTMLHelp HHC file">
        <xslt processor="trax"
              basedir="${dita.temp.dir}"
              destdir="${output.dir}"
              includesfile="${dita.temp.dir}${file.separator}${user.input.file.listfile}"
              extension=".hhc"
              classpathref="dost.class.path"
              style="${dita.script.dir}${file.separator}map2hhc.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" />
        </xslt>
    </target>
    
    <target name="dita.out.map.htmlhelp.hhc"
        depends="dita.map.htmlhelp.init" if="inner.transform"
        description="Build HTMLHelp HHC 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}map2hhc.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="${dita.map.filename.root}.hhc"/>
        </xslt>
    </target>

    <target name="dita.map.htmlhelp.hhk"
            depends="dita.map.htmlhelp.init" if="old.transform"
            description="Build HTMLHelp HHK 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="${out.ext}"/>
          <param name="indextype" value="htmlhelp"/>
          <param name="encoding" value="${args.dita.locale}" if="args.dita.locale"/>
        </pipeline>
    </target>
    
    <target name="dita.out.map.htmlhelp.hhk"
        depends="dita.map.htmlhelp.init" if="inner.transform"
        description="Build HTMLHelp HHK 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}.hhk"/>
          <param name="targetext" value="${out.ext}"/>
          <param name="indextype" value="htmlhelp"/>
          <param name="encoding" value="${args.dita.locale}" if="args.dita.locale"/>
        </pipeline>
    </target>
	
	<target name="dita.htmlhelp.convertlang">
		<taskdef name="check-lang" classname="org.dita.dost.util.CheckLang">
			<classpath refid="dost.jar.path" />
		</taskdef>
		<taskdef name="convert-lang" classname="org.dita.dost.util.ConvertLang">
			<classpath refid="dost.jar.path" />
		</taskdef>
		
		<check-lang message="Check Language"
			basedir="${basedir}"
		    tempdir="${dita.temp.dir}"
			inputmap="${user.input.file}"
			outputdir="${output.dir}"/>
		
		<convert-lang message="Convert Language"
			basedir="${basedir}"
			outputdir="${output.dir}"
			langcode="${htmlhelp.locale}"/>
	</target>

    <target name="compile.HTML.Help"
            if="HTMLHelpCompiler"
            description="Compile HTMLHelp output">
        <condition property="compile.dir" value="${output.dir}">
            <isset property="inner.transform"/>
        </condition>
        <condition property="compile.dir" value="${dita.map.output.dir}">
            <isset property="old.transform"/>
        </condition>
        <exec executable="${HTMLHelpCompiler}"
              failonerror="${failonerror}"
              failifexecutionfails="${failonerror}">
            <arg value="${compile.dir}${file.separator}${dita.map.filename.root}.hhp" />
        </exec>
    </target>

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

</project>
