Return-Path: X-Original-To: apmail-cocoon-users-archive@www.apache.org Delivered-To: apmail-cocoon-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id B311996C0 for ; Fri, 18 Nov 2011 07:34:13 +0000 (UTC) Received: (qmail 35617 invoked by uid 500); 18 Nov 2011 07:34:13 -0000 Delivered-To: apmail-cocoon-users-archive@cocoon.apache.org Received: (qmail 35558 invoked by uid 500); 18 Nov 2011 07:34:07 -0000 Mailing-List: contact users-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: users@cocoon.apache.org List-Id: Delivered-To: mailing list users@cocoon.apache.org Received: (qmail 35551 invoked by uid 99); 18 Nov 2011 07:34:05 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 18 Nov 2011 07:34:05 +0000 X-ASF-Spam-Status: No, hits=2.9 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (athena.apache.org: local policy) Received: from [77.238.189.222] (HELO nm7-vm0.bullet.mail.ird.yahoo.com) (77.238.189.222) by apache.org (qpsmtpd/0.29) with SMTP; Fri, 18 Nov 2011 07:33:58 +0000 Received: from [77.238.189.55] by nm7.bullet.mail.ird.yahoo.com with NNFMP; 18 Nov 2011 07:33:36 -0000 Received: from [212.82.108.247] by tm8.bullet.mail.ird.yahoo.com with NNFMP; 18 Nov 2011 07:33:36 -0000 Received: from [127.0.0.1] by omp1012.mail.ird.yahoo.com with NNFMP; 18 Nov 2011 07:33:36 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 485495.6036.bm@omp1012.mail.ird.yahoo.com Received: (qmail 37388 invoked by uid 60001); 18 Nov 2011 07:33:36 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1321601616; bh=ByRFOlZpWXufgkNkTZtxbpO8KwMMN2OkD22rsJ6EHnY=; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=bnpFCBJaE5vED/yERfUIswMuuq8ozZ8OyTmUfJucudG9N7XJLPVBebh48w6W0oOhixpR9ftoepkqpr8cfF1eWYRjBUIuKREmU45WEgFMACKTrsTdyw5pe5jpx7RCBrkELGis4SbF3AWjA1JyDtX8bzcian4Lww4wigO+BvDZv78= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.de; h=X-YMail-OSG:Received:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=BAnRQGeMzlEMZNa2w1NOQ+KZMaWFor1D310dKmTRuWCwE/aJzaT3PmqcxAiW1nkD22NNYrUp6xSxndiqxwO6OkjyLNrrWL8Q8iep5P0GdqaHR3qVPJVx2s2Pn1wGQGCcdv1Q4xDRv/1kpYzInLIjvK8T1N3DvPZ+sKjK1dWVlh8=; X-YMail-OSG: AVSEFCoVM1muW4yxpacxypK44RLySWi8Me2YH5_lyPGfBEO w6.4R2ZcwzTGAi9CPch4EI9SUX9I516vKOkfe2LbOPpF_tm0oPLlSZjyxCby GSo0h.Aokq.Gy5hKIK4cwjYBIlLvYooPHK0iGRjSefs_uDR7SnAjg_0LtB1. mqi1FsHTzaX5QoS3w6xMfPpaGLOUkU7UdHUpfPwd_zCEBjgdB5hd186lYx95 yvWn9etLDNduMpzNIH43Rj9SKFcIL6r0XNDUYS0gFF6NpO1gtGhkyCbJYUqU cADa_IYJNsTXFhApR4vg4ELIIUEMJ6qh.1en3aSx43WmFTqPyzzBrxw4fUPf eMKzohyhZAJwzgdytkvq4dzDidJFqrnXYY3sZgXTO4jCkESn8xE6QEZxvLd3 bGBVG0Tu2GO31R19Az59i6ToN5r5wi7ffkFV29iYW7TDGJiH6JUMZE8lsNP_ TugyGNgceHN2uZNNH84K4BXtcyMRLjOqtiVCU8m.DJlD2Smz61oDeahLNZ0B g64xFqw-- Received: from [192.54.144.229] by web29503.mail.ird.yahoo.com via HTTP; Fri, 18 Nov 2011 07:33:36 GMT X-Mailer: YahooMailWebService/0.8.115.331698 References: <1321537197.76938.YahooMailNeo@web29503.mail.ird.yahoo.com> <78B923726E7D59429936580CF127E943A1EC5C845A@eu1rdcrdc1wx032.exi.nxp.com> <1321541611.11704.YahooMailNeo@web29513.mail.ird.yahoo.com> <78B923726E7D59429936580CF127E943A1EC6A7243@eu1rdcrdc1wx032.exi.nxp.com> Message-ID: <1321601616.34264.YahooMailNeo@web29503.mail.ird.yahoo.com> Date: Fri, 18 Nov 2011 07:33:36 +0000 (GMT) From: =?iso-8859-1?Q?Matthias_M=FCller?= Reply-To: =?iso-8859-1?Q?Matthias_M=FCller?= Subject: Re: [C2.2] Get Element from uploaded file To: "users@cocoon.apache.org" In-Reply-To: <78B923726E7D59429936580CF127E943A1EC6A7243@eu1rdcrdc1wx032.exi.nxp.com> MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-73641666-1956557234-1321601616=:34264" ---73641666-1956557234-1321601616=:34264 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable I extended your first approach:=0A=0A=0Ain the flow script I use the inputS= tream from the uploaded file to feed a XpathEvaluator class in combination = with the an xpath expression.=0A=0Avar inputStream =3D widget.getValue().ge= tInputStream();=0Avar xpath =3D "/my/path/to/element";=0Avar result =3D coc= oon.getComponent('XPathEvaluator').evaluate(inputStream, xpath);=0A=0AThank= s again, Matthias=0A=0A=0A=0A=0A________________________________=0A Von: Ro= bby Pelssers =0AAn: Matthias M=FCller ; "users@cocoon.apache.org" =0AGesendet: 16:2= 2 Donnerstag, 17.November 2011=0ABetreff: RE: [C2.2] Get Element from uploa= ded file=0A =0A=0AI actually had a similar need the other week and while I = have used some XML-JAVA mappers like Castor and XStream in the past I decid= ed to try another approach where I generated JSON which can be used from fl= owscript:=0A=A0=0A=A0=0A/** flowscript function to generate the pdf **/=0A= =A0=0A=A0=0Afunction json2Object(json) {=0A=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 return eval("(" + json + ")");=0A}=0A=A0=0A=A0=0Afunction g= eneratePDF() {=0A=A0=A0=A0 var id =3D cocoon.parameters.id;=A0 //e.g. PH333= 0L=0A=A0=0A=A0=0A=A0=A0=A0 //var fileName =3D cocoon.getComponent('fileName= Extractor').getFileName(id);=0A=A0=0A=A0=A0=A0 var output =3D new Packages.= java.io.ByteArrayOutputStream();=0A=A0=0A=A0=A0=A0 var uri =3D "extractData= /" + id;=A0=A0 =0A=A0=A0=A0=A0//now we invoke a pipeline which returns a JS= ON string. E.g:=0A=A0=A0=A0 /**=0A=A0=A0=A0=A0 *=A0=A0 {"id": "PH3330L","fi= leName": "PH3330L.pdf"},=0A=A0=A0=A0=A0 */=0A=A0=A0=A0 cocoon.processPipeli= neTo(uri, null, output);=0A=A0=0A=A0=A0=A0 var responseData =3D json2Object= (output.toString());=A0=A0=A0 =0A=A0=0A=A0=0A=A0=A0=A0 var response =3D coc= oon.response;=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0 =0A=A0=A0=A0 response.setHeader(=0A=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0 "Content-Disposition",=0A=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0 "attachment; filename=3D" + responseData.fileName;=0A=A0=A0= =A0 );=A0=A0=A0=A0=A0=A0=A0=A0 =0A=A0=A0=A0 cocoon.sendPage('source2pdf/' += id);=0A=A0=0A}=0A=A0=0A=A0=0ASitemap:=0A----------=0A=0A=0A=A0 =0A= =A0=A0=A0 =0A=A0 =0A=0A=A0=0A=0A=A0 =0A=A0 =0A=A0 =0A=0A=A0=0A=0A=0A=A0 =0A=A0 =0A=A0 = =A0 =0A=0A=A0= =0A=A0=0A=A0=0A/**** ExtractData.xslt will generate a JSON representation o= f the DATA needed ****/=0A=A0=0A= =0A=0A=A0=0A=0A=A0=A0=A0 =0A=A0=A0=0A=A0 =0A=A0= =0A=A0 =0A=A0=A0=A0 {"id": "= ", "fileName: ""}=0A=A0 =0A=A0 =0A=A0=0A=A0=A0=A0 =0A=A0 ---73641666-1956557234-1321601616=:34264 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
I extended your first= approach:

in the flow script I use the= inputStream from the uploaded file to feed a XpathEvaluator class in combi= nation with the an xpath expression.

var inputStre= am =3D widget.getValue().getInputStream();
var xpath =3D "/my/path/to/el= ement";
var result =3D cocoon.getComponent('XPathEvaluator').evaluate(in= putStream, xpath);

Thanks again, Matthias


<= hr size=3D"1"> Von: Robby= Pelssers <Robby.Pelssers@nxp.com>
An: Matthias M=FCller <pymote@yahoo.de>; "users@co= coon.apache.org" <users@cocoon.apache.org>
Gesendet: 16:22 Donnerstag, 17.November 2011 Betreff: RE: [C2.2] Get = Element from uploaded file

I = actually had a similar need the other week and while I have used some XML-J= AVA mappers like Castor and XStream in the past I decided to try another ap= proach where I generated JSON which can be used from flowscript:
 
 =
/** flowscri= pt function to generate the pdf **/
&nbs= p;
&n= bsp;
f= unction json2Object(json) {
         = ;       return eval("(" + json + ")");=
}
 
 
function generatePDF= () {
&= nbsp;   var id =3D cocoon.parameters.id;  //e.g. PH3330L
 
 =
 = ;   //var fileName =3D cocoon.getComponent('fileNameExtractor').getFileName(id);
 
 &= nbsp;  var output =3D new Packages.java.io.ByteArrayOutputStream();
 <= /span>
 =    var uri =3D "extractData/" + id;  
   &nbs= p;//now we invoke a pipeline which returns a JSON string. E.g:
    /**
   &n= bsp; *   {"id": "PH3330L","fileName": "PH3330L.pdf"},
   = ;  */
    cocoon.processPipelineTo(uri, null, output);=
 
    var= responseData =3D json2Object(output.toString());    =
 
 
 &nb= sp;  var response =3D cocoon.response;     &n= bsp;            = ;      
    response.setHeader(
   &nbs= p;            "Conte= nt-Disposition",
          &nbs= p;     "attachment; filename=3D" + responseData.fileNam= e;
&nb= sp;   );         <= /div>
  &= nbsp; cocoon.sendPage('source2pdf/' + id);
 
}
 
 
Sitemap:
----------
<!--
  {1} id: uniqu= e identifier for the source xml used to generate the PDF
-->
<map:match pattern= =3D"generatePdf/*">
  <map:call function=3D"generatePDF">
    <m= ap:parameter name=3D"id" value=3D"{1}"/>
  </map:call>
=
</map:match>=
&nbs= p;
<= ;map:match pattern=3D"source2pdf/*">
  <map:generate src=3D"source/{1}= .xml"/> <!-- assume our sources are located in source folder -->
  <map:transform src=3D"xslt/source2poi.xslt"/>
  <map:serialize type=3D"pdf"/>
</ma= p:match>
 
  {1} id: unique identifier for the source xml used to generate th= e PDF
= -->
<map:match pattern=3D"extractData/*">
  <map:generate src=3D"sourc= e/{1}.xml"/>
  <= map:transform src=3D"extractData.xslt"/>
  <map:serialize type=3D"json= "/>  <!-- you can quickly test with @type=3D"text" -->=
</map:mat= ch>
 
 
 
 
<?xml version=3D"1.0" encoding=3D"UTF-8"?>
<!--
  Author: Robby = Pelssers
-->
 
<xsl:= stylesheet version=3D"2.0"
  xmlns:xsl=3D"http://www.w3.org/1999/XSL/T= ransform"
  xmlns:xs=3D"http://www.w3.org/2001/XMLSchema">
  &n= bsp;
&nbs= p; <xsl:output method=3D"text" version=3D"1.0" encoding=3D"UTF-8"/&= gt;
&n= bsp;
=  
    <xsl:text>{"id= ": "</xsl:text><xsl:value-of select=3D"someXpathExpr"/><xsl:= text>", "fileName: "</xsl:text><xsl:value-of select=3D"someXpathExpr"/>"}<xsl:= text></xsl:text>
=   </xsl:template>
 
 
    =
</xsl:sty= lesheet> 
&nbs= p;
&n= bsp;


=
---73641666-1956557234-1321601616=:34264--