Commit 9a148cb4 authored by Antoine's avatar Antoine

Merge branch 'master' of https://gitlab.utc.fr/crozatst/hdoc

parents a9ca354d 89f9f767
*/input/
*/tmp/
*/output/
wikipedia_to_hdoc/result/*
wikipedia_to_hdoc/tmp/*
wikipedia_to_hdoc/hdoc_to_opale/tmp/*
wikipedia_to_hdoc/output/*
mindmapping_to_opale/result/*
mindmapping_to_opale/tmp/*
mindmapping_to_lexique/result/*
mindmapping_to_lexique/tmp/*
mindmapping_to_optim/result/*
mindmapping_to_optim/tmp/*
mindmapping_to_hdoc/result/*
mindmapping_to_hdoc/tmp/*
\ No newline at end of file
*/input/*
*/tmp/*
*/output/*
!*/input/sample.*
\ No newline at end of file
Usage
-----
Put the `.hdoc` files in the input folder, run `run.bat` or `run.sh` according to your operating system and get the .scar in the output folder.
Now, the script is able to manage several files.
Todo list
---------
- Refactor the ant script
- Resolve bugs
- (Optional) Port to XSLT 2.0
Bugs
----
- Table cell size
This diff is collapsed.
<?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"/>
<taskdef resource="net/sf/antcontrib/antlib.xml"/>
<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"/>
<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>
<antcall target="ValidateOutput"/>
<antcall target="DivideOutput"/>
<antcall target="ZipOutput"/>
<antcall target="ZipDividedOutput"/>
</target>
<target name="CleanDirectory">
<delete>
<fileset dir="${tmp}">
<include name="*"/>
</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. -->
<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>
</target>
<target name="FindContentFiles">
<!-- Finds the absolute path of container.xml and applies transformation0.xsl on it.-->
<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>
</target>
<target name="ZipOutput">
<for param="inputFile">
<path>
<fileset dir="${in}" includes="**/*.hdoc"/>
</path>
<sequential>
<local name="filename"/>
<basename property="filename" file="@{inputFile}"/>
<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"/>
</sequential>
</for>
</target>
<target name="ZipDividedOutput">
<for param="inputFile">
<path>
<fileset dir="${in}" includes="**/*.hdoc"/>
</path>
<sequential>
<local name="filename"/>
<basename property="filename" file="@{inputFile}"/>
<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"/>
</sequential>
</for>
</target>
<!-- Validating the XML container file -->
<target name="ValidateInput">
<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>
</target>
<!-- Validating the XML output -->
<target name="ValidateOutput">
<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>
</target>
<target name="DivideOutput">
<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>
</target>
</project>
@echo off
set lib=lib
set ant=myantce.ant
set ant=hdoc_to_opale.ant
set antparam=-Dprogram.param=%1
set scJarList=%lib%\*
......
#!/bin/sh
lib="lib"
ant="myantce.ant"
ant="hdoc_to_opale.ant"
antparam="-Dprogram.param=$1"
#Recherche de java et controle que se soit une version SUN
......
......@@ -27,7 +27,7 @@
<!-- Header in hdoc -->
<xsl:template match="node[1]" mode="header">
<title>
<xsl:value-of select="utc:string-remove-order(@TEXT)"/>
<xsl:value-of select="utc:remove-language(@TEXT)"/>
<xsl:value-of select="richcontent"/>
</title>
<meta charset="utf-8"/>
......@@ -39,7 +39,7 @@
<xsl:element name="section">
<header>
<h1>
<xsl:value-of select="utc:string-remove-order(@TEXT)"/>
<xsl:value-of select="utc:remove-language(@TEXT)"/>
<xsl:value-of select="richcontent"/>
</h1>
</header>
......@@ -49,7 +49,7 @@
<header><h1>Introduction</h1>
<xsl:element name="div">
<xsl:attribute name="data-hdoc-type">introduction</xsl:attribute>
<xsl:value-of select="utc:string-remove-order(utc:string-remove-all(child::*[contains(@TEXT, '#intro')][1]/@TEXT, '#intro '))"/>
<xsl:value-of select="utc:remove-language(child::*[contains(@TEXT, '#intro')][1]/@TEXT)"/>
</xsl:element>
</header>
</xsl:element>
......@@ -63,7 +63,7 @@
<footer>
<xsl:element name="div">
<xsl:attribute name="data-hdoc-type">conclusion</xsl:attribute>
<xsl:value-of select="utc:string-remove-order(utc:string-remove-all(child::*[contains(@TEXT, '#conclu')][1]/@TEXT, '#conclu '))"/>
<xsl:value-of select="utc:remove-language(child::*[contains(@TEXT, '#conclu')][1]/@TEXT)"/>
</xsl:element>
</footer>
</xsl:element>
......@@ -84,7 +84,7 @@
</xsl:if>
<header>
<h1>
<xsl:value-of select="utc:string-remove-order(@TEXT)"/>
<xsl:value-of select="utc:remove-language(@TEXT)"/>
<xsl:value-of select="richcontent"/>
</h1>
</header>
......@@ -95,7 +95,7 @@
<!-- Paragraph -->
<xsl:template match="node[contains(@TEXT, '#p')]" priority="2">
<xsl:element name="p">
<xsl:value-of select="utc:string-remove-order(utc:string-remove-all(@TEXT, '#p '))"/>
<xsl:value-of select="utc:remove-language(@TEXT)"/>
</xsl:element>
</xsl:template>
......@@ -104,9 +104,9 @@
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:text>#</xsl:text>
<xsl:value-of select="utc:string-remove-order(utc:string-remove-all(@TEXT, '#a '))"/>
<xsl:value-of select="utc:remove-language(@TEXT)"/>
</xsl:attribute>
<xsl:value-of select="utc:string-remove-order(utc:string-remove-all(@TEXT, '#a '))"/>
<xsl:value-of select="utc:remove-language(@TEXT)"/>
</xsl:element>
</xsl:template>
......@@ -114,43 +114,14 @@
<xsl:template match="node[contains(@TEXT, '#intro')] | node[contains(@TEXT, '#conclu')]" priority="3"/>
<xsl:template match="richcontent">
<xsl:value-of select="utc:string-remove-order(html/body/p)"/>
<xsl:value-of select="utc:remove-language(html/body/p)"/>
</xsl:template>
<!-- Utility functions -->
<xsl:function name="utc:string-remove-all" as="xs:string">
<xsl:param name="text" as="xs:string"/>
<xsl:param name="replace" as="xs:string"/>
<xsl:variable name="ret">
<xsl:call-template name="string-remove-all">
<xsl:with-param name="text" select="$text"/>
<xsl:with-param name="replace" select="$replace"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$ret"/>
</xsl:function>
<xsl:template name="string-remove-all">
<xsl:param name="text" as="xs:string"/>
<xsl:param name="replace" as="xs:string"/>
<xsl:choose>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:call-template name="string-remove-all">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:function name="utc:string-remove-order" as="xs:string">
<xsl:function name="utc:remove-language" as="xs:string">
<xsl:param name="text" as="xs:string?" />
<xsl:variable name="text2" select="string($text)"/>
<xsl:value-of select="replace($text2,'#[1-9][0-9]* ','')"></xsl:value-of>
<xsl:value-of select="replace($text2,'(#[0-9a-z]* )+','')"></xsl:value-of>
</xsl:function>
</xsl:stylesheet>
......@@ -82,7 +82,7 @@
<target name="opale_conversion.windows">
<echo>This is a Windows machine.</echo>
<copy file="${resultFile}/hdoc/${hdocName}.hdoc" todir="${basedir}/../hdoc_to_opale/input"/>
<exec dir="." executable="cmd">
<exec dir="${basedir}/../hdoc_to_opale" executable="cmd">
<arg value="${basedir}/../hdoc_to_opale/run.bat"/>
</exec>
<!-- <copy file="${basedir}/../hdoc_to_opale/output/output.scar" todir="${resultFile}/scar/${hdocName}.scar"/>-->
......@@ -91,7 +91,7 @@
<target name="opale_conversion.unix">
<echo>This is an Unix machine.</echo>
<copy file="${resultFile}/hdoc/${hdocName}.hdoc" todir="${basedir}/../hdoc_to_opale/input"/>
<exec dir="." executable="/bin/sh">
<exec dir="${basedir}/../hdoc_to_opale" executable="/bin/sh">
<arg value="${basedir}/../hdoc_to_opale/run.sh"/>
</exec>
<!-- <copy file="${basedir}/../hdoc_to_opale/output/output.scar" todir="${resultFile}/scar/${hdocName}.scar"/>-->
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?><map version="0.8.1"><node CREATED="1450312359766" ID="2nngtspni6hi1484pfec44c8lk" MODIFIED="1450312359766" TEXT="MindMapping"><node CREATED="1450312359766" ID="00lp6bpfm6jibhcjrpdonrhoqb" MODIFIED="1450312359766" POSITION="right" TEXT="#1 MindMapping to Hdoc"><node CREATED="1450312359766" ID="3qm1jgu7dfgs328jthlek5fd4e" MODIFIED="1450312359766" TEXT="Prendre en main le projet existant"/><node CREATED="1450312359766" ID="0u38ectmhqqp4p08p5guvgij71" MODIFIED="1450312359766" TEXT="Corriger les bugs existants"/><node CREATED="1450312359766" ID="3b1t9o2te6enh59j4iv48f4mdi" MODIFIED="1450312359766" TEXT="Restructurer le ant"/></node><node CREATED="1450312359766" ID="6lohsep5crh5g3ngj8ld8loei6" MODIFIED="1450312359766" POSITION="right" TEXT="#2 MindMapping to Opale"><node CREATED="1450312359766" ID="5pl3210hq6if3nv7r2chtjstmo" MODIFIED="1450312359766" TEXT="Faire la connexion avec le transformateur Hdoc to Opale"/><node CREATED="1450312359766" ID="3haa2fgohe9j4n04ilddco84uh" MODIFIED="1450312359766" TEXT="Permettre la personnalisation de l'organisation du module"/><node CREATED="1450312359766" ID="11k2hbkcu415e1mgk5c5ucr48k" MODIFIED="1450312359766" TEXT="Permettre la personnalisation dy type de noeud (Intro, conclusion etc.)"/><node CREATED="1450312359766" ID="4npf8jpvak3lffn9c1rsogi0sq" MODIFIED="1450312359766" TEXT="Permettre la personnalisation grâce aux couleurs/icônes"/></node><node CREATED="1450312359766" ID="3n8v43p8qb005puq3qiv7aiubc" MODIFIED="1450312359766" POSITION="right" TEXT="#3 MindMapping to Optim"><node CREATED="1450312359766" ID="2bn1la3apnjf1fi8qqfqde226t" MODIFIED="1450312359766" TEXT="Faire la connexion avec le transformateur Hdoc to Optim"/></node><node CREATED="1450312359766" ID="3s00si3hquol4pldg7lo9opjd6" MODIFIED="1450312359766" POSITION="right" TEXT="#4 MindMapping to Lexique"><node CREATED="1450312359766" ID="37jlfl25iuaoe6f2cpiv30qksd" MODIFIED="1450312359766" TEXT="Faire la connexion avec le transformateur Hdoc to Lexique"/></node><node CREATED="1450312359767" ID="27gnl6pgottjfiukpa3ulfdjrj" MODIFIED="1450312359767" POSITION="left" TEXT="#5 Prendre d'autres outils de carte mentales en entrée"/><node CREATED="1450312359767" ID="24d41nnnnvvu7fv5m8m4vegu0g" MODIFIED="1450312359767" POSITION="left" TEXT="#intro This converter aims at convert a given MindMapping file into a Hdoc file which then will be imported in Opale (advanced only)."/><node CREATED="1450312359767" ID="6a7pr2b5vvmq6na5964dhf9e13" MODIFIED="1450312359767" POSITION="left" TEXT="#conclu Ma conclusion"/></node></map>
\ No newline at end of file
......@@ -49,6 +49,8 @@
<echo message="Convert to hdoc..."/>
<xslt basedir="${tmp}/internationalisation" destdir="${out}" style="${xsl}/optim_to_hdoc.xsl"/>
<echo message="Copy ressources files..."/>
......@@ -63,6 +65,20 @@
</fileset>
</copy>
<!--<for param="folder">
<path>
<dirset dir="${out}" includes="*"/>
</path>
<sequential>
<local name="folder_name"/>
<basename property="folder_name" file="@{folder}"/>
<copy todir="@{folder}">
<fileset dir="${tmp}/extract">
</fileset>
</copy>
</sequential>
</for>-->
<echo message="Zip result..."/>
<for param="folder">
......
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