opale_to_hdoc.ant 4.48 KB
Newer Older
Drain's avatar
Drain committed
1
2
<project name="ProjetOpale" default="convert">
	
Tyrannas's avatar
Tyrannas committed
3
4
5
6
7
8
9
	<!-- additionnal lib -->
    <taskdef resource="net/sf/antcontrib/antlib.xml">
        <classpath>
            <pathelement location="lib/ant-contrib.jar"/>
        </classpath>
    </taskdef> 

Drain's avatar
Drain committed
10
	<!-- Other properties -->
Tyrannas's avatar
Tyrannas committed
11
	<property name="ScarPath" 	value="input" />
12
	<property name="UnzipSourcePath" 	value="unzipSourcePath" />
Drain's avatar
Drain committed
13
	<property name="XmlModuleName" 		value="" />
14
15
	<property name="TmpPath" 			value="tmp" />
	<property name="TmpFile1" 			value="tmpFile1.xml" />
Drain's avatar
Drain committed
16
	<property name="RacineFile" 		value="content.xml" />
17
18
	<property name="OutputPath"			value="output" />
	<property name="HdocPath" 			value="${OutputPath}/hdoc" />
Drain's avatar
Drain committed
19
20
21
22
23
24
	
	<!-- Others properties (in another file) currently empty -->
	<property file="opale_to_hdoc.properties" />

	<!-- Beginning -->
	<target name="convert">
25
26
27
		<delete>
          <fileset dir="${OutputPath}" excludes=".gitkeep"/>
        </delete>
28
		<mkdir dir="${OutputPath}"/>
Tyrannas's avatar
Tyrannas committed
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
		<for param="filename">
            <path>
                <fileset dir="./input" includes="*.scar"/>
            </path>
            <sequential>
                <var name="newFileName" unset="true"/>
                <basename  property="newFileName" file="@{filename}"/>
				<antcall target="clean" />
				<antcall target="unzip_scar"> 
					<param name="file" value="${newFileName}"/>
				</antcall>	  	
				<antcall target="check_source_xml" />
				<antcall target="hdoc_structure" />
				<antcall target="fusion_xml" />
				<antcall target="copy_ressources"/>
				<antcall target="content_xml" />
				<antcall target="zip">
					<param name="file" value="${newFileName}"/>
				</antcall>
			</sequential>
		</for>
Hachem Rihab's avatar
Hachem Rihab committed
50
		<antcall target="clean" />
Drain's avatar
Drain committed
51
	</target>
52
	
Drain's avatar
Drain committed
53
54
55
	<!-- Clean : delete old files -->
	<target name="clean">
		<!-- delete folders -->
Hachem Rihab's avatar
Hachem Rihab committed
56
57
58
		<delete dir="${UnzipSourcePath}"/>
		<delete dir="${TmpPath}"/>
		<delete dir="${HdocPath}"/>
59
		<delete file="get_ressources.ant"></delete>
Drain's avatar
Drain committed
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
	</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">
84
		<!-- get scar file path -->
Tyrannas's avatar
Tyrannas committed
85
		<unzip src="${ScarPath}/${file}" dest="./${UnzipSourcePath}"/>
Drain's avatar
Drain committed
86
87
88
89
90
91
92
93
94
	</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" />
95
96
		<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
97
				<rootfiles>
98
					<rootfile full-path="${RacineFile}" media-type="text/xml" />
Drain's avatar
Drain committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
				</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 -->
114
115
		<xslt style="xsl/opale_to_hdoc_regle1.xsl" in="${xml.path}" out="./${TmpPath}/${TmpFile1}" classpath="./lib/saxon9he.jar">
			<factory name="net.sf.saxon.TransformerFactoryImpl"/>
Drain's avatar
Drain committed
116
117
118
119
		</xslt>
		
	</target>
	
120
121
122
123
124
125
126
127
128
	<!-- Copy ressources -->
	<target name="copy_ressources">	
		<xslt style="xsl/find_ressources.xsl" in="./${TmpPath}/${TmpFile1}" out="./get_ressources.ant" classpath="./lib/saxon9he.jar" >
			<factory name="net.sf.saxon.TransformerFactoryImpl"/>
		</xslt>
		<chmod file="get_ressources.ant" perm="777"/>
		<ant antfile="get_ressources.ant"/>
	</target>
	
Drain's avatar
Drain committed
129
130
	<!-- Create content.xml -->
	<target name="content_xml">	
131
132
133
		<xslt style="xsl/opale_to_hdoc_regle2.xsl" in="./${TmpPath}/${TmpFile1}" out="./${HdocPath}/${RacineFile}" classpath="./lib/saxon9he.jar">
			<factory name="net.sf.saxon.TransformerFactoryImpl"/>
		</xslt>
Drain's avatar
Drain committed
134
135
136
137
	</target>
	
	<!-- Zip Hdoc -->
	<target name="zip">
Tyrannas's avatar
Tyrannas committed
138
		<zip destfile="${OutputPath}/${file}.hdoc" basedir="${HdocPath}"/>
Drain's avatar
Drain committed
139
140
	</target>
</project>