opale_to_hdoc.ant 3.29 KB
Newer Older
Drain's avatar
Drain committed
1 2 3
<project name="ProjetOpale" default="convert">
	
	<!-- Other properties -->
4
	<property name="UnzipSourcePath" 	value="unzipSourcePath" />
Drain's avatar
Drain committed
5
	<property name="XmlModuleName" 		value="" />
6 7
	<property name="TmpPath" 			value="tmp" />
	<property name="TmpFile1" 			value="tmpFile1.xml" />
Drain's avatar
Drain committed
8
	<property name="RacineFile" 		value="content.xml" />
9 10 11
	<property name="OutputPath"			value="output" />
	<property name="HdocPath" 			value="${OutputPath}/hdoc" />
	<property name="ZipPath" 			value="${OutputPath}/result.hdoc" />
Drain's avatar
Drain committed
12 13 14 15 16 17 18 19 20 21 22 23
	
	<!-- Others properties (in another file) currently empty -->
	<property file="opale_to_hdoc.properties" />

	<!-- Beginning -->
	<target name="convert">
		<antcall target="unzip_scar" />	  	
		<antcall target="check_source_xml" />
		<antcall target="hdoc_structure" />
		<antcall target="fusion_xml" />
		<antcall target="content_xml" />
		<antcall target="zip" />
Hachem Rihab's avatar
Hachem Rihab committed
24
		<antcall target="clean" />
Drain's avatar
Drain committed
25 26 27 28 29
	</target>
		
	<!-- Clean : delete old files -->
	<target name="clean">
		<!-- delete folders -->
30 31 32
		<!--delete dir="${UnzipSourcePath}"/-->
		<!--delete dir="${TmpPath}"/-->
		<!--delete dir="${HdocPath}"/-->
Drain's avatar
Drain committed
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
	</target>
	
	<!-- Check if only one xml file -->
	<target name="check_source_xml">
		
		<!-- count xml files -->
		<resourcecount property="xml.count">
			<fileset dir="${UnzipSourcePath}" casesensitive="yes">
				<include name="*.xml"/>
			</fileset>
		</resourcecount>
		
		<!-- check if only one xml file -->
		<condition  property="xml.onlyone">
			<equals arg1="${xml.count}" arg2="1"/>
		</condition>
		
		<!-- fail if more than one -->
		<fail message="Error : too many source file (${xml.count}), source file not found or unreadable." unless="xml.onlyone"/>

	</target>
	
	<!-- Unzip scar source file -->
	<target name="unzip_scar">
57 58 59 60 61 62
		<!-- 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="./${UnzipSourcePath}"/>
Drain's avatar
Drain committed
63 64 65 66 67 68 69 70 71
	</target>
	
	<!-- Create the hdoc structure -->
	<target name="hdoc_structure">
		<mkdir dir="${HdocPath}"/>
		<mkdir dir="${HdocPath}/META-INF" />
		<touch file="${HdocPath}/META-INF/container.xml" />
		<touch file="${HdocPath}/mimetype" />
		<echo message="application/x-hdoc+zip" file="${HdocPath}/mimetype" />
72 73
		<echoxml file="${HdocPath}/META-INF/container.xml" namespacePolicy="elementsOnly">
			<container xmlns="urn:utc.fr:ics:hdoc:container" version="1.0">
Drain's avatar
Drain committed
74
				<rootfiles>
75
					<rootfile full-path="${RacineFile}" media-type="text/xml" />
Drain's avatar
Drain committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
				</rootfiles>
			</container>
		</echoxml>
	</target>

	<!-- Make a unique xml source file -->
	<target name="fusion_xml">
		
		<!-- get xml source file path -->
		<fileset id="fileset_source_xml" dir="${UnzipSourcePath}" casesensitive="yes">
			<include name="*.xml"/>
		</fileset>
		<pathconvert property="xml.path" pathsep="" refid="fileset_source_xml" />
		
		<!-- xsl -->
91
		<xslt style="xsl/opale_to_hdoc_regle1.xsl" in="${xml.path}" out="./${TmpPath}/${TmpFile1}">
Drain's avatar
Drain committed
92 93 94 95 96 97
		</xslt>
		
	</target>
	
	<!-- Create content.xml -->
	<target name="content_xml">	
98
		<xslt style="xsl/opale_to_hdoc_regle2.xsl" in="./${TmpPath}/${TmpFile1}" out="./${HdocPath}/${RacineFile}" />
Drain's avatar
Drain committed
99 100 101 102
	</target>
	
	<!-- Zip Hdoc -->
	<target name="zip">
103
		<zip destfile="${ZipPath}" basedir="${HdocPath}"/>
Drain's avatar
Drain committed
104 105
	</target>
</project>