Commit 8d2b49a3 authored by Jean Vintache's avatar Jean Vintache

factor for-loop (see main target) and handle jing errors

parent 76315f26
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
<project basedir="." name="myantce" default="main"> <project basedir="." name="myantce" default="main">
<property file="etherpad_to_hdoc.properties"/> <property file="etherpad_to_hdoc.properties"/>
<!-- import classes --> <!-- import classes -->
<taskdef resource="net/sf/antcontrib/antlib.xml"></taskdef> <taskdef resource="net/sf/antcontrib/antlib.xml"/>
<taskdef name="htmlcleaner" classname="org.htmlcleaner.HtmlCleanerForAnt"></taskdef> <taskdef name="htmlcleaner" classname="org.htmlcleaner.HtmlCleanerForAnt"/>
<taskdef name="jing" classname="com.thaiopensource.relaxng.util.JingTask"></taskdef> <taskdef name="jing" classname="com.thaiopensource.relaxng.util.JingTask"/>
<target name="start"> <target name="start">
<delete dir="${tmp}" failonerror="false"/> <delete dir="${tmp}" failonerror="false"/>
...@@ -14,101 +14,105 @@ ...@@ -14,101 +14,105 @@
<delete dir="${log}" failonerror="false"/> <delete dir="${log}" failonerror="false"/>
<mkdir dir="${log}"/> <mkdir dir="${log}"/>
</target> </target>
<target name="clean-tmp">
<delete dir="${tmp}" failonerror="false"/>
<mkdir dir="${tmp}"/>
</target>
<!-- Apply Xslt --> <!-- Apply Xslt -->
<target name="apply-xslt"> <target name="apply-xslt">
<for param="inputPad"> <!-- clean html file (html -> xhtml) -->
<path> <htmlcleaner src="${in}/${fileName}" dest="${tmp}/pad-clean.xml"/>
<fileset dir="${in}" includes="*.html" /> <!-- calls for pad-clean.xml internally -->
</path> <xslt in="${xsl}/html2xhtml.xsl" out="${tmp}/${properName}/tmpPad.xhtml"
<sequential> style="${xsl}/html2xhtml.xsl"/>
<local name="padFileName" /> <delete file="${tmp}/pad-clean.xml"></delete>
<basename property="padFileName" file="@{inputPad}"/>
<local name="properName" /> <xslt in="${tmp}/${properName}/tmpPad.xhtml" out="${tmp}/${properName}/tmpPad2.xhtml"
<basename property="properName" file="@{inputPad}" suffix=".html"/> style="${xsl}/html2xhtmlv1.xsl"/>
<xslt in="${tmp}/${properName}/tmpPad2.xhtml" out="${tmp}/${properName}/tmpPad3.xhtml"
<htmlcleaner src="${in}/${padFileName}" dest="${tmp}/pad-clean.xml"/> style="${xsl}/html2xhtmlv2.xsl"/>
<xslt in="${xsl}/html2xhtml.xsl" out="${tmp}/${properName}/tmpPad.xhtml" style="${xsl}/html2xhtml.xsl" /> <xslt in="${tmp}/${properName}/tmpPad3.xhtml" out="${tmp}/${properName}/tmpPad4.xhtml"
<xslt in="${tmp}/${properName}/tmpPad.xhtml" out="${tmp}/${properName}/tmpPad2.xhtml" style="${xsl}/html2xhtmlv1.xsl" /> style="${xsl}/html2xhtml3.xsl"/>
<xslt in="${tmp}/${properName}/tmpPad2.xhtml" out="${tmp}/${properName}/tmpPad3.xhtml" style="${xsl}/html2xhtmlv2.xsl" /> <xslt in="${tmp}/${properName}/tmpPad4.xhtml" out="${tmp}/${properName}/tozip/content.xml"
<xslt in="${tmp}/${properName}/tmpPad3.xhtml" out="${tmp}/${properName}/tmpPad4.xhtml" style="${xsl}/html2xhtml3.xsl" /> style="${xsl}/xhtml2hdoc.xsl"/>
<xslt in="${tmp}/${properName}/tmpPad4.xhtml" out="${tmp}/${properName}/tozip/content.xml" style="${xsl}/xhtml2hdoc.xsl" />
</sequential>
</for>
</target> </target>
<!-- Builds Hdoc structure --> <!-- Builds Hdoc structure -->
<target name="construct_hdoc"> <target name="construct_hdoc">
<for param="inputPad"> <mkdir dir="${tmp}/${properName}/tozip/"/>
<path> <mkdir dir="${tmp}/${properName}/META-INF/"/>
<fileset dir="${in}" includes="*.html" /> <mkdir dir="${tmp}/${properName}/tozip/META-INF"/>
</path>
<sequential> <!-- container -->
<local name="properName" /> <touch file="${tmp}/${properName}/META-INF/container.xml"/>
<basename property="properName" file="@{inputPad}" suffix=".html"/> <echoxml file="${tmp}/${properName}/META-INF/container.xml">
<container version="1.0">
<mkdir dir="${tmp}/${properName}/tozip/" /> <rootfiles>
<mkdir dir="${tmp}/${properName}/META-INF/" /> <rootfile full-path="${rootfilename}" media-type="text/xml"/>
<mkdir dir="${tmp}/${properName}/tozip/META-INF" /> </rootfiles>
</container>
<!-- container --> </echoxml>
<touch file="${tmp}/${properName}/META-INF/container.xml" /> <xslt in="${tmp}/${properName}/META-INF/container.xml"
<echoxml file="${tmp}/${properName}/META-INF/container.xml"> out="${tmp}/${properName}/tozip/META-INF/container.xml"
<container version="1.0"> style="${xsl}/addNamespaceToContainer.xsl"/>
<rootfiles>
<rootfile full-path="${rootfilename}" media-type="text/xml" /> <!-- mimetype -->
</rootfiles> <touch file="${tmp}/${properName}/mimetype"/>
</container> <echo message="application/x-hdoc+zip" file="${tmp}/${properName}/tozip/mimetype"/>
</echoxml>
<xslt in="${tmp}/${properName}/META-INF/container.xml" out="${tmp}/${properName}/tozip/META-INF/container.xml" style="${xsl}/addNamespaceToContainer.xsl"/>
<!-- mimetype -->
<touch file="${tmp}/${properName}/mimetype" />
<echo message="application/x-hdoc+zip" file="${tmp}/${properName}/tozip/mimetype" />
</sequential>
</for>
</target> </target>
<target name="jing-hdoc"> <target name="jing-hdoc">
<for param="inputPad" keepgoing="true"> <jing file="${tmp}/${properName}/tozip/content.xml"
<path> rngfile="${schema}/xhtml/hdoc1-xhtml.rng"/>
<fileset dir="${in}" includes="*.html" />
</path>
<sequential>
<local name="properName" />
<basename property="properName" file="@{inputPad}" suffix=".html"/>
<jing file="${tmp}/${properName}/tozip/content.xml" rngfile="${schema}/xhtml/hdoc1-xhtml.rng" />
</sequential>
</for>
</target> </target>
<!-- Zip Hdoc container --> <!-- Zip Hdoc container -->
<target name="zip"> <target name="zip">
<zip basedir="${tmp}/${properName}/tozip/" destfile="${out}/${properName}.hdoc"/>
</target>
<target name="main">
<antcall target="start"/>
<for param="inputPad"> <for param="inputPad">
<path> <path>
<fileset dir="${in}" includes="*.html" /> <fileset dir="${in}" includes="*.html"/>
</path> </path>
<sequential> <sequential>
<local name="properName" /> <local name="padFileName"/>
<basename property="properName" file="@{inputPad}" suffix=".html"/> <basename property="padFileName" file="@{inputPad}"/>
<zip basedir="${tmp}/${properName}/tozip/" destfile="${out}/${properName}.hdoc" /> <local name="properFileName"/>
<basename property="properFileName" file="@{inputPad}" suffix=".html"/>
<echo>============ Processing pad : ${properFileName} ============</echo>
<antcall target="apply-xslt">
<param name="fileName" value="${padFileName}"/>
<param name="properName" value="${properFileName}"/>
</antcall>
<antcall target="construct_hdoc">
<param name="properName" value="${properFileName}"/>
</antcall>
<trycatch>
<try>
<!-- schema verification -->
<antcall target="jing-hdoc">
<param name="properName" value="${properFileName}"/>
</antcall>
<!-- zip hdoc if the schema is verified -->
<antcall target="zip">
<param name="properName" value="${properFileName}"/>
</antcall>
<!-- delete tmp files if everything went fine -->
<delete dir="${tmp}/${properFileName}" failonerror="false"/>
</try>
<catch>
<echo>WARNING</echo>
<echo>${properFileName} : the outptut doesn't match the hdoc schema</echo>
<echo>see the Jing log above and the tmp files</echo>
</catch>
</trycatch>
</sequential> </sequential>
</for> </for>
</target> </target>
</project>
<target name="main">
<antcall target="start" />
<antcall target="apply-xslt" />
<antcall target="construct_hdoc" />
<antcall target="jing-hdoc" />
<antcall target="zip" />
<antcall target="clean-tmp" />
</target>
</project>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment