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 @@
<project basedir="." name="myantce" default="main">
<property file="etherpad_to_hdoc.properties"/>
<!-- import classes -->
<taskdef resource="net/sf/antcontrib/antlib.xml"></taskdef>
<taskdef name="htmlcleaner" classname="org.htmlcleaner.HtmlCleanerForAnt"></taskdef>
<taskdef name="jing" classname="com.thaiopensource.relaxng.util.JingTask"></taskdef>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<taskdef name="htmlcleaner" classname="org.htmlcleaner.HtmlCleanerForAnt"/>
<taskdef name="jing" classname="com.thaiopensource.relaxng.util.JingTask"/>
<target name="start">
<delete dir="${tmp}" failonerror="false"/>
......@@ -14,101 +14,105 @@
<delete dir="${log}" failonerror="false"/>
<mkdir dir="${log}"/>
</target>
<target name="clean-tmp">
<delete dir="${tmp}" failonerror="false"/>
<mkdir dir="${tmp}"/>
</target>
<!-- Apply Xslt -->
<target name="apply-xslt">
<for param="inputPad">
<path>
<fileset dir="${in}" includes="*.html" />
</path>
<sequential>
<local name="padFileName" />
<basename property="padFileName" file="@{inputPad}"/>
<local name="properName" />
<basename property="properName" file="@{inputPad}" suffix=".html"/>
<htmlcleaner src="${in}/${padFileName}" dest="${tmp}/pad-clean.xml"/>
<xslt in="${xsl}/html2xhtml.xsl" out="${tmp}/${properName}/tmpPad.xhtml" style="${xsl}/html2xhtml.xsl" />
<xslt in="${tmp}/${properName}/tmpPad.xhtml" out="${tmp}/${properName}/tmpPad2.xhtml" style="${xsl}/html2xhtmlv1.xsl" />
<xslt in="${tmp}/${properName}/tmpPad2.xhtml" out="${tmp}/${properName}/tmpPad3.xhtml" style="${xsl}/html2xhtmlv2.xsl" />
<xslt in="${tmp}/${properName}/tmpPad3.xhtml" out="${tmp}/${properName}/tmpPad4.xhtml" style="${xsl}/html2xhtml3.xsl" />
<xslt in="${tmp}/${properName}/tmpPad4.xhtml" out="${tmp}/${properName}/tozip/content.xml" style="${xsl}/xhtml2hdoc.xsl" />
</sequential>
</for>
<!-- clean html file (html -> xhtml) -->
<htmlcleaner src="${in}/${fileName}" dest="${tmp}/pad-clean.xml"/>
<!-- calls for pad-clean.xml internally -->
<xslt in="${xsl}/html2xhtml.xsl" out="${tmp}/${properName}/tmpPad.xhtml"
style="${xsl}/html2xhtml.xsl"/>
<delete file="${tmp}/pad-clean.xml"></delete>
<xslt in="${tmp}/${properName}/tmpPad.xhtml" out="${tmp}/${properName}/tmpPad2.xhtml"
style="${xsl}/html2xhtmlv1.xsl"/>
<xslt in="${tmp}/${properName}/tmpPad2.xhtml" out="${tmp}/${properName}/tmpPad3.xhtml"
style="${xsl}/html2xhtmlv2.xsl"/>
<xslt in="${tmp}/${properName}/tmpPad3.xhtml" out="${tmp}/${properName}/tmpPad4.xhtml"
style="${xsl}/html2xhtml3.xsl"/>
<xslt in="${tmp}/${properName}/tmpPad4.xhtml" out="${tmp}/${properName}/tozip/content.xml"
style="${xsl}/xhtml2hdoc.xsl"/>
</target>
<!-- Builds Hdoc structure -->
<target name="construct_hdoc">
<for param="inputPad">
<path>
<fileset dir="${in}" includes="*.html" />
</path>
<sequential>
<local name="properName" />
<basename property="properName" file="@{inputPad}" suffix=".html"/>
<mkdir dir="${tmp}/${properName}/tozip/" />
<mkdir dir="${tmp}/${properName}/META-INF/" />
<mkdir dir="${tmp}/${properName}/tozip/META-INF" />
<!-- container -->
<touch file="${tmp}/${properName}/META-INF/container.xml" />
<echoxml file="${tmp}/${properName}/META-INF/container.xml">
<container version="1.0">
<rootfiles>
<rootfile full-path="${rootfilename}" media-type="text/xml" />
</rootfiles>
</container>
</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>
<mkdir dir="${tmp}/${properName}/tozip/"/>
<mkdir dir="${tmp}/${properName}/META-INF/"/>
<mkdir dir="${tmp}/${properName}/tozip/META-INF"/>
<!-- container -->
<touch file="${tmp}/${properName}/META-INF/container.xml"/>
<echoxml file="${tmp}/${properName}/META-INF/container.xml">
<container version="1.0">
<rootfiles>
<rootfile full-path="${rootfilename}" media-type="text/xml"/>
</rootfiles>
</container>
</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"/>
</target>
<target name="jing-hdoc">
<for param="inputPad" keepgoing="true">
<path>
<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>
<jing file="${tmp}/${properName}/tozip/content.xml"
rngfile="${schema}/xhtml/hdoc1-xhtml.rng"/>
</target>
<!-- Zip Hdoc container -->
<target name="zip">
<zip basedir="${tmp}/${properName}/tozip/" destfile="${out}/${properName}.hdoc"/>
</target>
<target name="main">
<antcall target="start"/>
<for param="inputPad">
<path>
<fileset dir="${in}" includes="*.html" />
<fileset dir="${in}" includes="*.html"/>
</path>
<sequential>
<local name="properName" />
<basename property="properName" file="@{inputPad}" suffix=".html"/>
<zip basedir="${tmp}/${properName}/tozip/" destfile="${out}/${properName}.hdoc" />
<local name="padFileName"/>
<basename property="padFileName" file="@{inputPad}"/>
<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>
</for>
</target>
<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
</project>
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