hdoc_to_opale.ant 7.71 KB
Newer Older
1
2
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="hdoc_to_opale" basedir="." default="convert">
3
4
5
6

    <taskdef resource="net/sf/antcontrib/antlib.xml"/>
    <taskdef name="jing" classname="com.thaiopensource.relaxng.util.JingTask"/>

7
8
9
10
11
12
13
14
15
16
17
18
    <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"/>

  	<target name="convert">
19
20
21
22
23
24
25
26
27
28

      <delete dir="${tmp}" failonerror="false"/>
      <sleep seconds="2"/>
      <mkdir dir="${tmp}"/>
      <delete dir="${out}" failonerror="false"/>
      <sleep seconds="2"/>
      <mkdir dir="${out}"/>
  	  <delete dir="${log}" failonerror="false"/>
      <sleep seconds="2"/>
      <mkdir dir="${log}"/>
29
30
31
32
33

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

  		<antcall target="FindContentFiles"/>
Decorde Jeffrey's avatar
Decorde Jeffrey committed
34
35
36
37
38
39
40
41
42
43
44
45
46

      <for param="inputFile">
        <path>
          <fileset dir="${in}" includes="**/*.hdoc"/>
        </path>
        <sequential>
          <local name="filename"/>
          <basename property="filename" file="@{inputFile}"/>
  		    <ant antfile="${tmp}/${filename}/generateContentPath.xml">
            <property name="filename" value="${filename}"/>
          </ant>
        </sequential>
      </for>
47
48
49
50
51
52
53
54
55
56
57
58

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

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

      </target>

  	<target name="CleanDirectory">
      <delete>
         <fileset dir="${tmp}">
Decorde Jeffrey's avatar
Decorde Jeffrey committed
59
           <include name="*"/>
60
61
62
63
64
65
66
         </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. -->
Decorde Jeffrey's avatar
Decorde Jeffrey committed
67
68
69
70
71
72
73
74
75
76
77
      <for param="inputFile">
        <path>
          <fileset dir="${in}" includes="**/*.hdoc"/>
        </path>
        <sequential>
          <local name="filename"/>
          <basename property="filename" file="@{inputFile}"/>
          <unzip src="${in}/${filename}" dest="${tmp}/${filename}/decompressedHdoc"/>
          <chmod dir="${tmp}/${filename}/decompressedHdoc" perm="777"/>
        </sequential>
  		</for>
78
79
80
81
  	</target>

  	<target name="FindContentFiles">
  		<!-- Finds the absolute path of container.xml and applies transformation0.xsl on it.-->
Decorde Jeffrey's avatar
Decorde Jeffrey committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
      <for param="inputFile">
        <path>
          <fileset dir="${in}" includes="**/*.hdoc"/>
        </path>
        <sequential>
          <local name="filename"/>
          <basename property="filename" file="@{inputFile}"/>
          <first id="first">
      		    <fileset dir="${tmp}/${filename}/decompressedHdoc/META-INF" includes="**/container.xml"/>
      		</first>
      		<xslt in="${toString:first}" out="${tmp}/${filename}/generateContentPath.xml" style="${xsl}/transformation0.xsl" processor="org.apache.tools.ant.taskdefs.optional.TraXLiaison">
            <param name="filename" expression="${filename}"/>
          </xslt>
      		<chmod file="${tmp}/${filename}/generateContentPath.xml" perm="777"/>
        </sequential>
  		</for>
98
99
100
  	</target>

  	<target name="ZipOutput">
Decorde Jeffrey's avatar
Decorde Jeffrey committed
101
102
103
104
105
106
107
      <for param="inputFile">
        <path>
          <fileset dir="${in}" includes="**/*.hdoc"/>
        </path>
        <sequential>
          <local name="filename"/>
          <basename property="filename" file="@{inputFile}"/>
Decorde Jeffrey's avatar
Decorde Jeffrey committed
108
109
          <propertyregex property="properFilename" input="${filename}" regexp=".hdoc" replace="" casesensitive="false" override="true" />

Decorde Jeffrey's avatar
Decorde Jeffrey committed
110
111
112
      		<copy file="${bibtex}/.wspmeta" todir="${tmp}/${filename}/decompressedOpale"/>
      		<mkdir dir="${tmp}/${filename}/decompressedOpale/res"/>
      		<ant antfile="${tmp}/${filename}/moveRessourceFiles.xml"/>
Decorde Jeffrey's avatar
Decorde Jeffrey committed
113
      		<zip basedir="${tmp}/${filename}/decompressedOpale" destfile="${out}/${properFilename}/output.scar" encoding="UTF-8"/>
Decorde Jeffrey's avatar
Decorde Jeffrey committed
114
115
116
        </sequential>
      </for>
    </target>
117
118

  	<target name="ZipDividedOutput">
Decorde Jeffrey's avatar
Decorde Jeffrey committed
119
120
121
122
123
124
125
      <for param="inputFile">
        <path>
          <fileset dir="${in}" includes="**/*.hdoc"/>
        </path>
        <sequential>
          <local name="filename"/>
          <basename property="filename" file="@{inputFile}"/>
Decorde Jeffrey's avatar
Decorde Jeffrey committed
126
127
128
          <propertyregex property="properFilename" input="${filename}" regexp=".hdoc" replace="" casesensitive="false" override="true" />

          <copy file="${bibtex}/.wspmeta" todir="${tmp}/${filename}/decompressedOpaleDivided"/>
Decorde Jeffrey's avatar
Decorde Jeffrey committed
129
130
131
132
133
134
      		<copy todir="${tmp}/${filename}/decompressedOpaleDivided/res" >
      	        <fileset dir="${tmp}/${filename}/decompressedOpale/res" includes="**"/>
      	 	</copy>
      		<copy todir="${tmp}/${filename}/decompressedOpaleDivided/references" >
      	        <fileset dir="${tmp}/${filename}/decompressedOpale/references" includes="**"/>
      	 	</copy>
Decorde Jeffrey's avatar
Decorde Jeffrey committed
135
      		<zip basedir="${tmp}/${filename}/decompressedOpaleDivided" destfile="${out}/${properFilename}/dividedOutput.scar" encoding="UTF-8"/>
Decorde Jeffrey's avatar
Decorde Jeffrey committed
136
137
138
        </sequential>
      </for>
    </target>
139
140
141

  	<!-- Validating the XML container file -->
  	<target name="ValidateInput">
Decorde Jeffrey's avatar
Decorde Jeffrey committed
142
143
144
145
146
147
148
149
150
151
      <for param="inputFile">
        <path>
          <fileset dir="${in}" includes="**/*.hdoc"/>
        </path>
        <sequential>
          <local name="filename"/>
          <basename property="filename" file="@{inputFile}"/>
          <jing file="${tmp}/${filename}/decompressedHdoc/META-INF/container.xml" rngfile="${schema}/hdoc1-container.rng"></jing>
        </sequential>
  		</for>
152
153
154
155
  	</target>

  	<!-- Validating the XML output -->
  	<target name="ValidateOutput">
Decorde Jeffrey's avatar
Decorde Jeffrey committed
156
157
158
159
160
161
162
163
164
165
      <for param="inputFile">
        <path>
          <fileset dir="${in}" includes="**/*.hdoc"/>
        </path>
        <sequential>
          <local name="filename"/>
          <basename property="filename" file="@{inputFile}"/>
  		    <jing file="${tmp}/${filename}/decompressedOpale/main.xml" rngfile="${schema}/op_ue.rng"></jing>
        </sequential>
      </for>
166
167
168
  	</target>

  	<target name="DivideOutput">
Decorde Jeffrey's avatar
Decorde Jeffrey committed
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
      <for param="inputFile">
        <path>
          <fileset dir="${in}" includes="**/*.hdoc"/>
        </path>
        <sequential>
          <local name="filename"/>
          <basename property="filename" file="@{inputFile}"/>
  		    <mkdir dir="${tmp}/${filename}/decompressedOpaleDivided"/>

      		<!-- Adding IDS to the general output file -->
      		<xslt
            in="${tmp}/${filename}/decompressedOpale/main.xml"
            out="${tmp}/${filename}/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}/${filename}/outputWithCourseUcIds.xml"
            out="${tmp}/${filename}/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}/${filename}/outputWithCourseUcIds.xml"
            out="${tmp}/${filename}/exportUnits.ant"
            style="${xsl}/prepareCourseUcCopies.xsl"
            processor="org.apache.tools.ant.taskdefs.optional.TraXLiaison"
      		>
            <param name="filename" expression="${filename}"/>
          </xslt>

      		<!-- Executing that ANT file -->
      		<ant antfile="${tmp}/${filename}/exportUnits.ant"/>
        </sequential>
      </for>
208
209
210
  	</target>

</project>