Created
May 11, 2012 09:15
-
-
Save mkarg/2658574 to your computer and use it in GitHub Desktop.
Applying multiple .ditaval filters on the same .ditamap (automatically, using ANT)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" ?> | |
<!-- | |
To be published under the same terms as DITA-OT. | |
This script allows to execute DITA-OT upon a set | |
of automatically found .ditaval files, e. g. to | |
build multiple editions of the same .ditamap | |
project. | |
To use this script in ANT, do the following: | |
<include file="ant-ditaot-macro.xml" /> | |
<target name="PDFs"> | |
<dita-ot sourceFile="src/main/dita/my.ditamap" outputDir="target"> | |
<fileset dir="src/main/dita" includes="*.ditaval" /> | |
</dita-ot> | |
</target> | |
Note that this script is just a prototype and | |
does not support lots of DITA-OT features. | |
It is developed and tested solely with PDFs. | |
Any improvements welcome! :-) | |
Copyright © 2012 QUIPSY QUALITY GmbH & Co. KG | |
Author(s): | |
Markus KARG ([email protected]) | |
--> | |
<project name="ant-ditaot-macro"> | |
<property environment="env" /> | |
<property name="temp.dir" location="${env.TEMP}" /> | |
<property name="dita.dir" location="${env.DITA_HOME}" /> | |
<macrodef name="call-dita-ot"> | |
<attribute name="sourceFile" /> | |
<attribute name="filterFile" /> | |
<attribute name="outputDir" default="${basedir}" /> | |
<attribute name="outputName" /> | |
<!-- The below attributes are necessary because building those using <basedir/> is not possible when macro is called from script, as properties are GLOBAL then! --> | |
<attribute name="filterName" /> | |
<attribute name="sourceName" /> | |
<sequential> | |
<java classname="org.apache.tools.ant.launch.Launcher" fork="true" failonerror="true" taskname="dita-ot"> | |
<classpath> | |
<pathelement location="${dita.dir}/tools/ant/lib/ant-launcher.jar" /> | |
</classpath> | |
<arg value="-f" /> | |
<arg file="${dita.dir}/build.xml" /> | |
<arg value="-lib" /> | |
<arg value="${dita.dir}/tools/ant/lib;${dita.dir}/lib;${dita.dir}/lib/saxon" /> | |
<arg value="-Dbasedir=${basedir}" /> | |
<arg value="-Dargs.input=@{sourceFile}" /> | |
<arg value="-Ddita.input.valfile=@{filterFile}" /> | |
<arg value="-Doutput.dir=${env.TEMP}/ditaot/@{filterName}/out" /> | |
<arg value="-Dtranstype=pdf" /> | |
<arg value="-Ddita.temp.dir=${env.TEMP}/ditaot/@{filterName}/temp" /> | |
</java> | |
<move file="${env.TEMP}/ditaot/@{filterName}/out/@{sourceName}.pdf" tofile="@{outputDir}/@{outputName}.pdf" /> | |
</sequential> | |
</macrodef> | |
<scriptdef name="dita-ot" language="javascript"> | |
<attribute name="sourceFile" /> | |
<attribute name="outputDir" /> | |
<element name="fileset" type="fileset" /> | |
<![CDATA[ | |
importClass(java.io.File); | |
sourceFile = attributes.get("sourcefile"); | |
outputDir = attributes.get("outputdir"); | |
sourceName = new File(sourceFile).getName().replaceFirst("[.][^.]+$", ""); // Strip file extension | |
filesets = elements.get("fileset"); | |
fileSeparator = self.project.getProperty("file.separator"); | |
parallel = self.project.createTask("parallel"); | |
for (i = 0; i < filesets.size(); i++) { | |
fileset = filesets.get(i); | |
scanner = fileset.getDirectoryScanner(project); | |
scanner.scan(); | |
files = scanner.getIncludedFiles(); | |
for (j = 0; j < files.length; j++) { | |
filterFile = fileset.getDir() + fileSeparator + files[j]; | |
filterName = new File(filterFile).getName().replaceFirst("[.][^.]+$", ""); // Strip file extension | |
outputName = java.lang.String.format("%s (%s)", sourceName, filterName); | |
macro = self.project.createTask("call-dita-ot"); | |
macro.setDynamicAttribute("sourcefile", sourceFile); | |
macro.setDynamicAttribute("filterfile", filterFile); | |
macro.setDynamicAttribute("outputdir", outputDir); | |
macro.setDynamicAttribute("outputname", outputName); | |
macro.setDynamicAttribute("sourcename", sourceName); | |
macro.setDynamicAttribute("filtername", filterName); | |
parallel.addTask(macro); | |
} | |
} | |
parallel.execute(); | |
]]> | |
</scriptdef> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment