<?xml version="1.0"?>
<!-- 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="ditaot-init" basedir=".">
  <import file="catalog-ant.xml"/>
    
  <dirname property="ant.file.ditaot-init.dir" file="${ant.file.ditaot-init}" />

  <!-- First try to initialize ${dita.dir} using the special 
    property passed by Ant's import task. -->
  <condition property="dita.dir" value="${ant.file.ditaot-init.dir}">
    <and>
      <isset property="ant.file.ditaot-init" />
      <not>
        <isset property="dita.dir" />
      </not>
    </and>
  </condition>

  <!-- Try to initialize ${dita.dir} again if it was not set. -->
  <condition property="dita.dir" value="${basedir}">
    <not>
      <isset property="dita.dir" />
    </not>
  </condition>

  <path id="dost.jar.path">
    <pathelement
      location="${dita.dir}${file.separator}lib${file.separator}dost.jar" />
  </path>

  <taskdef name="pipeline"
    classname="org.dita.dost.invoker.AntInvoker">
    <classpath refid="dost.jar.path" />
  </taskdef>
  <taskdef name="config-logger"
    classname="org.dita.dost.log.LogConfigTask">
    <classpath refid="dost.jar.path" />
  </taskdef>

  <taskdef name="dita-ot-echo"
    classname="org.dita.dost.log.DITAOTEchoTask">
    <classpath refid="dost.jar.path" />
  </taskdef>

  <taskdef name="dita-ot-fail"
    classname="org.dita.dost.log.DITAOTFailTask">
    <classpath refid="dost.jar.path" />
  </taskdef>

  <taskdef name="dita-ot-copy"
    classname="org.dita.dost.util.DITAOTCopy">
    <classpath refid="dost.jar.path" />
  </taskdef>
	
  <taskdef name="xmlpropertyreader"
  	classname="org.dita.dost.platform.XmlPropertyTask">
  	<classpath refid="dost.jar.path"/>
  </taskdef>
	
  <typedef name="isabsolute"
    classname="org.dita.dost.util.IsAbsolute">
    <classpath refid="dost.jar.path" />
  </typedef>
  <property name="dita.temp.dir" value="temp" />
  <property name="output.dir" value="out" />
  <property name="dita.extname" value="xml" />
  <property name="dita.script.dir"
    value="${dita.dir}${file.separator}xsl" />
  <property name="dita.resource.dir"
    value="${dita.dir}${file.separator}resource" />
  <property environment="env" />
  <property name="dita.empty" value="" />
  <property name="args.message.file"
    value="${dita.dir}${file.separator}resource${file.separator}messages.xml" />
  <!-- property values end -->

  <target name="build-init"
    depends="start-process, init-logger, use-init, check-arg, output-msg" />
    
  <target name="start-process" description="Processing started" />

  <target name="init-logger"
    description="Initialize log directory and file name">
    <config-logger />
  </target>
  
  <target name="use-init.envhhcdir" if="env.HHCDIR">
    <available file="${env.HHCDIR}${file.separator}hhc.exe" property="HTMLHelpCompiler"
      value="${env.HHCDIR}${file.separator}hhc.exe"/>
  </target>
  
  <target name="use-init.hhcdir" unless="env.HHCDIR">
    <condition property="hhc.dir" value="C:\Program Files (x86)\HTML Help Workshop" else="C:\Program Files\HTML Help Workshop">
      <available file="C:\Program Files (x86)\HTML Help Workshop" type="dir"/>
    </condition>
    <available file="${hhc.dir}${file.separator}hhc.exe" property="HTMLHelpCompiler"
      value="${hhc.dir}${file.separator}hhc.exe" />
  </target>
  
  <target name="use-init" depends="use-init.envhhcdir,use-init.hhcdir">
    <available classname="com.icl.saxon.StyleSheet" property="hasSaxon" />
    <available classname="org.apache.fop.tools.anttasks.Fop"
      property="hasFOP" />    
  </target>

  <!-- property value validation begin -->
  <target name="check-arg" depends="use-init"
    description="Validate and init input arguments">
    <!-- begin to check input parameters -->
    <dita-ot-fail id="DOTA002F">
      <condition>
        <and>
          <or>
            <not>
              <isset property="args.input" />
            </not>
            <and>
              <isset property="args.input" />
              <not>
                <available file="${args.input}" type="file" />
              </not>
            </and>
          </or>
          <or>
            <not>
              <isset property="dita.input" />
            </not>
            <not>
              <isset property="dita.input.dirname" />
            </not>
            <and>
              <isset property="dita.input" />
              <isset property="dita.input.dirname" />
              <not>
                <available file="${dita.input}"
                  filepath="${dita.input.dirname}" type="file" />
              </not>
            </and>
          </or>
        </and>
      </condition>
    </dita-ot-fail>

    <dita-ot-fail id="DOTA003F" params="%1=${args.xsl}">
      <condition>
        <and>
          <isset property="args.xsl" />
          <not>
            <available file="${args.xsl}" type="file" />
          </not>
        </and>
      </condition>
    </dita-ot-fail>

    <dita-ot-fail id="DOTA004F" params="%1=${dita.extname}">
      <condition>
        <not>
          <or>
            <contains string="${dita.extname}" substring="dita" />
            <contains string="${dita.extname}" substring="xml" />
          </or>
        </not>
      </condition>
    </dita-ot-fail>
   <dita-ot-fail id="DOTA007E" params="%1=${args.ftr}">
        <condition>
        	<and>
        	 <isset property="args.ftr" />
        	 <not>
        	<available file="${args.ftr}" type="file"/>
        	</not>
        	</and>
        </condition>
     </dita-ot-fail>
    <dita-ot-fail id="DOTA008E" params="%1=${args.hdr}">
      <condition>
        <and>
          <isset property="args.hdr" />
          <not>
            <available file="${args.hdr}" type="file"/>
          </not>
        </and>
      </condition>
    </dita-ot-fail>
    <dita-ot-fail id="DOTA009E" params="%1=${args.hdf}">
      <condition>
        <and>
          <isset property="args.hdf" />
          <not>
            <available file="${args.hdf}" type="file"/>
          </not>
        </and>
      </condition>
    </dita-ot-fail>
    <!-- end to check input parameters -->

    <!-- begin to init required parameters -->

    <condition property="msg.deprecate">
      <and>
        <not>
          <isset property="args.input" />
        </not>
        <isset property="dita.input" />
        <isset property="dita.input.dirname" />
      </and>
    </condition>

    <condition property="args.input"
      value="${dita.input.dirname}${file.separator}${dita.input}">
      <not>
        <isset property="args.input" />
      </not>
    </condition>

    <condition property="dita.ext" value=".xml">
      <and>
        <isset property="dita.extname" />
        <contains string="${dita.extname}" substring="xml" />
      </and>
    </condition>
    <condition property="dita.ext" value=".dita">
      <and>
        <isset property="dita.extname" />
        <contains string="${dita.extname}" substring="dita" />
      </and>
    </condition>

    <!-- append a '.' to out.ext if args.outext not contains '.' -->
    <condition property="out.ext" value=".${args.outext}">
      <and>
        <isset property="args.outext" />
        <not>
          <contains string="${args.outext}" substring="." />
        </not>
      </and>
    </condition>
    <condition property="out.ext" value="${args.outext}">
      <and>
        <isset property="args.outext" />
        <contains string="${args.outext}" substring="." />
      </and>
    </condition>

    <!-- append a '.' to ${fo.img.ext} if ${args.fo.img.ext} not contains '.' -->
    <condition property="fo.img.ext" value=".${args.fo.img.ext}">
      <and>
        <isset property="args.fo.img.ext" />
        <not>
          <contains string="${args.fo.img.ext}" substring="." />
        </not>
      </and>
    </condition>
    <condition property="fo.img.ext" value="${args.fo.img.ext}">
      <and>
        <isset property="args.fo.img.ext" />
        <contains string="${args.fo.img.ext}" substring="." />
      </and>
    </condition>

    <condition property="clean_temp">
      <and>
        <isset property="clean.temp" />
        <equals arg1="${clean.temp}" arg2="no" casesensitive="false" />
      </and>
    </condition>

    <basename property="dita.input.filename" file="${args.input}" />
    <basename property="dita.map.filename.root"
      file="${dita.input.filename}" suffix=".ditamap" />
    <basename property="dita.topic.filename.root"
      file="${dita.input.filename}" suffix="${dita.ext}" />
    <!-- end to init required parameters -->

    <!-- create required directories -->
    <mkdir dir="${output.dir}" />
    <mkdir dir="${dita.temp.dir}" />

    <!-- begin to check and init css relevant properties -->
    <condition property="user.csspath.url">
      <or>
        <contains string="${args.csspath}" substring="http://" />
        <contains string="${args.csspath}" substring="https://" />
      </or>
    </condition>
    <condition property="args.csspath.absolute">
      <isabsolute path="${args.csspath}" />
    </condition>
    <!-- Set the csspath as default empty directory when there is no user
      input csspath or user input csspath is a local absolute path. -->
    <condition property="user.csspath" value="">
      <or>
        <not>
          <isset property="args.csspath" />
        </not>
        <isset property="args.csspath.absolute" />
      </or>
    </condition>
    <condition property="user.csspath" value="${args.csspath}/">
      <not>
        <isset property="user.csspath" />
      </not>
    </condition>
    <condition property="args.css.real"
      value="${args.cssroot}${file.separator}${args.css}">
      <isset property="args.cssroot" />
    </condition>
    <condition property="args.css.real" value="${args.css}">
      <not>
        <isset property="args.cssroot" />
      </not>
    </condition>
    <available file="${args.css.real}" property="args.css.present"
      type="file" />
    <basename property="args.css.file.temp" file="${args.css}" />
    <condition property="args.css.file" value="${args.css.file.temp}">
      <isset property="args.css.present" />
    </condition>
    <!-- end to check and init css relevant parameters -->

    <condition property="args.logdir" value="${output.dir}">
      <not>
        <isset property="args.logdir" />
      </not>
    </condition>

    <condition property="index.ext.param.encoding" value="">
      <not>
        <isset property="args.dita.locale" />
      </not>
    </condition>

    <condition property="index.ext.param.encoding"
      value="encoding=${args.dita.locale}">
      <not>
        <isset property="index.ext.param.encoding" />
      </not>
    </condition>

    <condition property="xslt.parser" value="SAXON">
      <isset property="hasSaxon" />
    </condition>
    <condition property="xslt.parser" value="XALAN">
      <not>
        <isset property="xslt.parser" />
      </not>
    </condition>
  	
  	<!-- Validate the xml file or not,default is validation(true)-->
  	<condition property="validate" value="true">
  	   <not>
  		 <isset property="validate" />
  	   </not>
  	</condition>
  	
  	<!--solution for the output control-->
  	<condition property="generate.copy.outer" value="1">
  	   <not>
  		 <isset property="generate.copy.outer" />
  	   </not>
  	</condition>
  	
  	<condition property="onlytopic.in.map" value="false">
  	   <not>
  		 <isset property="onlytopic.in.map" />
  	   </not>
	</condition>
  	<!--
  	default value : warn
	fail     :1a) Fail quickly if files are going to be generated/copied outside of that directory
	warn  :1b) Complete if files will be generated/copied outside, but log a warning
	quiet  :1c) Quietly finish with only those files (no warning or error)
  	-->
  	<condition property="outer.control" value="warn">
  	   <not>
  		 <isset property="outer.control" />
  	   </not>
  	</condition>
  	
  	<!-- Move the outer.transform to build_general.xml -->
	<!--
  	<condition property="outer.transform">
	   <equals arg1="${generate.copy.outer}" arg2="2"></equals>
	</condition>	
    -->
    
    <condition property="inner.transform">
	   <or>
	 	 <equals arg1="${generate.copy.outer}" arg2="1"></equals>
	     <equals arg1="${generate.copy.outer}" arg2="2"></equals>
	   </or>
  	</condition>
  	
  	<condition property="old.transform">
    	<equals arg1="${generate.copy.outer}" arg2="3"></equals>
    </condition>
    
    <!-- output parameters info -->
    <echo>*****************************************************************</echo>
    <echo>* basedir = ${basedir}</echo>
    <echo>* dita.dir = ${dita.dir}</echo>
    <echo>* input = ${args.input}</echo>
    <echo>* transtype = ${transtype}</echo>
    <echo>* tempdir = ${dita.temp.dir}</echo>
    <echo>* outputdir = ${output.dir}</echo>
    <echo>* extname = ${dita.ext}</echo>
    <echo>* clean.temp = ${clean.temp}</echo>
    <echo>* xslt.parser = ${xslt.parser}</echo>
    <echo>*****************************************************************</echo>
  </target>

  <target name="output-msg" depends="output-deprecated-msg, output-css-warn-message"/>
  
  <target name="output-deprecated-msg" if="msg.deprecate">
    <dita-ot-echo id="DOTA005W" />
  </target>
  
  <target name="output-css-warn-message" if="args.csspath.absolute">
    <dita-ot-echo id="DOTA006W" />
  </target>

</project>