hdoc_to_opale.ant 7.77 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
<?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"/>

14
    <taskdef resource="net/sf/antcontrib/antlib.xml"/>
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
  	<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"/>
30 31 32 33 34 35 36 37 38 39 40 41 42

      <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>
43 44 45 46 47 48 49 50 51 52 53 54

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

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

      </target>

  	<target name="CleanDirectory">
      <delete>
         <fileset dir="${tmp}">
55
           <include name="*"/>
56 57 58 59 60 61 62
         </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. -->
63 64 65 66 67 68 69 70 71 72 73
      <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>
74 75 76 77
  	</target>

  	<target name="FindContentFiles">
  		<!-- Finds the absolute path of container.xml and applies transformation0.xsl on it.-->
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
      <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>
94 95 96
  	</target>

  	<target name="ZipOutput">
97 98 99 100 101 102 103
      <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
104 105
          <propertyregex property="properFilename" input="${filename}" regexp=".hdoc" replace="" casesensitive="false" override="true" />

106 107 108
      		<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
109
      		<zip basedir="${tmp}/${filename}/decompressedOpale" destfile="${out}/${properFilename}/output.scar" encoding="UTF-8"/>
110 111 112
        </sequential>
      </for>
    </target>
113 114

  	<target name="ZipDividedOutput">
115 116 117 118 119 120 121
      <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
122 123 124
          <propertyregex property="properFilename" input="${filename}" regexp=".hdoc" replace="" casesensitive="false" override="true" />

          <copy file="${bibtex}/.wspmeta" todir="${tmp}/${filename}/decompressedOpaleDivided"/>
125 126 127 128 129 130
      		<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
131
      		<zip basedir="${tmp}/${filename}/decompressedOpaleDivided" destfile="${out}/${properFilename}/dividedOutput.scar" encoding="UTF-8"/>
132 133 134
        </sequential>
      </for>
    </target>
135 136 137

  	<!-- Validating the XML container file -->
  	<target name="ValidateInput">
138 139 140 141 142 143 144 145 146 147
      <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>
148 149 150 151
  	</target>

  	<!-- Validating the XML output -->
  	<target name="ValidateOutput">
152 153 154 155 156 157 158 159 160 161
      <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>
162 163 164
  	</target>

  	<target name="DivideOutput">
165 166 167 168 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
      <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>
204 205 206
  	</target>

</project>