hdoc_to_pdf.ant 2.69 KB
Newer Older
Baptiste Perraud's avatar
Baptiste Perraud committed
1
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2
3
<project name="hdoc_to_pdf" basedir="." default="main">

4
5
6
7
8
9
    <taskdef resource="net/sf/antcontrib/antlib.xml">
      <classpath>
        <pathelement location="lib/ant-contrib.jar"/>
      </classpath>
    </taskdef>

10
11
12
    <!-- Arguments properties -->
    <property name="InputPath" location="input"/>
    <property name="OutputPath" location="output"/>
13
    <property name="tmpdir" location="${basedir}/tmp"/>
14
15
16
17
18
19
20
21
22
23
24
    <property name="OutputFileName" location="${OutputPath}/result.pdf"/>

    <target name="main" depends="hdocPreparation">

      <exec executable="java">
          <arg value="-jar"/>
          <arg value="lib/MyPDFGenerator.jar"/>
          <arg value="${dirpath}/final.xhtml"/>
          <arg value="${OutputFileName}"/>
      </exec>

25
26
27
28
    </target>


    <target name="hdocPreparation">
29

30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
        <!-- Clean the folders before proceeding -->
        <delete>
          <fileset dir="${OutputPath}"/>
          <fileset dir="${tmpdir}"/>
        </delete>

        <echo message="Getting input hdoc file..."/>

        <condition property="InputFile.set" else="false">
          <isset property="InputFile"/>
        </condition>

        <if>
          <equals arg1="${InputFile.set}" arg2="false" />
          <then>
            <!-- There is no input, check the input folder -->
            <echo message="Checking the input folder..."/>
47

48
49
50
51
52
53
54
            <!-- Get input hdoc file path -->
            <fileset id="fileset_hdoc" dir="${InputPath}" casesensitive="yes">
                <include name="*.hdoc"/>
            </fileset>
            <pathconvert property="InputFile" pathsep="" refid="fileset_hdoc"/>
          </then>
        </if>
55
56
57
58

        <echo message="Executing conversion..."/>

        <!-- Unzips the hdoc to be converted-->
59
        <unzip dest="${tmpdir}" src="${InputFile}"/>
60
61

        <!-- Gives all rights to avoid bugs-->
62
        <chmod dir="${tmpdir}" perm="777"/>
63

64
        <!-- Launches the XSLT find_content to retrieve the content path -->
65
        <xslt in="${tmpdir}/META-INF/container.xml" out="${tmpdir}/prepare_hdoc.ant" classpath="./lib/saxon9he.jar" style="xsl/find_content.xsl">
66
            <param name="BaseDirectory" expression="${basedir}"/>
67
            <param name="TempDirectory" expression="${tmpdir}"/>
68
        </xslt>
69
        <chmod file="${tmpdir}/prepare_hdoc.ant" perm="777"/>
70

71
        <!-- Launches the ANT prepare_hdoc.ant resulting from the previous XSLT in order to get a clean xhtml ready for the pdf conversion -->
72
        <ant antfile="${tmpdir}/prepare_hdoc.ant"/>
73
74

        <!-- Recover of the dirpath property extracted through find_content.xsl execution -->
75
        <property file="${tmpdir}/my.properties"/>
76
    </target>
Baptiste Perraud's avatar
Baptiste Perraud committed
77
78

</project>