framapad_to_hdoc.ant 4.85 KB
Newer Older
1 2
<?xml version="1.0" encoding="UTF-8"?>
<project basedir="." name="myantce" default="main">
3
    <property file="framapad_to_hdoc.properties"/>
4
    <!-- import classes -->
5 6 7
    <taskdef resource="net/sf/antcontrib/antlib.xml"/>
    <taskdef name="htmlcleaner" classname="org.htmlcleaner.HtmlCleanerForAnt"/>
    <taskdef name="jing" classname="com.thaiopensource.relaxng.util.JingTask"/>
8

9 10 11 12 13 14 15 16
    <target name="start">
        <delete dir="${tmp}" failonerror="false"/>
        <mkdir dir="${tmp}"/>
        <delete dir="${out}" failonerror="false"/>
        <mkdir dir="${out}"/>
        <delete dir="${log}" failonerror="false"/>
        <mkdir dir="${log}"/>
    </target>
qaomia's avatar
qaomia committed
17

18 19
    <!-- Apply Xslt -->
    <target name="apply-xslt">
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
        <!-- clean html file (html -> xhtml) -->
        <htmlcleaner src="${in}/${fileName}" dest="${tmp}/pad-clean.xml"/>
        <!-- calls for pad-clean.xml internally -->
        <xslt in="${xsl}/html2xhtml.xsl" out="${tmp}/${properName}/tmpPad.xhtml"
            style="${xsl}/html2xhtml.xsl"/>
        <delete file="${tmp}/pad-clean.xml"></delete>
        
        <xslt in="${tmp}/${properName}/tmpPad.xhtml" out="${tmp}/${properName}/tmpPad2.xhtml"
            style="${xsl}/html2xhtmlv1.xsl"/>
        <xslt in="${tmp}/${properName}/tmpPad2.xhtml" out="${tmp}/${properName}/tmpPad3.xhtml"
            style="${xsl}/html2xhtmlv2.xsl"/>
        <xslt in="${tmp}/${properName}/tmpPad3.xhtml" out="${tmp}/${properName}/tmpPad4.xhtml"
            style="${xsl}/html2xhtml3.xsl"/>
        <xslt in="${tmp}/${properName}/tmpPad4.xhtml" out="${tmp}/${properName}/tozip/content.xml"
            style="${xsl}/xhtml2hdoc.xsl"/>
35
    </target>
36

37 38
    <!-- Builds Hdoc structure -->
    <target name="construct_hdoc">
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
        <mkdir dir="${tmp}/${properName}/tozip/"/>
        <mkdir dir="${tmp}/${properName}/META-INF/"/>
        <mkdir dir="${tmp}/${properName}/tozip/META-INF"/>

        <!-- container -->
        <touch file="${tmp}/${properName}/META-INF/container.xml"/>
        <echoxml file="${tmp}/${properName}/META-INF/container.xml">
            <container version="1.0">
                <rootfiles>
                    <rootfile full-path="${rootfilename}" media-type="text/xml"/>
                </rootfiles>
            </container>
        </echoxml>
        <xslt in="${tmp}/${properName}/META-INF/container.xml"
            out="${tmp}/${properName}/tozip/META-INF/container.xml"
            style="${xsl}/addNamespaceToContainer.xsl"/>

        <!-- mimetype -->
        <touch file="${tmp}/${properName}/mimetype"/>
        <echo message="application/x-hdoc+zip" file="${tmp}/${properName}/tozip/mimetype"/>
59
    </target>
60

61
    <target name="jing-hdoc">
62 63
        <jing file="${tmp}/${properName}/tozip/content.xml"
            rngfile="${schema}/xhtml/hdoc1-xhtml.rng"/>
64
    </target>
65

66 67
    <!-- Zip Hdoc container -->
    <target name="zip">
68 69 70 71 72 73
        <zip basedir="${tmp}/${properName}/tozip/" destfile="${out}/${properName}.hdoc"/>
    </target>

    <target name="main">
        <antcall target="start"/>

74 75
        <for param="inputPad">
            <path>
76
                <fileset dir="${in}" includes="*.html"/>
77 78
            </path>
            <sequential>
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
                <local name="padFileName"/>
                <basename property="padFileName" file="@{inputPad}"/>
                <local name="properFileName"/>
                <basename property="properFileName" file="@{inputPad}" suffix=".html"/>

                <echo>============ Processing pad : ${properFileName} ============</echo>

                <antcall target="apply-xslt">
                    <param name="fileName" value="${padFileName}"/>
                    <param name="properName" value="${properFileName}"/>
                </antcall>

                <antcall target="construct_hdoc">
                    <param name="properName" value="${properFileName}"/>
                </antcall>

                <trycatch>
                    <try>
                        <!-- schema verification -->
                        <antcall target="jing-hdoc">
                            <param name="properName" value="${properFileName}"/>
                        </antcall>
                        <!-- zip hdoc if the schema is verified -->
                        <antcall target="zip">
                            <param name="properName" value="${properFileName}"/>
                        </antcall>
                        <!-- delete tmp files if everything went fine -->
                        <delete dir="${tmp}/${properFileName}" failonerror="false"/>
                    </try>

                    <catch>
                        <echo>WARNING</echo>
                        <echo>${properFileName} : the outptut doesn't match the hdoc schema</echo>
                        <echo>see the Jing log above and the tmp files</echo>
                    </catch>
                </trycatch>
115 116
            </sequential>
        </for>
117
    </target>
118
</project>