wiki_to_hdoc.ant 3.77 KB
Newer Older
1
2
3
<?xml version="1.0" encoding="UTF-8"?>
<project name="wikiToHdoc" default="main" basedir="..">
    
4
5
    <!-- input path -->
    <property name="in"                      value="${basedir}/input"/>
6
    <!-- inputFile is the only required parameter to run the script -->
7
8
    <property name="inputFile"               value="${inputFile}/source.xml"/>
    
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    <basename property="filename"            file="${inputFile}" suffix=".xml"/>
    
    <!-- Folder paths -->
    <!-- tmp paths (removed at the end of the process) -->
    <property name="tmpFolderPath"           value="${basedir}/tmp"/>
    <property name="tmpHdocResultFolderPath" value="${tmpFolderPath}/hdoc"/>
    <!-- ant and xslt paths -->
    <property name="resultFolderPath"        value="${basedir}/result"/>
    <property name="xsltFolderPath"          value="${basedir}/xslt"/>
    <!-- result path -->
    <property name="hdocResultPath"          value="${resultFolderPath}/${filename}"/>
    
    <!-- Main target -->
    <target name="main">
        <antcall target="prepare"/>
        <antcall target="prepareHdocStructure"/>
        <antcall target="transformWikiToHdoc"/>
        <antcall target="zip"/>
        <antcall target="clean"/>
    </target>
    
    <target name="prepare">
        <!-- Create tmp directory for tmp files and result directory if does not exist -->
        <mkdir dir="${tmpHdocResultFolderPath}"/>
        <mkdir dir="${hdocResultPath}"/>
        
        <!-- Making tmp xml wikipedia file without some elements which are not useful -->
36
        <xslt classpath="lib/saxon9he.jar" in="input/${inputFile}" out="${tmpFolderPath}/${filename}_prepared.xml" style="${xsltFolderPath}/prepare_wiki_to_hdoc.xsl">
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
            <factory name="net.sf.saxon.TransformerFactoryImpl"/>
        </xslt>
    </target>
    
    <!-- Create the hdoc structure of the new file -->
    <target name="prepareHdocStructure">
        <mkdir dir="${tmpHdocResultFolderPath}"/>
        <mkdir dir="${tmpHdocResultFolderPath}/META-INF" />
        <touch file="${tmpHdocResultFolderPath}/META-INF/container.xml" />
        <touch file="${tmpHdocResultFolderPath}/mimetype" />
        <echo message="application/x-hdoc+zip" file="${tmpHdocResultFolderPath}/mimetype" />
        <echoxml file="${tmpFolderPath}/containerTmp.xml">
            <container version="1.0" xmlns="urn:utc.fr:ics:hdoc:container">
                <rootfiles>
                    <rootfile full-path="content.xml" media-type="text/xml" />
                </rootfiles>
            </container>
        </echoxml>
55
        <xslt classpath="lib/saxon9he.jar" in="${tmpFolderPath}/containerTmp.xml" out="${tmpHdocResultFolderPath}/META-INF/container.xml" style="${xsltFolderPath}/addNamespaceToContainer.xsl"/>
56
57
58
59
    </target>
    
    <target name="transformWikiToHdoc">
        <!-- Applying wikipedia -> hdoc -->
60
        <xslt classpath="lib/saxon9he.jar" in="${tmpFolderPath}/${filename}_prepared.xml" out="${hdocResultPath}/${filename}.html" style="${xsltFolderPath}/wiki_to_hdoc.xsl">
61
62
63
            <factory name="net.sf.saxon.TransformerFactoryImpl"/>
        </xslt>
        
64
65
66
67
68
        <!-- Copy listing files -->
        <copy todir="${tmpHdocResultFolderPath}/listing" >  
            <fileset dir="${hdocResultPath}/listing" includes="**"/>  
        </copy>
        
69
70
71
72
73
74
75
76
77
78
79
80
81
82
        <!-- Copy of the html file, hdoc needs "container.xml" file, not a html. The html file can be useful to the user -->
        <copy file="${hdocResultPath}/${filename}.html" tofile="${tmpHdocResultFolderPath}/content.xml"/>
    </target>
    
    <!-- Make hdoc file -->
    <target name="zip">
        <zip destfile="${hdocResultPath}/${filename}.hdoc" basedir="${tmpHdocResultFolderPath}"/>
    </target>
    
    <!-- Delete tmp directory -->
    <target name="clean">
        <delete dir="${tmpFolderPath}"/>
    </target>
</project>