hdoc_to_epub.ant 3.12 KB
Newer Older
1
<?xml version="1.0" encoding="UTF-8"?>
cliclac's avatar
cliclac committed
2 3 4
<project name="hdoc_to_epub" basedir="." default="convert">

  <taskdef resource="net/sf/antcontrib/antlib.xml"/>
cliclac's avatar
cliclac committed
5
  <taskdef name="jing" classname="com.thaiopensource.relaxng.util.JingTask"/>
cliclac's avatar
cliclac committed
6 7 8 9

  <property name="in" location="${basedir}/input"/>
  <property name="out" location="${basedir}/output"/>
  <property name="tmp" location="${basedir}/tmp"/>
cliclac's avatar
cliclac committed
10
  <property name="xsl" location="${basedir}/xsl"/>
Asus-PC's avatar
Asus-PC committed
11
  <property name="file" location="${basedir}/file"/>
cliclac's avatar
cliclac committed
12
  <property name="schema" location="${basedir}/schema"/>
cliclac's avatar
cliclac committed
13
  <property name="lib" location="${basedir}/lib"/>
cliclac's avatar
cliclac committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39

  <target name="convert">
    <delete dir="${tmp}" failonerror="false"/>
    <sleep seconds="1"/>
    <mkdir dir="${tmp}"/>

    <delete dir="${out}" failonerror="false"/>
    <sleep seconds="1"/>
    <mkdir dir="${out}"/>

    <for param="inputFile">
      <path>
        <fileset dir="${in}" includes="**/*.hdoc"/>
      </path>

      <sequential>
        <local name="filename"/>
        <basename property="filename" file="@{inputFile}"/>

        <antcall target="UnzipHdocFile">
          <param name="filename" value="${filename}"/>
        </antcall>

        <antcall target="ValidateInput">
          <param name="filename" value="${filename}"/>
        </antcall>
Asus-PC's avatar
Asus-PC committed
40 41 42

        <antcall target="MakeOCF"/>

cliclac's avatar
cliclac committed
43 44 45
        <antcall target="MakeOPF">
          <param name="filename" value="${filename}"/>
        </antcall>
Asus-PC's avatar
Asus-PC committed
46

cliclac's avatar
cliclac committed
47 48 49
        <antcall target="MakeOPS">
          <param name="filename" value="${filename}"/>
        </antcall>
Asus-PC's avatar
Asus-PC committed
50

cliclac's avatar
cliclac committed
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
      </sequential>
    </for>
  </target>

  <target name="UnzipHdocFile">
    <!-- Unzip the input hdoc file. Decompressed folder is named "decompressedHdoc" : this name is the only one which
    refers to the hdoc file furthermore in this project. -->
    <unzip src="${in}/${filename}" dest="${tmp}/${filename}/decompressedHdoc"/>
    <chmod dir="${tmp}/${filename}/decompressedHdoc" perm="777"/>
  </target>

  <!-- Validating the XML container file -->
	<target name="ValidateInput">
    <trycatch property="foo" reference="bar">
      <try>
        <jing file="${tmp}/${filename}/decompressedHdoc/META-INF/container.xml" rngfile="${schema}/hdoc1-container.rng"></jing>
      </try>
      <catch>
        <echo>Validation failed</echo>
      </catch>
    </trycatch>
	</target>

Asus-PC's avatar
Asus-PC committed
74 75 76 77 78 79 80 81
  <target name="MakeOCF">
    <mkdir dir="${out}/META-INF"/>
    <mkdir dir="${out}/oebps"/>
    <copy file="${file}/mimetype" todir="${out}"/>
    <copy file="${file}/container.xml" todir="${out}/META-INF"/>
  </target>

  <target name="MakeOPF">
cliclac's avatar
cliclac committed
82
    <xslt in="${tmp}/${filename}/decompressedHdoc/content.xml" out="${out}/oebps/content.xml" classpath="${lib}/saxon9he.jar" style="${xsl}/content.xsl"/>
Asus-PC's avatar
Asus-PC committed
83 84 85 86
  </target>

  <target name="MakeOPS">
    <mkdir dir="${out}/oebps/images"/>
cliclac's avatar
cliclac committed
87 88 89
    <copy todir="${out}/oebps/images">
      <fileset dir="${tmp}/${filename}/decompressedHdoc/re" includes="**"/>
    </copy>
Asus-PC's avatar
Asus-PC committed
90
    <mkdir dir="${out}/oebps/styles"/>
cliclac's avatar
cliclac committed
91 92 93
    <mkdir dir="${out}/oebps/chapitres"/>
    <xslt in="${tmp}/${filename}/decompressedHdoc/content.xml" out="${out}/oebps/tableDesMatieres.ncx" classpath="${lib}/saxon9he.jar" style="${xsl}/tdmncx.xsl"/>

Asus-PC's avatar
Asus-PC committed
94 95
  </target>

96
</project>