myantce.ant 4.69 KB
Newer Older
1
2
3
4
5
6
7
8
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
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
115
116
117
118
119
120
121
122
123
124
125
126
127
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="hdoc_to_opale" basedir="." default="convert">
    <property name="in" location="${basedir}/input"/>
    <property name="out" location="${basedir}/output"/>
    <property name="tmp" location="${basedir}/tmp"/>
    <property name="xsl" location="${basedir}/xsl"/>
    <property name="lib" location="${basedir}/lib"/>
    <property name="log" location="${basedir}/log"/>
    <property name="schema" location="${basedir}/schema"/>
    <property name="bibtex" location="${basedir}/bibtex_to_opale"/>

    <property file="global.properties"/>

  	<taskdef name="jing" classname="com.thaiopensource.relaxng.util.JingTask">
  		<classpath>
  			<pathelement location="lib/jing.jar"/>
  		</classpath>
  	</taskdef>

  	<target name="convert">
  		<!-- This is the main target : it is called whether by the project (as the default target) or by the user/converter
  		website, if specified in the command line. Basically, this target consists in several targets/ant buildfiles calls. -->
  		<antcall target="CleanDirectory"/>

  		<antcall target="UnzipHdocFile"/>
  		<antcall target="ValidateInput" />

  		<antcall target="FindContentFiles"/>
  		<ant antfile="${tmp}/generateContentPath.xml"/>

  		<antcall target="ValidateOutput"/>
  		<antcall target="DivideOutput"/>

  		<antcall target="ZipOutput"/>
  		<antcall target="ZipDividedOutput"/>

  		<antcall target="CleanDirectory"/>
      </target>

  	<target name="CleanDirectory">
      <delete>
         <fileset dir="${tmp}">
            <include name="**/*"/>
         </fileset>
      </delete>
  	</target>

  	<target name="UnzipHdocFile">
  		<!-- Unzip the input hdoc file. Decompressed folder is named "decompressedHdoc" : this name is the only one which
  		refers to the hdoc file furthermore in this project. -->
      <unzip dest="${tmp}/decompressedHdoc">
          <fileset dir="${in}">
              <include name="**/*.hdoc"/>
          </fileset>
      </unzip>
  		<chmod dir="${tmp}/decompressedHdoc" perm="777"/>
  	</target>

  	<target name="FindContentFiles">
  		<!-- Finds the absolute path of container.xml and applies transformation0.xsl on it.-->
  		<first id="first">
  		    <fileset dir="${tmp}/decompressedHdoc/META-INF" includes="**/container.xml"/>
  		</first>
  		<xslt in="${toString:first}" out="${tmp}/generateContentPath.xml" style="${xsl}/transformation0.xsl" processor="org.apache.tools.ant.taskdefs.optional.TraXLiaison" />
  		<chmod file="${tmp}/generateContentPath.xml" perm="777"/>
  	</target>

  	<target name="ZipOutput">
  		<copy file="${bibtex}/.wspmeta" todir="${tmp}/decompressedOpale"/>
  		<mkdir dir="${tmp}/decompressedOpale/res"/>
  		<ant antfile="${tmp}/moveRessourceFiles.xml"/>
  		<zip basedir="${tmp}/decompressedOpale" destfile="${out}/output.scar" encoding="UTF-8"/>
  	</target>

  	<target name="ZipDividedOutput">
  		<copy file="${bibtex}/.wspmeta" todir="${tmp}/decompressedOpaleDivided"/>
  		<copy todir="${tmp}/decompressedOpaleDivided/res" >
  	        <fileset dir="${tmp}/decompressedOpale/res" includes="**"/>
  	 	</copy>
  		<copy todir="${tmp}/decompressedOpaleDivided/references" >
  	        <fileset dir="${tmp}/decompressedOpale/references" includes="**"/>
  	 	</copy>
  		<zip basedir="${tmp}/decompressedOpaleDivided" destfile="${out}/outdividedOutput.scar" encoding="UTF-8"/>
  	</target>

  	<!-- Validating the XML container file -->
  	<target name="ValidateInput">
  		<jing file="${tmp}/decompressedHdoc/META-INF/container.xml" rngfile="${schema}/hdoc1-container.rng"></jing>
  	</target>

  	<!-- Validating the XML output -->
  	<target name="ValidateOutput">
  		<jing file="${tmp}/decompressedOpale/main.xml" rngfile="${schema}/op_ue.rng"></jing>
  	</target>

  	<target name="DivideOutput">
  		<mkdir dir="${tmp}/decompressedOpaleDivided"/>

  		<!-- Adding IDS to the general output file -->
  		<xslt
  			in="${tmp}/decompressedOpale/main.xml"
  			out="${tmp}/outputWithCourseUcIds.xml"
  			style="${xsl}/addCourseUcIds.xsl"
  			processor="org.apache.tools.ant.taskdefs.optional.TraXLiaison"
  		/>

  		<!-- Generating the root file (with refs to other files) -->
  		<xslt
  			in="${tmp}/outputWithCourseUcIds.xml"
  			out="${tmp}/decompressedOpaleDivided/main.xml"
  			style="${xsl}/addCourseUcReferences.xsl"
  			processor="org.apache.tools.ant.taskdefs.optional.TraXLiaison"
  		/>

  		<!-- Generating the ANT file that will copy the files -->
  		<xslt
  			in="${tmp}/outputWithCourseUcIds.xml"
  			out="${tmp}/exportUnits.ant"
  			style="${xsl}/prepareCourseUcCopies.xsl"
  			processor="org.apache.tools.ant.taskdefs.optional.TraXLiaison"
  		/>

  		<!-- Executing that ANT file -->
  		<ant antfile="${tmp}/exportUnits.ant"/>
  	</target>

</project>