cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robby Pelssers <Robby.Pelss...@nxp.com>
Subject RE: [C2.2] Get Element from uploaded file
Date Thu, 17 Nov 2011 14:04:31 GMT
There are many ways to accomplish this but below a possible approach:

/**** Java Component to extract the filename **/

public interface FileNameExtractor {

   public String getFileName(String id);

}

public class PrototypeFileNameExtractor implements FileNameExtractor {

     public String getFileName(String id) {
         //TODO extract the fileName from the xml file identifiable by {id} e.g.
     }

}


/** flowscript function to generate the pdf **/

function generatePDF() {
    var id = cocoon.parameters.id;
    var fileName = cocoon.getComponent('fileNameExtractor').getFileName(id);
    var response = cocoon.response;
    response.setHeader(
                "Content-Disposition",
                "attachment; filename=" + fileName + ".pdf"
    );
    cocoon.sendPage('source2pdf/' + id);

}


Sitemap:
----------
<!--
  {1} id: unique identifier for the source xml used to generate the PDF
-->
<map:match pattern="generatePdf/*">
  <map:call function="generatePDF">
    <map:parameter name="id" value="{1}"/>
  </map:call>
</map:match>

<map:match pattern="source2pdf/*">
  <map:generate src="source/{1}.xml"/> <!-- assume our sources are located in source
folder -->
  <map:transform src="xslt/source2poi.xslt"/>
  <map:serialize type="pdf"/>
</map:match>


From: Matthias Müller [mailto:pymote@yahoo.de]
Sent: Thursday, November 17, 2011 2:40 PM
To: users cocoon.apache.org
Subject: [C2.2] Get Element from uploaded file

Hi there,

I do some xml -> pdf transformation using Coocon 2.2 and fop. My output file name must
contain a string that's in a certain element of my uploaded file.
I wonder how to access my uploaded file to extract the values?
Do I need to access it via control flow?
Is there something like a XPath evaluator?

Matthias

Mime
View raw message