hdoc_to_pdf.ant 3.34 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
    <taskdef resource="net/sf/antcontrib/antlib.xml">
      <classpath>
        <pathelement location="lib/ant-contrib.jar"/>
      </classpath>
    </taskdef>
9
10
11
12
13
    <!--<taskdef name="jing" classname="com.thaiopensource.relaxng.util.JingTask">
      <classpath>
        <pathelement location="lib/jing.jar"/>
      </classpath>
    </taskdef>-->
14

15
16
17
    <!-- Arguments properties -->
    <property name="InputPath" location="input"/>
    <property name="OutputPath" location="output"/>
18
    <property name="Schema" location="schemas"/>
19
    <property name="tmpdir" location="${basedir}/tmp"/>
20
21
22
23
24
25
26
27
28
29
30
    <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>

31
32
    </target>

33
34
      

35
36

    <target name="hdocPreparation">
37

38
39
        <!-- Clean the folders before proceeding -->
        <delete>
40
41
          <fileset dir="${OutputPath}" excludes=".gitkeep"/>
          <fileset dir="${tmpdir}" excludes=".gitkeep"/>
42
43
44
45
46
47
48
49
50
51
52
53
54
        </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..."/>
55

56
57
58
59
60
61
62
            <!-- 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>
63
64
65
66

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

        <!-- Unzips the hdoc to be converted-->
67
        <unzip dest="${tmpdir}" src="${InputFile}"/>
68
69

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

72
        <!-- Validating the XML container file -->
73
        <!--<trycatch property="foo" reference="bar">
74
75
76
77
78
79
            <try>
                <jing file="${tmpdir}/META-INF/container.xml" rngfile="${Schema}/container/hdoc1-container.rng"></jing>
            </try>
            <catch>
                <echo>Validation failed</echo>
            </catch>
80
        </trycatch>-->
81
82

        <!--  Launches the XSLT find_content to retrieve the content path -->
83
        <xslt in="${tmpdir}/META-INF/container.xml" out="${tmpdir}/prepare_hdoc.ant" classpath="./lib/saxon9he.jar" style="xsl/find_content.xsl">
84
            <param name="BaseDirectory" expression="${basedir}"/>
85
            <param name="TempDirectory" expression="${tmpdir}"/>
86
        </xslt>
87
        <chmod file="${tmpdir}/prepare_hdoc.ant" perm="777"/>
88

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

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

</project>