You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users-fr@cocoon.apache.org by Sebastien BARATHIEU <se...@urssaf.fr> on 2005/09/20 09:48:10 UTC
Réf. : Erreur " did notsend a response"
Voici une implémentation qui fonctionne correctement et qui dépasse le
cadre simple de ton problème, néammoins elle peut donner des idées :
La fonction Makepdf estimplémenté dans un fichier pdf.flow :
function makepdf() {
var xml_file;
var pdf_file;
var outstreamPDF;
// the parameter passed to the script from the pipeline.
// This is the real path to the application context
var folder1 = Packages.java.lang.String(cocoon.parameters["folder1"]);
try {
// creating links to files
pdf_file = Packages.java.io.File( folder1 +".pdf");
// xml_file = Packages.java.io.File( "D:/Program Files/Apache Software
Foundation/Tomcat
5.0/webapps/cocoon/ImpressionLiasse/U13010000757_0404151956.xml");
// creating outputstream to dump the results of conversion to the
file
outstreamPDF = new Packages.java.io.FileOutputStream( pdf_file );
// calling cocoon pipeline using processPipelineTo() method and
dumping the results to the outputstream
cocoon.processPipelineTo( "/ImpressionLiasse/" + folder1 +".pdf",
null, outstreamPDF );
// do not forget to close the outputstream
outstreamPDF.close();
// since the result is dumped to the filesystem we need to send smth.
to the browser
// to make it happy. So let's send just a usual .txt file with OK
message
cocoon.sendPage("yes.txt", null);
} catch( ex ) {
//cocoon.log.error(ex);
// Smth. went wrong. Sending a error.txt file to the browser
cocoon.sendPage("error.txt", null);
}
}
Au niveau du sitemap, on retrouve obligatoirement:
<map:flow language="javascript">
<map:script src="pdf.flow"/>
</map:flow>
et ensuite les pattern dans le pipeline:
<map:pipeline>
<map:match pattern="**.pdf">
<map:generate src="{1}.xml"/>
<map:transform src="principal.xsl"/>
<map:serialize type="fo2pdf"/>
</map:match>
<map:match pattern="**.do">
<map:call function="makepdf">
<map:parameter name="folder1" value="{1}"/>
</map:call>
</map:match>
<map:match pattern="**.xml">
<map:act type="copy-source" src="
cocoon:/production/{1}.pdf">
<map:parameter name="dest" value="{1}.pdf"/>
</map:act>
<map:generate type="jx" src="success.jx">
<map:parameter name="filename" value="{1}"/>
</map:generate>
<map:serialize type="html"/>
</map:match>
<map:match pattern="*.txt">
<map:redirect-to uri=""/>
</map:match>
<map:match pattern="**/generate-all.html">
<!-- liste de tous les fichiers xml -->
<map:generate type="directory" src="{1}">
</map:generate>
<map:transform src="dir2include.xsl">
<map:parameter name="folder1" value="{1}"/>
</map:transform>
<!-- on réalise l'inclusion qui par effet de bord va
copier les
sur disque -->
<map:transform type="xinclude"/>
<map:serialize type="html"/>
</map:match>
<map:match pattern="">
<map:generate src="vide.xml"/>
<map:transform src="vide.xslt">
<map:parameter name="contextPath" value="{request:contextPath}"/>
</map:transform>
<map:serialize type="xhtml"/>
</map:match>
</map:pipeline>
A noter le pattern "genrate-all.html" qui permet de boucler sur le contenu
d'un répertoire (tant qu'il existe des xml à transformer), dans ce cas on
fait appel à un fichier dir2include.xsl
<xsl:stylesheet version="1.0" xmlns:xsl="
http://www.w3.org/1999/XSL/Transform" xmlns:dir="
http://apache.org/cocoon/directory/2.0" xmlns:xi="
http://www.w3.org/2001/XInclude">
<xsl:param name="folder1" select="/"/>
<xsl:template match="dir:file">
<p>
<!-- on inclut le rapport de g诩ration d'un fichier dont
on extrait le body -->
<xsl:variable name="long_nom_fic" select="string-length
(@name)"/>
<xsl:variable name="nom_fic_temp" select="substring
(@name, 1, $long_nom_fic - 3)"/>
<xi:include href="cocoon:/{concat($folder1, '/',
$nom_fic_temp, 'do')}">
<xi:fallback/>
</xi:include>
</p>
</xsl:template>
</xsl:stylesheet>
Cette réalisation a bien entendu pu aboutir grace à la communauté Cocoon,
Française notamment.
Dans ton cas précis je suppose qu'il ne manque que la déclaration map:flow
dans le sitmeap (pour pouvoir utiliser le javascript), c'est pour cela que
le call function est défaillant.
Cordialement
|--------------+---------------------------------+----------------------------------|
| (Embedded | Sébastien BARATHIEU | (Embedded image moved to file: |
| image moved | EDI CFE | pic19912.gif) |
| to file: | Etudes | sebastien.barathieu@urssaf.fr |
| pic01869.jpg)| CIPAM Marseille | (Embedded image moved to file: |
| | | pic23811.gif) |
| | | Groupe CFE : 04 91 74.96.12 |
| | | Personnel : 04.91.74.97.11 |
|--------------+---------------------------------+----------------------------------|