canoprof_to_hdoc.ant 3.64 KB
Newer Older
1 2 3 4 5 6 7 8 9
<project name="ProjetOpale" default="convert" xmlns:if="ant:if"
    xmlns:unless="ant:unless">

    <property file="canoprof_to_hdoc.properties" />

    <!-- Main target -->
    <target name="convert">
        <antcall target="init" />
        <antcall target="unzip_scar" />
Neveux Anais's avatar
Neveux Anais committed
10
        <antcall target="hdoc_structure"/>
11
        <antcall target="process_canoscar"/>
12
		<antcall target="not_canoscar"/>
13 14 15 16 17
        <antcall target="zip" />
        <antcall target="clean"/>
        
    </target>
    
Neveux Anais's avatar
Neveux Anais committed
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
    <!-- Create the hdoc structure -->
    <target name="hdoc_structure">
        <mkdir dir="${hdoc}"/>
        <mkdir dir="${hdoc}/META-INF" />
        <touch file="${hdoc}/META-INF/container.xml" />
        <touch file="${hdoc}/mimetype" />
        <echo message="application/x-hdoc+zip" file="${hdoc}/mimetype" />
        <echoxml file="${hdoc}/META-INF/container.xml" namespacePolicy="elementsOnly">
            <container xmlns="urn:utc.fr:ics:hdoc:container" version="1.0">
                <rootfiles>
                    <rootfile full-path="${rootfilename}" media-type="text/xml" />
                </rootfiles>
            </container>
        </echoxml>
    </target>
33 34 35 36
    
    <!-- Initialize folders -->
    <target name="init">
        <!-- create folders (to be sure) -->
37 38 39
        <delete>
            <fileset file="${out}/*.hdoc"/>
        </delete>
40 41 42 43 44 45 46 47 48 49 50
        <mkdir dir="${unzipfolder}"/>
        <mkdir dir="${tmp}"/>
        <mkdir dir="${out}"/>
        <touch file="get_ressources.ant"/>
    </target>
    
    <!-- Clean : delete old files -->
    <target name="clean">
        <!-- delete folders -->
        <delete dir="${unzipfolder}"/>
        <delete dir="${tmp}"/>
51
        <delete dir="${hdoc}"/>
52 53 54 55 56 57 58 59 60 61 62 63 64
        <delete file="get_ressources.ant"/>
    </target>
    
    <!-- Check if the scar input is a Canoprof one or not -->
    <target name="check_scar">
        <xmlproperty semanticattributes="true" file="${unzipfolder}/.wspmeta" keeproot="true"/>
        <condition property="canoprof.is_canoprof_scar">
            <equals arg1="${wspType.defaultCode}" arg2="${canoprof_code}"/>
        </condition>
    </target>
    
    
    <target name="process_canoscar" depends="check_scar" if="${canoprof.is_canoprof_scar}">
Neveux Anais's avatar
Neveux Anais committed
65
        <!-- TODO change test.xml to the temporary file created while fusioning all the xml files -->
66 67 68
        <copy tofile="${unzipfolder}/Test.programme">
            <fileset file="${unzipfolder}/*.programme"/>
        </copy>
69
        <xslt style="xsl/programmation.xsl" in="${unzipfolder}/Test.programme" out="${hdoc}/content.xml" classpath="./lib/saxon9he.jar">
Neveux Anais's avatar
Neveux Anais committed
70 71
            <factory name="net.sf.saxon.TransformerFactoryImpl"/>
        </xslt>
72 73
    </target>
    
74 75 76 77
	<target name="not_canoscar" depends="check_scar" unless="${canoprof.is_canoprof_scar}">
        <echo file="${out}/scar_cano_or_not_scar_cano.txt" message="Ce n'est pas un scar canoprof"/>
    </target>
	
78 79 80 81 82 83 84 85 86 87 88 89
    <!-- Unzip the scar -->
    <target name="unzip_scar">
        <!-- get scar file path -->
        <fileset id="fileset_scar" dir="input" casesensitive="yes">
            <include name="*.scar"/>
        </fileset>
        <pathconvert property="scar.path" pathsep="" refid="fileset_scar" />
        <unzip src="${scar.path}" dest="${unzipfolder}"/>
    </target>
    
    <!-- Zip the final content into a scar file -->
    <target name="zip">
Neveux Anais's avatar
Neveux Anais committed
90 91 92 93 94 95
        <fileset id="fileset_scar" dir="input" casesensitive="yes">
            <include name="*.scar"/>
        </fileset>
        <pathconvert property="scar.path" pathsep="" refid="fileset_scar" />
        <basename property="filename" file="${scar.path}" suffix=".scar"/>
        <zip destfile="${out}/${filename}.hdoc" basedir="${hdoc}"/>
96 97
    </target>
</project>