Commit 21084fe0 authored by Bastien FREMONDIERE's avatar Bastien FREMONDIERE
Browse files

Merge branch 'master' into mindmapping

parents eb287fa3 2c09fc3a
<?xml version="1.0" encoding="UTF-8"?>
<sc:item xmlns:sc="http://www.utc.fr/ics/scenari/v3/core">
<of:gallery xmlns:of="scpf.org:office"
xmlns:sp="http://www.utc.fr/ics/scenari/v3/primitive">
<of:galleryM>
<sp:title>Hdoc Converter Portal (v0.2) Demo</sp:title>
</of:galleryM>
<sp:img xmlns="http://www.utc.fr/ics/hdoc/xhtml"
role="ref"
sc:refUri="/home/ivan/Downloads/projets/hdoc/optim_to_hdoc/re/screen1.png"/>
<sp:img xmlns="http://www.utc.fr/ics/hdoc/xhtml"
role="ref"
sc:refUri="/home/ivan/Downloads/projets/hdoc/optim_to_hdoc/re/screen2.png"/>
</of:gallery>
</sc:item>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
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"
xmlns="http://www.utc.fr/ics/hdoc/xhtml">
<xsl:output method="xml" indent="yes"/>
<xsl:param name="currentDir"/>
<!-- Identity transformation -->
<xsl:template match="node()|@*">
<xsl:param name="src" />
<xsl:copy>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="src" select="$src"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:variable name="src"><xsl:value-of select="$currentDir"/>/</xsl:variable>
<xsl:copy>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="src" select="$src"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="sp:main[@sc:refUri]" priority="1">
<xsl:param name="src" />
<sp:main>
<xsl:variable name="refUri" select="@sc:refUri" />
<xsl:variable name="refDoc" select="document($refUri)" />
<xsl:variable name="refUriWithoutLastPart">
<xsl:call-template name="removeLastPart">
<xsl:with-param name="value" select="$refUri" />
<xsl:with-param name="everything" select="$refUri" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="totalUri">
<xsl:value-of select="concat($src, $refUriWithoutLastPart)" />
</xsl:variable>
<xsl:apply-templates select="$refDoc/sc:item/of:section" >
<xsl:with-param name="src" select="$totalUri"/>
</xsl:apply-templates>
</sp:main>
</xsl:template>
<xsl:template match="sp:sec[@sc:refUri]" priority="1">
<xsl:param name="src" />
<xsl:variable name="refUri" select="@sc:refUri" />
<xsl:variable name="refDoc" select="document($refUri)" />
<xsl:variable name="refUriWithoutLastPart">
<xsl:call-template name="removeLastPart">
<xsl:with-param name="value" select="$refUri" />
<xsl:with-param name="everything" select="$refUri" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="totalUri">
<xsl:value-of select="concat($src, $refUriWithoutLastPart)" />
</xsl:variable>
<xsl:apply-templates select="$refDoc/sc:item/of:section" >
<xsl:with-param name="src" select="$totalUri"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="sp:subPage[@sc:refUri]" priority="1">
<xsl:param name="src" />
<xsl:variable name="refUri" select="@sc:refUri" />
<xsl:variable name="refDoc" select="document($refUri)" />
<xsl:variable name="refUriWithoutLastPart">
<xsl:call-template name="removeLastPart">
<xsl:with-param name="value" select="$refUri" />
<xsl:with-param name="everything" select="$refUri" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="totalUri">
<xsl:value-of select="concat($src, $refUriWithoutLastPart)" />
</xsl:variable>
<xsl:apply-templates select="$refDoc/sc:item/of:page | $refDoc/sc:item/of:section | $refDoc/sc:item/of:folder" >
<xsl:with-param name="src" select="$totalUri"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="sp:page[@sc:refUri]" priority="1">
<xsl:param name="src" />
<xsl:variable name="refUri" select="@sc:refUri" />
<xsl:variable name="refDoc" select="document($refUri)" />
<xsl:variable name="refUriWithoutLastPart">
<xsl:call-template name="removeLastPart">
<xsl:with-param name="value" select="$refUri" />
<xsl:with-param name="everything" select="$refUri" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="totalUri">
<xsl:value-of select="concat($src, $refUriWithoutLastPart)" />
</xsl:variable>
<xsl:comment>Page in dir : <xsl:value-of select="$totalUri"/></xsl:comment>
<xsl:apply-templates select="$refDoc/sc:item/of:page | $refDoc/sc:item/of:section | $refDoc/sc:item/of:folder" >
<xsl:with-param name="src" select="$totalUri"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="sp:frag" priority="1">
<xsl:param name="src" />
<xsl:variable name="refUri" select="@sc:refUri" />
<xsl:variable name="refDoc" select="document($refUri)" />
<xsl:variable name="totalUri">
<xsl:value-of select="concat($src, $refUri)" />
</xsl:variable>
<xsl:apply-templates select="$refDoc/sc:item/of:fragment" >
<xsl:with-param name="src" select="$totalUri"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="sc:uLink[@role='def']" priority="1">
<xsl:param name="src" />
<xsl:variable name="refUri" select="@sc:refUri" />
<xsl:variable name="refDoc" select="document($refUri)" />
<xsl:variable name="totalUri">
<xsl:value-of select="concat($src, $refUri)" />
</xsl:variable>
<xsl:apply-templates select="$refDoc/sc:item/of:def">
<xsl:with-param name="src" select="$totalUri"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="sc:uLink[@role='ref' and contains(@sc:refUri, '.section')]" priority="2">
<xsl:param name="src" />
<xsl:choose >
<xsl:when test="../self::sc:para">
<xsl:value-of select="." />
</xsl:when>
<xsl:otherwise>
<xsl:variable name="refUri" select="@sc:refUri" />
<xsl:variable name="refDoc" select="document($refUri)" />
<xsl:variable name="totalUri">
<xsl:value-of select="concat($src, $refUri)" />
</xsl:variable>
<xsl:apply-templates select="$refDoc/sc:item/of:section">
<xsl:with-param name="src" select="$totalUri"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="sc:uLink[@role='ref' and @sc:refUri]" priority="1">
<xsl:param name="src" />
<xsl:variable name="refUri" select="@sc:refUri" />
<xsl:comment>sc:uLink src = <xsl:value-of select="$src"/> refUri = <xsl:value-of select="$refUri"/></xsl:comment>
<sc:uLink role="ref" sc:refUri="{$src}{$refUri}">
<xsl:value-of select="."/>
</sc:uLink>
</xsl:template>
<xsl:template match="sp:evtList[contains(@sc:refUri, '.object')]" priority="1">
<xsl:param name="src" />
<xsl:variable name="refUri" select="@sc:refUri" />
<xsl:variable name="refDoc" select="document($refUri)" />
<xsl:variable name="totalUri">
<xsl:value-of select="concat($src, $refUri)" />
</xsl:variable>
<xsl:apply-templates select="$refDoc/sc:item/of:eventList">
<xsl:with-param name="src" select="$totalUri"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="sp:tree[contains(@sc:refUri, '.tree')]" priority="1">
<xsl:param name="src" />
<xsl:variable name="refUri" select="@sc:refUri" />
<xsl:variable name="refDoc" select="document($refUri)" />
<xsl:variable name="totalUri">
<xsl:value-of select="concat($src, $refUri)" />
</xsl:variable>
<xsl:apply-templates select="$refDoc/sc:item/of:tree">
<xsl:with-param name="src" select="$totalUri"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="sc:extBlock[@role='img' and @sc:refUri]" priority="1">
<xsl:param name="src" />
<xsl:variable name="refUri" select="@sc:refUri" />
<sc:extBlock role="img" sc:refUri="{$src}{$refUri}"></sc:extBlock>
</xsl:template>
<xsl:template match="sp:gallery[@sc:refUri]">
<xsl:param name="src" />
<xsl:variable name="refUri" select="@sc:refUri" />
<xsl:variable name="refDoc" select="document($refUri)" />
<xsl:variable name="refUriWithoutLastPart">
<xsl:call-template name="removeLastPart">
<xsl:with-param name="value" select="$refUri" />
<xsl:with-param name="everything" select="$refUri" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="totalUri">
<xsl:value-of select="concat($src, $refUriWithoutLastPart)" />
</xsl:variable>
<xsl:apply-templates select="$refDoc/sc:item/of:gallery" >
<xsl:with-param name="src" select="$totalUri"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="sp:img[@sc:refUri]">
<xsl:param name="src" />
<xsl:variable name="refUri" select="@sc:refUri" />
<sp:img role="ref" sc:refUri="{$src}{$refUri}">
<xsl:value-of select="."/>
</sp:img>
</xsl:template>
<xsl:template name="removeLastPart">
<xsl:param name="everything" />
<xsl:param name="value" />
<xsl:variable name="separator" select="'/'" />
<xsl:choose>
<xsl:when test="contains($value, $separator)">
<xsl:call-template name="removeLastPart">
<xsl:with-param name="value" select="substring-after($value, $separator)" />
<xsl:with-param name="everything" select="$everything" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring-before($everything, $value)" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="of:folder">
<xsl:param name="src" />
<xsl:copy>
<xsl:comment>Web Folder in dir : <xsl:value-of select="$src"/></xsl:comment>
<xsl:apply-templates select="node()|@*">
<xsl:with-param name="src" select="$src"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<!--Retracer le bon lien pour tous les refUri...-->
</xsl:stylesheet>
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="http://www.utc.fr/ics/hdoc/xhtml"
xmlns:ns="http://www.utc.fr/ics/hdoc/xhtml"
>
<xsl:output method="xml" indent="yes"/>
<!-- Identity transformation -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<!-- section -->
<xsl:template match="ns:section" priority="1">
<xsl:choose>
<xsl:when test="ns:section">
<xsl:element name="section">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="section">
<xsl:attribute name="data-hdoc-type">opale-expUc</xsl:attribute>
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<project name="wikiToHdoc" default="main" basedir="..">
<!-- inputFile is the only required parameter to run the script -->
<property name="inputFile" value="source.xml"/>
<basename property="filename" file="${inputFile}" suffix=".xml"/>
<!-- Folder paths -->
<!-- tmp paths (removed at the end of the process) -->
<property name="tmpFolderPath" value="${basedir}/tmp"/>
<property name="tmpHdocResultFolderPath" value="${tmpFolderPath}/hdoc"/>
<!-- ant and xslt paths -->
<property name="resultFolderPath" value="${basedir}/result"/>
<property name="xsltFolderPath" value="${basedir}/xslt"/>
<!-- result path -->
<property name="hdocResultPath" value="${resultFolderPath}/${filename}"/>
<!-- Main target -->
<target name="main">
<antcall target="prepare"/>
<antcall target="prepareHdocStructure"/>
<antcall target="transformWikiToHdoc"/>
<antcall target="zip"/>
<antcall target="clean"/>
</target>
<target name="prepare">
<!-- Create tmp directory for tmp files and result directory if does not exist -->
<mkdir dir="${tmpHdocResultFolderPath}"/>
<mkdir dir="${hdocResultPath}"/>
<!-- Making tmp xml wikipedia file without some elements which are not useful -->
<xslt classpath="ant/saxon9he.jar" in="ant/${inputFile}" out="${tmpFolderPath}/${filename}_prepared.xml" style="${xsltFolderPath}/prepare_wiki_to_hdoc.xsl">
<factory name="net.sf.saxon.TransformerFactoryImpl"/>
</xslt>
</target>
<!-- Create the hdoc structure of the new file -->
<target name="prepareHdocStructure">
<mkdir dir="${tmpHdocResultFolderPath}"/>
<mkdir dir="${tmpHdocResultFolderPath}/META-INF" />
<touch file="${tmpHdocResultFolderPath}/META-INF/container.xml" />
<touch file="${tmpHdocResultFolderPath}/mimetype" />
<echo message="application/x-hdoc+zip" file="${tmpHdocResultFolderPath}/mimetype" />
<echoxml file="${tmpFolderPath}/containerTmp.xml">
<container version="1.0" xmlns="urn:utc.fr:ics:hdoc:container">
<rootfiles>
<rootfile full-path="content.xml" media-type="text/xml" />
</rootfiles>
</container>
</echoxml>
<xslt classpath="ant/saxon9he.jar" in="${tmpFolderPath}/containerTmp.xml" out="${tmpHdocResultFolderPath}/META-INF/container.xml" style="${xsltFolderPath}/addNamespaceToContainer.xsl"/>
</target>
<target name="transformWikiToHdoc">
<!-- Applying wikipedia -> hdoc -->
<xslt classpath="ant/saxon9he.jar" in="${tmpFolderPath}/${filename}_prepared.xml" out="${hdocResultPath}/${filename}.html" style="${xsltFolderPath}/wiki_to_hdoc.xsl">
<factory name="net.sf.saxon.TransformerFactoryImpl"/>
</xslt>
<!-- Copy of the html file, hdoc needs "container.xml" file, not a html. The html file can be useful to the user -->
<copy file="${hdocResultPath}/${filename}.html" tofile="${tmpHdocResultFolderPath}/content.xml"/>
</target>
<!-- Make hdoc file -->
<target name="zip">
<zip destfile="${hdocResultPath}/${filename}.hdoc" basedir="${tmpHdocResultFolderPath}"/>
</target>
<!-- Delete tmp directory -->
<target name="clean">
<delete dir="${tmpFolderPath}"/>
</target>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project name="wikiToHdoc" default="main" basedir=".">
<!-- wikipediaUrl and destination are the only required parameters -->
<property name="wikipediaUrl" value=""/>
<property name="filename" value=""/>
<!-- Folder paths -->
<!-- tmp paths (removed at the end of the process) -->
<property name="tmpFolderPath" value="${basedir}/tmp"/>
<property name="tmpHdocResultFolderPath" value="${tmpFolderPath}/hdoc"/>
<property name="in" location="${basedir}/input"/>
<property name="resultFolderPath" value="${basedir}/result"/>
<property name="xsltFolderPath" value="${basedir}/xslt"/>
<property name="hdocResultPath" value="${resultFolderPath}/${filename}"/>
<property name="inputFile" value="${hdocResultPath}/${filename}.xml"/>
<!-- Main target -->
<target name="main">
<antcall target="prepare"/>
<antcall target="prepareHdocStructure"/>
<antcall target="transformWikiToHdoc"/>
<antcall target="zip"/>
<antcall target="clean"/>
</target>
<target name="prepare">
<!-- Create tmp directory for tmp files and result directory if does not exist -->
<mkdir dir="${tmpHdocResultFolderPath}"/>
<mkdir dir="${hdocResultPath}"/>
<!-- Fetching html from wikipedia -->
<java fork="true" failonerror="true" jar="${basedir}/javaSources/FetchWikipediaXml.jar">
<arg value="${wikipediaUrl}"/>
<arg value="${filename}"/>
</java>
<!-- Making tmp xml wikipedia file without some elements which are not useful -->
<xslt classpath="lib/saxon9he.jar" in="${inputFile}" out="${tmpFolderPath}/${filename}_prepared.xml" style="${xsltFolderPath}/prepare_wiki_to_hdoc.xsl">
<factory name="net.sf.saxon.TransformerFactoryImpl"/>
</xslt>
</target>
<!-- Create the hdoc structure of the new file -->
<target name="prepareHdocStructure">
<mkdir dir="${tmpHdocResultFolderPath}"/>
<mkdir dir="${tmpHdocResultFolderPath}/META-INF" />
<touch file="${tmpHdocResultFolderPath}/META-INF/container.xml" />
<touch file="${tmpHdocResultFolderPath}/mimetype" />
<echo message="application/x-hdoc+zip" file="${tmpHdocResultFolderPath}/mimetype" />
<echoxml file="${tmpFolderPath}/containerTmp.xml">
<container version="1.0" xmlns="urn:utc.fr:ics:hdoc:container">
<rootfiles>
<rootfile full-path="content.xml" media-type="text/xml" />
</rootfiles>
</container>
</echoxml>
<xslt classpath="lib/saxon9he.jar" in="${tmpFolderPath}/containerTmp.xml" out="${tmpHdocResultFolderPath}/META-INF/container.xml" style="${xsltFolderPath}/addNamespaceToContainer.xsl"/>
</target>
<target name="transformWikiToHdoc">
<!-- Applying wikipedia -> hdoc -->
<xslt classpath="lib/saxon9he.jar" in="${tmpFolderPath}/${filename}_prepared.xml" out="${hdocResultPath}/${filename}.html" style="${xsltFolderPath}/wiki_to_hdoc.xsl">
<factory name="net.sf.saxon.TransformerFactoryImpl"/>
</xslt>
<!-- Copy of the html file, hdoc needs "container.xml" file, not a html. The html file can be useful to the user -->
<copy file="${hdocResultPath}/${filename}.html" tofile="${tmpHdocResultFolderPath}/content.xml"/>
</target>
<!-- Make hdoc file -->
<target name="zip">
<zip destfile="${hdocResultPath}/${filename}.hdoc" basedir="${tmpHdocResultFolderPath}"/>
</target>
<!-- Delete tmp directory -->
<target name="clean">
<delete dir="${tmpFolderPath}"/>
</target>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project name="wikiToOpale" default="main" basedir="..">
<!-- inputFile is the only required parameter to run the script -->
<property name="inputFile" value="source.xml"/>
<basename property="filename" file="${inputFile}" suffix=".xml"/>
<!-- Folder paths -->
<!-- tmp paths (removed at the end of the process) -->
<property name="tmpFolderPath" value="${basedir}/tmp"/>
<property name="tmpHdocResultFolderPath" value="${tmpFolderPath}/hdoc"/>
<!-- ant and xslt paths -->
<property name="resultFolderPath" value="${basedir}/result"/>
<property name="antFolderPath" value="${basedir}/ant"/>
<property name="xsltFolderPath" value="${basedir}/xslt"/>
<!-- result path -->
<property name="hdocResultPath" value="${resultFolderPath}/${filename}"/>
<target name="main">
<!-- First: wiki to Hdoc -->
<ant antfile="${antFolderPath}/wiki_to_hdoc.ant"/>
<!-- Then hdoc to opale (important to set the new basedir in order to make it work) -->
<ant antfile="${basedir}/hdoc_to_opale/hdoc_to_opale.ant" dir="${basedir}/hdoc_to_opale">
<property name="InputPath" value="${hdocResultPath}/${filename}.hdoc"/>
<property name="OutputPath" value="${hdocResultPath}/${filename}.scar"/>
</ant>
</target>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project name="wikiToOpale" default="main" basedir="..">
<!-- wikipediaUrl and destination are the only required parameters -->
<property name="wikipediaUrl" value=""/>
<property name="filename" value=""/>
<!-- Folder paths -->
<!-- tmp paths (removed at the end of the process) -->
<property name="tmpFolderPath" value="${basedir}/tmp"/>
<property name="tmpHdocResultFolderPath" value="${tmpFolderPath}/hdoc"/>
<!-- ant and xslt paths -->
<property name="resultFolderPath" value="${basedir}/result"/>
<property name="antFolderPath" value="${basedir}/ant"/>
<property name="xsltFolderPath" value="${basedir}/xslt"/>
<!-- result path -->
<property name="hdocResultPath" value="${resultFolderPath}/${filename}"/>
<target name="main">
<!-- First: wiki to Hdoc -->
<ant antfile="${antFolderPath}/wiki_to_hdoc_fetcher.ant"/>
<!-- Then hdoc to opale (important to set the new basedir in order to make it work) -->
<ant antfile="${basedir}/hdoc_to_opale/hdoc_to_opale.ant" dir="${basedir}/hdoc_to_opale">
<property name="InputPath" value="${hdocResultPath}/${filename}.hdoc"/>
<property name="OutputPath" value="${hdocResultPath}/${filename}.scar"/>
<property name="OutputPathDivided" value="${hdocResultPath}/${filename}_divided.scar"/>
</ant>
</target>
</project>
\ No newline at end of file
hdoc_to_opale @ 5b6cedd1
Subproject commit 5b6cedd19b2bf98a4a78c27402102f0cc3fc0099
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
public class FetchWikipediaXml {
public static void main(String[] args) throws IOException {
URL url = new URL(args[0]);
String destination = args[1];
System.out.println(destination);
BufferedInputStream in = null;
FileOutputStream fout = null;
in = new BufferedInputStream(url.openStream());
fout = new FileOutputStream("test.xml");
final byte data[] = new byte[1024];
int count;
while ((count = in.read(data, 0, 1024)) != -1) {
fout.write(data, 0, count);
}
if (in != null) {
in.close();
}
if (fout != null) {
fout.close();
}
}
}
import java.io.BufferedInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
public class FetchWikipediaXml {
public static void main(String[] args) throws Exception {
URL url = new URL(args[0]);
String destination = args[1];
System.out.println("URL "+args[0]);
System.out.println("File "+args[1]);
if(destination.length() == 0 || !args[0].contains("wikipedia.org/wiki"))
throw new Exception("Received invalid parameters");
BufferedInputStream in = null;
FileOutputStream fout = null;
in = new BufferedInputStream(url.openStream());
fout = new FileOutputStream("result/" + destination + "/" + destination + ".xml");
final byte data[] = new byte[1024];
int count;