hdoc_to_opale.ant 6.32 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
    <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">
18 19

      <delete dir="${tmp}" failonerror="false"/>
Decorde Jeffrey's avatar
Decorde Jeffrey committed
20
      <sleep seconds="1"/>
21 22
      <mkdir dir="${tmp}"/>
      <delete dir="${out}" failonerror="false"/>
Decorde Jeffrey's avatar
Decorde Jeffrey committed
23
      <sleep seconds="1"/>
24 25
      <mkdir dir="${out}"/>
  	  <delete dir="${log}" failonerror="false"/>
Decorde Jeffrey's avatar
Decorde Jeffrey committed
26
      <sleep seconds="1"/>
27
      <mkdir dir="${log}"/>
28

29 30 31 32 33 34 35
      <for param="inputFile">
        <path>
          <fileset dir="${in}" includes="**/*.hdoc"/>
        </path>
        <sequential>
          <local name="filename"/>
          <basename property="filename" file="@{inputFile}"/>
36

Decorde Jeffrey's avatar
Decorde Jeffrey committed
37 38 39
      		<antcall target="UnzipHdocFile">
            <param name="filename" value="${filename}"/>
          </antcall>
40

Decorde Jeffrey's avatar
Decorde Jeffrey committed
41 42 43
      		<antcall target="ValidateInput">
            <param name="filename" value="${filename}"/>
          </antcall>
44

Decorde Jeffrey's avatar
Decorde Jeffrey committed
45 46 47
      		<antcall target="FindContentFiles">
            <param name="filename" value="${filename}"/>
          </antcall>
48

Decorde Jeffrey's avatar
Decorde Jeffrey committed
49 50 51
    	    <ant antfile="${tmp}/${filename}/generateContentPath.xml">
            <property name="filename" value="${filename}"/>
          </ant>
52

Decorde Jeffrey's avatar
Decorde Jeffrey committed
53 54 55
      		<antcall target="ValidateOutput">
            <param name="filename" value="${filename}"/>
          </antcall>
56

Decorde Jeffrey's avatar
Decorde Jeffrey committed
57 58 59
          <antcall target="DivideOutput">
            <param name="filename" value="${filename}"/>
          </antcall>
60

Decorde Jeffrey's avatar
Decorde Jeffrey committed
61 62 63
		      <antcall target="ZipOutput">
            <param name="filename" value="${filename}"/>
          </antcall>
64

Decorde Jeffrey's avatar
Decorde Jeffrey committed
65 66 67
          <antcall target="ZipDividedOutput">
            <param name="filename" value="${filename}"/>
          </antcall>
68

69 70 71
        </sequential>
      </for>
    </target>
72

Decorde Jeffrey's avatar
Decorde Jeffrey committed
73 74 75 76 77
  	<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 src="${in}/${filename}" dest="${tmp}/${filename}/decompressedHdoc"/>
      <chmod dir="${tmp}/${filename}/decompressedHdoc" perm="777"/>
78 79
  	</target>

Decorde Jeffrey's avatar
Decorde Jeffrey committed
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
	<target name="FindContentFiles">
		<!-- Finds the absolute path of container.xml and applies transformation0.xsl on it.-->
    <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}"/>
      <param name="lib" expression="${lib}"/>
    </xslt>
		<chmod file="${tmp}/${filename}/generateContentPath.xml" perm="777"/>
	</target>

	<target name="ZipOutput">
    <propertyregex property="properFilename" input="${filename}" regexp=".hdoc" replace="" casesensitive="false" override="true" />
		<copy file="${bibtex}/.wspmeta" todir="${tmp}/${filename}/decompressedOpale"/>
		<mkdir dir="${tmp}/${filename}/decompressedOpale/res"/>
		<ant antfile="${tmp}/${filename}/moveRessourceFiles.xml"/>
		<zip basedir="${tmp}/${filename}/decompressedOpale" destfile="${out}/${properFilename}/output.scar" encoding="UTF-8"/>
  </target>

	<target name="ZipDividedOutput">
    <propertyregex property="properFilename" input="${filename}" regexp=".hdoc" replace="" casesensitive="false" override="true" />
    <copy file="${bibtex}/.wspmeta" todir="${tmp}/${filename}/decompressedOpaleDivided"/>
		<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>
		<zip basedir="${tmp}/${filename}/decompressedOpaleDivided" destfile="${out}/${properFilename}/dividedOutput.scar" encoding="UTF-8"/>
  </target>

	<!-- Validating the XML container file -->
	<target name="ValidateInput">
    <trycatch property="foo" reference="bar">
      <try>
        <jing file="${tmp}/${filename}/decompressedHdoc/META-INF/container.xml" rngfile="${schema}/hdoc1-container.rng"></jing>
      </try>
      <catch>
        <echo>Validation failed</echo>
      </catch>
    </trycatch>
	</target>

	<!-- Validating the XML output -->
	<target name="ValidateOutput">
    <trycatch property="foo" reference="bar">
      <try>
        <jing file="${tmp}/${filename}/decompressedOpale/main.xml" rngfile="${schema}/op_ue.rng"></jing>
      </try>
      <catch>
        <echo>Validation failed</echo>
      </catch>
    </trycatch>
	</target>

	<target name="DivideOutput">
    <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"/>
	</target>
168 169

</project>