Commit 796ebb40 authored by Jean Vintache's avatar Jean Vintache

pull master

parents 580791ac 42f770d3
Pour réaliser votre conversion vous devez ajouter un fichier .hdoc dans le dossier input. Veillez à n'en placer qu'un seul dedans. Ensuite il suffit d'appeler le script (.bat ou .sh).
\ No newline at end of file
Ce convertisseur permet de convertir des fichiers du format Hdoc (.hdoc) en contenus Optim de type papier (.paper) ou diaporama (.slideshow)
Il y a deux façons de réaliser votre conversion:
- Lancer le script run. Dans ce cas vous devez ajouter votre fichier .hdoc dans le dossier input. Veillez à ne placer qu'un seul fichier dans ce dossier. Le format par défaut utilisé pour le fichier cible est le type papier.
- En ligne de commande:
ant -buildfile hdoc_to_optim.ant
Vous pouvez spécifier le fichier input, avec le paramètre -DInputFile, et le format de sortie avec le paramètre -DDocType (paper ou slideshow). Les deux paramètres sont optionnels.
Exemple:
ant -buildfile hdoc_to_optim.ant -DDocType slideshow -DInputFile sample.hdoc
\ No newline at end of file
<project name="hdoc_to_optim" default="convert">
<taskdef resource="net/sf/antcontrib/antcontrib.properties">
<classpath>
<pathelement location="lib/ant-contrib.jar" />
</classpath>
</taskdef>
<!-- Arguments properties -->
<property name="DocType" value="paper" />
<property name="InputFile" value="none" />
<property name="InputPath" value="input" />
<property name="OutputPath" value="output" />
<property name="OutputScarPath" value="${OutputPath}/result.scar" />
<target name="convert">
<!--Check wether there is an input using command line or not-->
<if>
<equals arg1="${InputFile}" arg2="none" />
<then>
<!--There is no input, check the input folder-->
<echo message="The value of property InputFile is ${InputFile} ... Checking the input folder" />
<echo message="The value of property DocType is ${DocType}" />
<!-- get input hdoc file path -->
<fileset id="fileset_hdoc" dir="${InputPath}" casesensitive="yes">
<include name="*.hdoc"/>
</fileset>
<pathconvert property="HdocPath" pathsep="" refid="fileset_hdoc" />
<pathconvert property="HdocFile" pathsep="" refid="fileset_hdoc" />
<echo message="Executing conversion..." />
<!--unzips the hdoc to be converted-->
<unzip dest="hdoc" src ="${HdocPath}"/>
<unzip dest="hdoc" src ="${HdocFile}"/>
<!--gives all rights to avoid bugs-->
<chmod dir="hdoc" perm="777"/>
<!--launches the XSLT find_content to retrieve the content path-->
<xslt in="hdoc/META-INF/container.xml" out="get_content.ant" style="xsl/find_content.xsl"/>
<xslt in="hdoc/META-INF/container.xml" out="get_content.ant" style="xsl/find_content.xsl">
<param name="DocumentType" expression="${DocType}"/>
</xslt>
<chmod file="get_content.ant" perm="777"/>
<!--launches the ANT get_content resulting from the previous XSLT in order to launch the conversion-->
<ant antfile="get_content.ant"/>
<!--once the conversion is complete, the result is zipped-->
<zip basedir="result" destfile="${OutputScarPath}"/>
<zip basedir="result" destfile="${OutputScarPath}" encoding="UTF-8"/>
<!--temporary files and folders are deleted-->
<delete dir="hdoc"/>
......@@ -34,5 +53,39 @@
<delete file="get_content.ant"/>
<delete file="get_ressources.ant"/>
</then>
<else>
<!--There is an input-->
<echo message="The value of property InputFile is ${InputFile}" />
<echo message="The value of property DocType is ${DocType}" />
<echo message="Executing conversion..." />
<!--unzips the hdoc to be converted-->
<unzip dest="hdoc" src ="${InputFile}"/>
<!--gives all rights to avoid bugs-->
<chmod dir="hdoc" perm="777"/>
<!--launches the XSLT find_content to retrieve the content path-->
<xslt in="hdoc/META-INF/container.xml" out="get_content.ant" style="xsl/find_content.xsl">
<param name="DocumentType" expression="${DocType}"/>
</xslt>
<chmod file="get_content.ant" perm="777"/>
<!--launches the ANT get_content resulting from the previous XSLT in order to launch the conversion-->
<ant antfile="get_content.ant"/>
<!--once the conversion is complete, the result is zipped-->
<zip basedir="result" destfile="${OutputScarPath}" encoding="UTF-8"/>
<!--temporary files and folders are deleted-->
<delete dir="hdoc"/>
<delete dir="result"/>
<delete file="get_content.ant"/>
<delete file="get_ressources.ant"/>
</else>
</if>
</target>
</project>
\ No newline at end of file
......@@ -5,6 +5,7 @@
xmlns:h="urn:utc.fr:ics:hdoc:container"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!--<xsl:param name="destfile" required="yes" as="xs:string"/>-->
<xsl:param name="DocumentType" required="yes" as="xs:string"/>
<xsl:output method="xml" indent="yes"/>
<xsl:template match="h:container">
<project name="hdoc_to_optim" default="main">
......@@ -28,6 +29,20 @@
<chmod file="get_ressources.ant" perm="777"/>
<ant antfile="get_ressources.ant"/>
<!--the ANT runs the main XSLT transfo-->
<xslt in="hdoc/{$path}" out="result/content.paper" style="xsl/transfo.xsl"/>
<xsl:choose>
<xsl:when test="$DocumentType='paper'">
<xslt in="hdoc/{$path}" out="result/content.paper" style="xsl/transfo.xsl" classpath="lib/saxon9he.jar">
<factory name="net.sf.saxon.TransformerFactoryImpl"/>
</xslt>
</xsl:when>
<xsl:when test="$DocumentType='slideshow'">
<xslt in="hdoc/{$path}" out="result/content.slideshow" style="xsl/transfo2.xsl" classpath="lib/saxon9he.jar">
<factory name="net.sf.saxon.TransformerFactoryImpl"/>
</xslt>
</xsl:when>
<xsl:otherwise>
<xsl:message> Wrong document type </xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
......@@ -13,7 +13,7 @@
</of:paper>
</sc:item>
</xsl:template>
<xsl:strip-space elements="*"/>
<!--Metadata of the head tag-->
<xsl:template match="h:head">
<of:paperM>
......@@ -88,8 +88,23 @@
<!--hdoc sections can become chapters or sections in Optim, we must differentiate the two-->
<xsl:template match="h:body/h:section">
<sp:chap>
<xsl:call-template name="sec-body"/>
<xsl:variable name="chapi" select="(.//text())[1]"/>
<xsl:message><xsl:value-of select="$chapi"/></xsl:message>
<xsl:variable name="chap">
<xsl:choose>
<xsl:when test="contains($chapi,':')">
<xsl:message>Yescontiiii!</xsl:message>
<xsl:value-of select="normalize-space(replace($chapi,':','-'))"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="normalize-space($chapi)"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:message><xsl:value-of select="$chap"/></xsl:message>
<xsl:message>test</xsl:message>
<sp:chap sc:refUri="chapitres/{$chap}.section">
<xsl:call-template name="sec-body1">
<xsl:with-param name="chap" select = "$chap" />
</xsl:call-template>
</sp:chap>
</xsl:template>
......@@ -99,6 +114,33 @@
</sp:sec>
</xsl:template>
<xsl:template name="sec-body1">
<xsl:param name = "chap" />
<xsl:message><xsl:value-of select="$chap"/></xsl:message>
<xsl:result-document encoding="UTF-8" href="chapitres/{$chap}.section" >
<sc:item xmlns:sc="http://www.utc.fr/ics/scenari/v3/core">
<of:section>
<xsl:if test="@data-hdoc-type='introduction'">
<xsl:comment>Introduction</xsl:comment>
</xsl:if>
<xsl:if test="@data-hdoc-type='conclusion'">
<xsl:comment>Conclusion</xsl:comment>
</xsl:if>
<xsl:apply-templates select="h:header"/>
<xsl:if test="./h:div">
<sp:content>
<of:fragment>
<xsl:apply-templates select="h:div"/>
</of:fragment>
</sp:content>
</xsl:if>
<xsl:apply-templates select="h:section"/>
</of:section>
</sc:item>
</xsl:result-document>
<xsl:apply-templates select="h:footer"/>
</xsl:template>
<xsl:template name="sec-body">
<of:section>
<xsl:if test="@data-hdoc-type='introduction'">
......@@ -280,25 +322,25 @@
<!--Object-->
<xsl:template match="h:object">
<xsl:variable name="data" select="@data"/>
<sc:extBlock role="img" sc:refUri="{$data}"/>
<sc:extBlock role="img" sc:refUri="../{$data}"/>
</xsl:template>
<!--Image-->
<xsl:template match="h:img">
<xsl:variable name="src" select="@src"/>
<sc:extBlock role="img" sc:refUri="{$src}"/>
<sc:extBlock role="img" sc:refUri="../{$src}"/>
</xsl:template>
<!--Audio-->
<xsl:template match="h:audio">
<xsl:variable name="src" select="@src"/>
<sc:extBlock role="anim" sc:refUri="{$src}"/>
<sc:extBlock role="anim" sc:refUri="../{$src}"/>
</xsl:template>
<!--Video-->
<xsl:template match="h:video">
<xsl:variable name="src" select="@src"/>
<sc:extBlock role="anim" sc:refUri="{$src}"/>
<sc:extBlock role="anim" sc:refUri="../{$src}"/>
</xsl:template>
</xsl:stylesheet>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
xmlns:sc="http://www.utc.fr/ics/scenari/v3/core"
xmlns:of="scpf.org:office"
xmlns:sp="http://www.utc.fr/ics/scenari/v3/primitive"
xmlns:h="http://www.utc.fr/ics/hdoc/xhtml">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="h:html">
<sc:item xmlns:sc="http://www.utc.fr/ics/scenari/v3/core">
<of:slideshow xmlns:of="scpf.org:office" xmlns:sp="http://www.utc.fr/ics/scenari/v3/primitive" xmlns:sc="http://www.utc.fr/ics/scenari/v3/core">
<xsl:apply-templates/>
</of:slideshow>
</sc:item>
</xsl:template>
<xsl:strip-space elements="*"/>
<!--Metadata of the head tag-->
<xsl:template match="h:head">
<of:slideshowM>
<xsl:apply-templates select="h:title"/>
<sp:commonMeta>
<of:commonM>
<!--in optim there is only one tag for author and rights, we must concatenate them-->
<xsl:if test="h:meta[@name='author'] or h:meta[@name='rights']">
<sp:copyright>
<xsl:value-of select="h:meta[@name='author']/@content"/>
<xsl:if test="h:meta[@name='author'] and h:meta[@name='rights']"> - </xsl:if>
<xsl:value-of select="h:meta[@name='rights']/@content"/>
</sp:copyright>
</xsl:if>
<xsl:if test="h:meta[@name='date']">
<sp:version>
<xsl:value-of select="h:meta[@name='date']/@content"/>
</sp:version>
</xsl:if>
</of:commonM>
</sp:commonMeta>
</of:slideshowM>
<!--in optim there is no tag for description and keywords, they are added in a preliminary part-->
<!--<xsl:if test="h:meta[@name='description'] or h:meta[@name='keywords']">
<sp:pre>
<of:section>
<of:sectionM>
<sp:title>Metadata</sp:title>
</of:sectionM>
<sp:content>
<of:fragment>
<xsl:apply-templates select="h:meta[@name='description']"/>
<xsl:apply-templates select="h:meta[@name='keywords']"/>
</of:fragment>
</sp:content>
</of:section>
</sp:pre>
</xsl:if>-->
</xsl:template>
<!--<xsl:template match="h:meta[@name='description'] | h:meta[@name='keywords']">
<sp:info>
<of:block>
<of:blockM>
<sp:title>
<xsl:if test="@name='description'">Description</xsl:if>
<xsl:if test="@name='keywords'">Keywords</xsl:if>
</sp:title>
</of:blockM>
<sp:co>
<of:flow>
<sp:txt>
<of:txt>
<sc:para xml:space="preserve">
<xsl:value-of select="@content"/>
</sc:para>
</of:txt>
</sp:txt>
</of:flow>
</sp:co>
</of:block>
</sp:info>
</xsl:template>-->
<xsl:template match="h:title | h:h1 | h:h6">
<sp:title><xsl:value-of select="."/></sp:title>
</xsl:template>
<xsl:template match="h:body">
<xsl:apply-templates/>
</xsl:template>
<!--hdoc sections can become chapters or sections in Optim, we must differentiate the two-->
<xsl:template match="h:body/h:section">
<xsl:variable name="chapi" select="(.//text())[1]"/>
<xsl:message><xsl:value-of select="$chapi"/></xsl:message>
<xsl:variable name="chap">
<xsl:choose>
<xsl:when test="contains($chapi,':')">
<xsl:message>Yescontiiii!</xsl:message>
<xsl:value-of select="normalize-space(replace($chapi,':','-'))"/>
</xsl:when>
<xsl:otherwise><xsl:value-of select="normalize-space($chapi)"/></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:message><xsl:value-of select="$chap"/></xsl:message>
<xsl:message>test</xsl:message>
<sp:slide sc:refUri="slides/{$chap}.section">
<xsl:call-template name="sec-body1">
<xsl:with-param name="chap" select = "$chap" />
</xsl:call-template>
</sp:slide>
</xsl:template>
<xsl:template match="h:section">
<sp:sec>
<xsl:call-template name="sec-body"/>
</sp:sec>
</xsl:template>
<xsl:template name="sec-body1">
<xsl:param name = "chap" />
<xsl:message><xsl:value-of select="$chap"/></xsl:message>
<xsl:result-document encoding="UTF-8" href="slides/{$chap}.section" >
<sc:item xmlns:sc="http://www.utc.fr/ics/scenari/v3/core">
<of:section>
<xsl:if test="@data-hdoc-type='introduction'">
<xsl:comment>Introduction</xsl:comment>
</xsl:if>
<xsl:if test="@data-hdoc-type='conclusion'">
<xsl:comment>Conclusion</xsl:comment>
</xsl:if>
<xsl:apply-templates select="h:header"/>
<xsl:if test="./h:div">
<sp:content>
<of:fragment>
<xsl:apply-templates select="h:div"/>
</of:fragment>
</sp:content>
</xsl:if>
<xsl:apply-templates select="h:section"/>
</of:section>
</sc:item>
</xsl:result-document>
<xsl:apply-templates select="h:footer"/>
</xsl:template>
<xsl:template name="sec-body">
<of:section>
<xsl:if test="@data-hdoc-type='introduction'">
<xsl:comment>Introduction</xsl:comment>
</xsl:if>
<xsl:if test="@data-hdoc-type='conclusion'">
<xsl:comment>Conclusion</xsl:comment>
</xsl:if>
<xsl:apply-templates select="h:header"/>
<xsl:if test="./h:div">
<sp:content>
<of:fragment>
<xsl:apply-templates select="h:div"/>
</of:fragment>
</sp:content>
</xsl:if>
<xsl:apply-templates select="h:section"/>
</of:section>
<xsl:apply-templates select="h:footer"/>
</xsl:template>
<xsl:template match="h:header">
<of:sectionM>
<xsl:apply-templates/>
</of:sectionM>
</xsl:template>
<xsl:template match="h:footer">
<xsl:apply-templates/>
</xsl:template>
<!--there are no tags for metadata in Optim sections, so we add this information in the comments-->
<xsl:template match="h:div[@data-hdoc-type]">
<xsl:comment>
<xsl:if test="@data-hdoc-type='author'">Author : <xsl:value-of select="."/></xsl:if>
<xsl:if test="@data-hdoc-type='date'">Date : <xsl:value-of select="."/></xsl:if>
<xsl:if test="@data-hdoc-type='rights'">Rights : <xsl:value-of select="."/></xsl:if>
<xsl:if test="@data-hdoc-type='tags'">Tags : <xsl:for-each select="h:span"><xsl:value-of select="."/>, </xsl:for-each></xsl:if>
<xsl:if test="@data-hdoc-type='categories'">Categories : <xsl:for-each select="h:span"><xsl:value-of select="."/>, </xsl:for-each></xsl:if>
</xsl:comment>
</xsl:template>
<xsl:template match="h:div">
<sp:info>
<xsl:call-template name="div-body"/>
</sp:info>
</xsl:template>
<xsl:template match="h:div[@data-hdoc-type='emphasis'] | h:div[@data-hdoc-type='definition'] | h:div[@data-hdoc-type='warning']">
<sp:emphasis>
<xsl:if test="@data-hdoc-type='definition'">
<xsl:comment>Definition</xsl:comment>
</xsl:if>
<xsl:if test="@data-hdoc-type='warning'">
<xsl:comment>Warning</xsl:comment>
</xsl:if>
<xsl:if test="@data-hdoc-type='date'">Date : <xsl:value-of select="."/></xsl:if>
<xsl:call-template name="div-body"/>
</sp:emphasis>
</xsl:template>
<xsl:template match="h:div[@data-hdoc-type='complement'] | h:div[@data-hdoc-type='example'] | h:div[@data-hdoc-type='remark'] | h:div[@data-hdoc-type='advice']">
<sp:extra>
<xsl:if test="@data-hdoc-type='example'">
<xsl:comment>Example</xsl:comment>
</xsl:if>
<xsl:if test="@data-hdoc-type='remark'">
<xsl:comment>Remark</xsl:comment>
</xsl:if>
<xsl:if test="@data-hdoc-type='advice'">
<xsl:comment>Advice</xsl:comment>
</xsl:if>
<xsl:call-template name="div-body"/>
</sp:extra>
</xsl:template>
<xsl:template name="div-body">
<of:block>
<of:blockM>
<xsl:apply-templates select="h:h6"/>
</of:blockM>
<sp:co>
<of:flow>
<sp:txt>
<of:txt>
<xsl:apply-templates select="*[not(self::h:h6)]"/>
</of:txt>
</sp:txt>
</of:flow>
</sp:co>
</of:block>
</xsl:template>
<xsl:template match="h:span">
<xsl:apply-templates/>
</xsl:template>
<!--Text-->
<!--paragraph-->
<xsl:template match="h:p">
<sc:para xml:space="preserve">
<xsl:apply-templates/>
</sc:para>
</xsl:template>
<!--list-->
<xsl:template match="h:ul">
<sc:itemizedList>
<xsl:apply-templates/>
</sc:itemizedList>
</xsl:template>
<xsl:template match="h:ol">
<sc:orderedList>
<xsl:apply-templates/>
</sc:orderedList>
</xsl:template>
<xsl:template match="h:li">
<sc:listItem>
<xsl:apply-templates/>
</sc:listItem>
</xsl:template>
<!--url-->
<xsl:template match="h:a">
<sc:uLink role="url" url="{@href}">
<xsl:apply-templates/>
</sc:uLink>
</xsl:template>
<xsl:template match="h:em">
<sc:inlineStyle role="emphasis">
<xsl:apply-templates/>
</sc:inlineStyle>
</xsl:template>
<xsl:template match="h:i">
<sc:phrase role="special">
<xsl:apply-templates/>
</sc:phrase>
</xsl:template>
<xsl:template match="h:q">
<sc:phrase role="quote">
<xsl:apply-templates/>
</sc:phrase>
</xsl:template>
<!--Table-->
<xsl:template match="h:table">
<sc:table role="">
<xsl:apply-templates select="h:caption"/>
<xsl:for-each select="h:tr[1]/h:td">
<sc:column width="20"/>
</xsl:for-each>
<xsl:apply-templates select="h:tr"/>
</sc:table>
</xsl:template>
<xsl:template match="h:caption">
<sc:caption xml:space="preserve">
<xsl:value-of select="."/>
</sc:caption>
</xsl:template>
<xsl:template match="h:tr">
<sc:row>
<xsl:apply-templates/>
</sc:row>
</xsl:template>
<xsl:template match="h:td">
<sc:cell>
<xsl:apply-templates/>
</sc:cell>
</xsl:template>
<!--Object-->
<xsl:template match="h:object">
<xsl:variable name="data" select="@data"/>
<sc:extBlock role="img" sc:refUri="../{$data}"/>
</xsl:template>
<!--Image-->
<xsl:template match="h:img">
<xsl:variable name="src" select="@src"/>
<sc:extBlock role="img" sc:refUri="../{$src}"/>
</xsl:template>
<!--Audio-->
<xsl:template match="h:audio">
<xsl:variable name="src" select="@src"/>
<sc:extBlock role="anim" sc:refUri="../{$src}"/>
</xsl:template>
<!--Video-->
<xsl:template match="h:video">
<xsl:variable name="src" select="@src"/>
<sc:extBlock role="anim" sc:refUri="../{$src}"/>
</xsl:template>
</xsl:stylesheet>
\ 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