<?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. 2001, 2006 All Rights Reserved. -->
<project name="dita.build.demo" default="prompt" basedir=".">
	<!-- Set a property for each environment variable -->
	<description>Build the DITA Demos and Samples</description>
	<property environment="env"/>

  <import file="${basedir}${file.separator}build.xml"/>
  
  <import file="${basedir}/samples/ant_sample/sample_all.xml"/>

	<target name="use.init">
        <available classname="net.sf.saxon.StyleSheet"
			property="hasSaxon"/>
		<available classname="org.apache.fop.tools.anttasks.Fop"
			property="hasFOP"/>
		<available file="C:\Program Files\HTML Help Workshop\hhc.exe"
			property="HTMLHelpCompiler"
			value="C:\Program Files\HTML Help Workshop\hhc.exe"/>
		<property name="dita.extname" value=".xml"/>
		<property name="clean.temp" value="true"/>
	</target>

	<target name="all" description="build all output" 
		depends="samples">
		<echo>Output from the demo build is in the directory
${dita.output.dir}

Previous releases also built a copy of the DITA 1.1 Language
specification. The toolkit now fully supports DITA 1.2, but
that specification is not included here due to its size.
Source material and published versions of the latest DITA 1.2
specification can be found here:
http://docs.oasis-open.org/dita/v1.2/spec/DITA1.2-spec.html</echo>
	</target>
	<!-- revise below here -->

	<!-- defaults for DITA configuration required by callable targets -->
	<property name="dita.dir" value="${basedir}"/>
	<property name="dita.script.dir"
		value="${dita.dir}${file.separator}xsl"/>
	<property name="dita.dtd.dir"
		value="${dita.dir}${file.separator}dtd"/>
	<property name="dita.css.dir"
		value="${dita.dir}${file.separator}css"/>
	<property name="dita.resource.dir"
		value="${dita.dir}${file.separator}resource"/>

	<!-- defaults for DITA output configuration -->
	<property name="dita.doc.dir"
		value="${dita.dir}${file.separator}doc"/>
	<property name="dita.doc.langref.dir"
		value="${dita.doc.dir}${file.separator}langref-dita1.1"/>
	<property name="dita.doc.articles.dir"
		value="${dita.doc.dir}${file.separator}articles"/>
	
	<property name="dita.samples.dir"
		value="${dita.dir}${file.separator}samples"/>

	<property name="dita.output.dir"
		value="${dita.dir}${file.separator}out"/>

	<property name="dita.output.docbook.dir"
		value="${dita.output.dir}${file.separator}docbook"/>



	<target name="clean"
		description="delete all output">
		<delete dir="${dita.output.dir}"/>
	</target>

	<!-- mid-level targets -->
	<target name="init"
		depends="use.init">
		<!-- Create the time stamp -->
		<tstamp/>
		<mkdir dir="${dita.temp.dir}"/>
		<mkdir dir="${dita.output.dir}"/>
	</target>

	<target name="doc"
		description="build the documentation"
		depends="init, doc.articles.web, doc.readme.web, doc.installguide.chm">      
	</target>
	
	<target name="init.doc.articles" depends="init">
		<mkdir dir="${dita.output.doc.articles.dir}"/>
	</target>
	
	<target name="doc.articles.web" depends="init.doc.articles"
		description="Build the articles of dita as document.">
		<antcall target="dita2xhtml">
			<param name="args.input"
				value="${dita.doc.articles.dir}${file.separator}DITA-articles.ditamap"/>
			<param name="output.dir"     value="${dita.output.doc.articles.dir}"/>
      <param name="transtype" value="xhtml"/>
		</antcall>
	</target>
    
    <target name="doc.articles.chm" depends="init.doc.articles"
		description="Build the articles of dita as document.">
		<antcall target="dita2htmlhelp">
			<param name="args.input"
				value="${dita.doc.articles.dir}${file.separator}DITA-articles.ditamap"/>
			<param name="output.dir"     value="${dita.output.doc.articles.dir}"/>
      <param name="transtype" value="htmlhelp"/>
		</antcall>
	</target>
    
    <target name="doc.articles.pdf" depends="init.doc.articles"
		description="Build the articles of dita as document.">
    	<!-- DOST is the project name of imported build.xml-->
		<antcall target="DOST.init">
			<param name="args.input"      
				value="${dita.doc.articles.dir}${file.separator}DITA-articles.ditamap"/>
			<param name="output.dir"      value="${dita.output.doc.articles.dir}"/>
      		<param name="transtype" value="pdf"/>
		</antcall>
	</target>
	
	<target name="clean.doc.articles"
		description="Delete the articles directory in doc.">
		<delete dir="${dita.output.doc.articles.dir}"></delete>
	</target>
	
	<target name="doc.readme.web" depends="init">
		<antcall target="dita2xhtml">
			<param name="args.input"
				value="${dita.doc.dir}${file.separator}readme.ditamap"/>
			<param name="output.dir"     value="${dita.output.doc.dir}"/>
      <param name="transtype" value="xhtml"/>
		</antcall>
	</target>
    
    <target name="doc.readme.chm" depends="init">
		<antcall target="dita2htmlhelp">
			<param name="args.input"
				value="${dita.doc.dir}${file.separator}readme.ditamap"/>
			<param name="output.dir"     value="${dita.output.doc.dir}"/>
      <param name="transtype" value="htmlhelp"/>
		</antcall>
	</target>
    
    <target name="doc.readme.pdf" depends="init">
    	<!-- DOST is the project name of imported build.xml-->
		<antcall target="DOST.init">
			<param name="args.input"      
				value="${dita.doc.dir}${file.separator}readme.ditamap"/>
			<param name="output.dir"      value="${dita.output.doc.dir}"/>
      		<param name="transtype" value="pdf"/>
		</antcall>
	</target>
	
	<target name="doc.installguide.web" depends="init">
		<antcall target="dita2xhtml">
			<param name="args.input"
				value="${dita.doc.dir}${file.separator}ot-userguide${file.separator}DITAOT_UGRef_SOURCE${file.separator}installing${file.separator}installing_map.ditamap"/>
			<param name="output.dir" value="${dita.output.doc.dir}${file.separator}installguide"/>
      <param name="transtype" value="xhtml"/>
		</antcall>
	</target>
    
	<target name="doc.installguide.chm" depends="init">
		<antcall target="dita2htmlhelp">
			<param name="args.input"
				value="${dita.doc.dir}${file.separator}ot-userguide${file.separator}DITAOT_UGRef_SOURCE${file.separator}installing${file.separator}installing_map.ditamap"/>
			<param name="output.dir" value="${dita.output.doc.dir}${file.separator}installguide"/>
      <param name="transtype" value="htmlhelp"/>
		</antcall>
	</target>
  
	<target name="doc.installguide.pdf" depends="init">
		<!-- DOST is the project name of imported build.xml-->
		<antcall target="DOST.init">
			<param name="args.input"      
				value="${dita.doc.dir}${file.separator}ot-userguide${file.separator}DITAOT_UGRef_SOURCE${file.separator}installing${file.separator}installing_map.ditamap"/>
			<param name="output.dir"      value="${dita.output.doc.dir}${file.separator}installguide"/>
      		<param name="transtype" value="pdf"/>
		</antcall>
	</target>
	
	<target name="doc.quickstartguide.chm" depends="init">
		<antcall target="dita2htmlhelp">
			<param name="args.input"
			  value="${dita.doc.dir}${file.separator}quickstartguide.ditamap"/>
			<param name="output.dir" value="${dita.output.doc.dir}"/>
      <param name="transtype" value="htmlhelp"/>
		</antcall>
	</target>
  
	<target name="doc.quickstartguide.pdf" depends="init">
		<!-- DOST is the project name of imported build.xml-->
		<antcall target="DOST.init">
			<param name="args.input"
			  value="${dita.doc.dir}${file.separator}quickstartguide.ditamap"/>
			<param name="output.dir" value="${dita.output.doc.dir}"/>
      		<param name="transtype" value="pdf"/>
		</antcall>
	</target>

	<target name="clean.doc"
		description="remove the documentation output">
		<delete dir="${dita.output.doc.dir}"/>
	</target>
	
	<target name="docbook"
		description="transform the samples to DocBook"
		depends="init">
		<mkdir dir="${dita.output.docbook.dir}"/>

		<antcall target="samples.docbook"/>

		<antcall target="dita2docbook">
			<param name="args.input"
				value="${dita.doc.dir}${file.separator}readme${file.separator}DITA-readme.xml"/>
			<param name="output.dir"
				value="${dita.output.docbook.dir}"/>
      <param name="transtype" value="docbook"/>
		</antcall>
	</target>
	
	<target name="clean.docbook"
		description="remove the docbook output">
		<delete dir="${dita.output.docbook.dir}"/>
	</target>	
    
	<!-- prompting target -->
	<target name="prompt"
		description="prompt to build anything"
		depends="prompt.init">
		<!-- The prompt strings should be externalized in a properties file 
	     so they can be localized. -->
		<echo>Please enter the filename for the DITA map that you 
want to build including the directory path (if any).
The filename must have the .ditamap extension.
Note that relative paths that climb (..) are not supported yet.
To build the sample, press return without entering anything.</echo>
		<input message="The DITA map filename: "
			addproperty="prompt.ditamap.filename"
			defaultvalue="${dita.samples.dir}${file.separator}hierarchy.ditamap"/>
		<fail message="no map entered">
			<condition>
				<or>
					<not><isset property="prompt.ditamap.filename"/></not>
					<equals arg1="${prompt.ditamap.filename}" arg2=""/>
				</or>
			</condition>
		</fail>
		<fail message="cannot find ${prompt.ditamap.filename}">
			<condition>
				<not><available file="${prompt.ditamap.filename}"/></not>
			</condition>
		</fail>
		<basename property="prompt.ditamap.fileroot"
			file="${prompt.ditamap.filename}" suffix=".ditamap"/>
		<dirname property="prompt.ditamap.directory"
			file="${prompt.ditamap.filename}"/>
		<echo>
Please enter the name of the output directory or press return
to accept the default.</echo>
		<input message="The output directory (out): "
			addproperty="prompt.output.directory"
			defaultvalue="out"/>
		<echo>
Please enter the type of output to generate.
Options include: eclipse, tocjs, htmlhelp, javahelp, pdf, or web
Use lowercase letters.
		</echo>
		<input message="The output type: "
			addproperty="prompt.output.type"
			validargs="eclipse,tocjs,htmlhelp,javahelp,pdf,web,docbook"
			defaultvalue="web"/>
		<condition property="isEclipseOutput">
			<equals arg1="${prompt.output.type}" arg2="eclipse"/>
		</condition>
		<condition property="isTocjsOutput">
			<equals arg1="${prompt.output.type}" arg2="tocjs"/>
		</condition>
		<condition property="isHtmlHelpOutput">
			<equals arg1="${prompt.output.type}" arg2="htmlhelp"/>
		</condition>
		<condition property="isJavaHelpOutput">
			<equals arg1="${prompt.output.type}" arg2="javahelp"/>
		</condition>
		<condition property="isPDFOutput">
			<equals arg1="${prompt.output.type}" arg2="pdf"/>
		</condition>
		<condition property="isWebOutput">
			<equals arg1="${prompt.output.type}" arg2="web"/>
		</condition>
		<condition property="isDocbookOutput">
			<equals arg1="${prompt.output.type}" arg2="docbook"/>
		</condition>
		<echo>
Ready to build ${prompt.ditamap.filename}
for ${prompt.output.type} in ${prompt.output.directory}
		</echo>
		<input message="Continue? "
			addproperty="prompt.output.confirm"
			validargs="Y,y,N,n"
			defaultvalue="y"/>
		<fail message="not building">
			<condition>
				<or>
					<equals arg1="${prompt.output.confirm}" arg2="N"/>
					<equals arg1="${prompt.output.confirm}" arg2="n"/>
				</or>
			</condition>
		</fail>
		<antcall target="prompt.output"/>
	    <echo>
output in the ${prompt.output.directory} directory
    		
Before rebuilding, please delete the output or the directory.</echo>
	</target>

	<target name="prompt.init">
		<!-- Create the time stamp -->
		<tstamp/>
	</target>

	<target name="prompt.output.init" depends="init">
		<mkdir dir="${prompt.output.directory}"/>
	</target>

	<target name="prompt.output"
		depends="prompt.output.eclipse, prompt.output.tocjs, prompt.output.javahelp, prompt.output.htmlhelp, prompt.output.pdf, prompt.output.web, prompt.output.docbook"/>

	<target name="prompt.output.web" depends="prompt.output.init"
		if="isWebOutput">			
		<copy todir="${prompt.output.directory}">
			<fileset dir="${dita.resource.dir}"
				includes="index.html"/>
		</copy>
		<antcall target="dita2xhtml">
			<param name="args.input"      value="${prompt.ditamap.filename}"/>
			<param name="output.dir"     value="${prompt.output.directory}"/>
			<param name="args.xhtml.toc" value="toc"/>
			<param name="dita.temp.dir" value="temp"/>
      <param name="transtype" value="xhtml"/>
		</antcall>
	</target>

	<target name="prompt.output.eclipse" depends="prompt.output.init"
		if="isEclipseOutput">
		<antcall target="dita2eclipsehelp">
			<param name="args.input"      value="${prompt.ditamap.filename}"/>
			<param name="output.dir"     value="${prompt.output.directory}"/>
			<param name="args.eclipse.toc" value="toc"/>
			<param name="dita.temp.dir" value="temp"/>
      <param name="transtype" value="eclipsehelp"/>
		</antcall>
	</target>

	<target name="prompt.output.tocjs" depends="prompt.output.init"
		if="isTocjsOutput">
		<antcall target="dita2tocjs">
			<param name="args.input"      value="${prompt.ditamap.filename}"/>
			<param name="output.dir"     value="${prompt.output.directory}"/>
			<param name="dita.temp.dir" value="temp"/>
      <param name="transtype" value="tocjs"/>
		</antcall>
	</target>

	<target name="prompt.output.javahelp" depends="prompt.output.init"
		if="isJavaHelpOutput">
		<antcall target="dita2javahelp">
			<param name="args.input"      value="${prompt.ditamap.filename}"/>
			<param name="output.dir"     value="${prompt.output.directory}"/>
			<param name="args.javahelp.toc" value="toc"/>
			<param name="args.javahelp.map" value="map"/>
			<param name="dita.temp.dir" value="temp"/>
      <param name="transtype" value="javahelp"/>
		</antcall>
	</target>

	<target name="prompt.output.htmlhelp" depends="prompt.output.init"
		if="isHtmlHelpOutput">
		<antcall target="dita2htmlhelp">
			<param name="args.input"
				value="${prompt.ditamap.filename}"/>
			<param name="output.dir"
				value="${prompt.output.directory}"/>
			<param name="dita.temp.dir" value="temp"/>
      <param name="transtype" value="htmlhelp"/>
		</antcall>
	</target>

	<target name="prompt.output.pdf" depends="prompt.output.init"
		if="isPDFOutput">
		<!-- DOST is the project name of imported build.xml-->
		<antcall target="DOST.init">
			<param name="args.input"      
				value="${prompt.ditamap.filename}"/>
			<param name="output.dir"      value="${prompt.output.directory}"/>
			<param name="dita.temp.dir" value="temp"/>
      		<param name="transtype" value="pdf"/>
		</antcall>
	</target>

	<target name="prompt.output.docbook" depends="prompt.output.init"
		if="isDocbookOutput">
		<antcall target="dita2docbook">
			<param name="args.input"       value="${prompt.ditamap.filename}"/>
			<param name="output.dir"      value="${prompt.output.directory}"/>
			<param name="dita.temp.dir" value="temp"/>
      <param name="transtype" value="docbook"/>
		</antcall>
	</target>
  	
  <!-- The whole process on which javamerge depends equals to the target "dita-process" in build.xml. -->
  <target name="javamerge"  description="Merge topics" depends="start-process, init-logger, check-arg, output-deprecated-msg, output-css-warn-message, preprocess">
	<basename property="temp.base" file="${user.input.file}" suffix=".ditamap"/>
    <property name="temp.input" value="${dita.temp.dir}${file.separator}${user.input.file}"/>
    <property name="temp.output" value="${output.dir}${file.separator}${user.input.file}"/>
    <dirname property="temp.dir" file="${temp.input}"/>
    <dirname property="temp.outdir" file="${temp.output}"/>
    <pipeline message="topicmerge" module="TopicMerge" 
      inputmap="${temp.dir}${file.separator}${temp.base}.ditamap" 
      tempdir="${dita.temp.dir}">
      <param name="output" location="${temp.outdir}${file.separator}${temp.base}_merged.xml"/>
    </pipeline>
  </target>
	
</project>
