cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Derek Hohls" <dho...@csir.co.za>
Subject Re: AW: How to replace SQL/ESQL datasource through an XMLdatasource
Date Fri, 11 May 2007 16:01:10 GMT
Urs

This is not a straightforward issue.

One of the design principals of Cocoon is that of "separation of
concerns" - the pipeline concept evolved to support that, as did the
various components - generators, transfomers etc.  Unfortunately, the
XSP concept sits somewhat awkwardly in this approach; I think it was
developed in the early days of Cocoon as a type of equivalent to the
templating approach used in many other web frameworks (and which was,
perhaps, perceived as lacking in Cocoon).  As generators and
transformers grew in scope and power, development of XSP was left to one
side and is, effectively, deprecated. The main reason for this is that
it encourages mixing of logic and layout, and makes it hard to achieve
that ideal of "separation of concerns" which Cocoon aims at.  Logic and
complex program flow now resides in javascript code, and templating in
JXtemplates, data generation from databases in the SQLTransformer etc.

In short then, I think you need to restructure your application to
ensure that a change in one step, e.g. data generation, does not impact
on those downstream.  Specifically, stylesheets doing layout should
receive a consistent set of structured data from "upstream".  It seems
that, in your case, you will need to write an XSL file (or series of
files) to process the data from the data XML file.  The alternative is
to write a custom transformer in Java to do this for you.  This means
work in the short term - but a better and more maintainable application
in the long run.

HTH
Derek



>>> "Urs Iwert" <urs.iwert@sysinf.ch> 05/11/07 4:19 PM >>>
Hi Derek 
 
Thanks for helping me.
 
The first step from the matcher gets the raw data from the database and
I can do some calculation or formatting stuff. This works great for me
because the esql-stylesheet is merging raw data and layout together.
Using XSP is very convenient to skip rows, having values formatted,
running sums, etc. Further steps are just to translate and to transform
into the requested output format.
 
So far I could access the database directly. From the new requirements I
get the raw data from an xml file. It's easy to read an xml file, but
there is where my problem starts. Merging layout and raw data can not be
done in a similar way (using ESQL/XSP). At least I have to write an xsl
stylesheet to merge raw data and layout.
 
Using an xsl-stylesheet merging raw data and layout would mean I have to
transfer all logic from the xsp page to the stylesheet and therefore
rewriting all existing reports.

Urs
 

<!-- sitemap.xmap
------------------------------------------------------->
 
Here's the matcher in the sitemap
 
<map:match pattern="report/*.pdf">
    <map:generate src="report/{1}.xsp" type="serverpages" />
    <map:transform type="i18n" />
    <map:transform src="stylesheets/doc2pdf.xsl" />
    <map:serialize type="fo2pdf" />
</map:match><~!B*+R^&> 

<!-- employee.xsp
------------------------------------------------------->
 
Following a very simple example: 
 
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsp:page 
  language="java" 
  xmlns:xsp="http://apache.org/xsp" 
  xmlns:esql="http://apache.org/cocoon/SQL/v2" 
  xmlns:i18n="http://apache.org/cocoon/i18n/2.1">
 
  <content><~!B*+R^&> 
    <page orientation="landscape" paper="A4">
 
    <title><i18n:text>Employees</i18n:text></title><~!B*+R^&>

    <esql:connection><~!B*+R^&>     
<esql:pool>mydb</esql:pool><~!B*+R^&>      
      <esql:execute-query><~!B*+R^&>        <esql:query>select
firstname, lastname, age from employee order
by age asc</esql:query><~!B*+R^&> 
        <esql:results><~!B*+R^&>          <table border="0">
            <colgroup><~!B*+R^&>              <col width="4"/> <!--
firstname -->
              <col width="4"/> <!-- lastname -->
              <col width="2"/> <!-- age -->
            </colgroup><~!B*+R^&> 
            <thead><~!B*+R^&>              <tr><~!B*+R^&>
              
<th align="left"><i18n:text>firstname</i18n:text></th><~!B*+R^&>
       
       <th align="left"><i18n:text>lastname</i18n:text></th><~!B*+R^&>
 
             <th
align="center"><i18n:text>age</i18n:text></th><~!B*+R^&>  
          
</tr><~!B*+R^&>            </thead><~!B*+R^&>            
              

            <tbody><~!B*+R^&>              <esql:row-results><~!B*+R^&>

              <xsp:logic><~!B*+R^&>                    int age = (int)
<esql:get-int column="age"/>;
                    if (age > 50) {
                </xsp:logic><~!B*+R^&> 
                <tr><~!B*+R^&>                  <td><esql:get-string
column="firstname"/></td><~!B*+R^&>                 
<td><esql:get-string column="lastname"/></td><~!B*+R^&>      
          
<td><esql:get-int    column="age"/></td><~!B*+R^&>           
   
</tr><~!B*+R^&>                
                <xsp:logic><~!B*+R^&>                    }
                </xsp:logic><~!B*+R^&>             
</esql:row-results><~!B*+R^&>            </tbody><~!B*+R^&>
           
          </table><~!B*+R^&>        </esql:results><~!B*+R^&>

      </esql:execute-query><~!B*+R^&>    </esql:connection><~!B*+R^&>

</page><~!B*+R^&>                
  </content><~!B*+R^&></xsp:page><~!B*+R^&> 

 

________________________________

Von: Derek Hohls [mailto:DHohls@csir.co.za] 
Gesendet: Freitag, 11. Mai 2007 13:56
An: users@cocoon.apache.org
Betreff: Re: How to replace SQL/ESQL datasource through an XMLdatasource


Urs
 
Your problem statement is not quite clear in this message;
perhaps you can indicate your overall program logic, showing
how data is handled and processed by the different parts of 
Cocoon.   You need to differentiate clearly between data 
retrieval ('"raw" data); data alteration (eg. calculated values);
data manipulation (e.g. sorting) and data layout (order, 
appearance etc.) This will help visualise alternatives.
 
Derek

>>> "Urs Iwert" <urs.iwert@sysinf.ch> 2007/05/11 11:51:54 AM >>>

Hi cocooners,

I'm using cocoon to creating html,pdf,xls and rtf reports.

I started using XSP/ESQL to connect directly to the datasource (mysql)
and merged the data with the layout of the report in the xsp page.

<map:match pattern="report/*.xml">
    <map:generate src="report/{1}.xml" type="serverpages" />
    <map:transform type="i18n" />
    <map:transform src="stylesheets/doc2pdf.xsl" />
    <map:serialize type="fo2pdf" />
</map:match><~!B*+R^&><~!B*+R^&>  
Now the requirements have changed and the xml data comes from an other
provider. So I don't have to deal with the sql statement anymore, but
how can I merge the xml data with the layout of the report in the xsp
page. Formatting, filtering, grouping, calculations depend on the
provided data using xsp. How can use this approach without transfering
the! logic to a xsl stylesheet.

I can't see any solution. Any idea appreciated.

Urs Iwert

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org



-- 
This message is subject to the CSIR's copyright, terms and conditions
and e-mail legal notice. 
Views expressed herein do not necessarily represent the views of the
CSIR. 

CSIR E-mail Legal Notice
<http://mail.csir.co.za/CSIR_eMail_Legal_Notice.html>  

CSIR Copyright, Terms and Conditions
<http://mail.csir.co.za/CSIR_Copyright.html>  

For electronic copies of the CSIR Copyright, Terms and Conditions and
the CSIR Legal Notice 
send a blank message with "REQUEST LEGAL" in the subject line to CSIR
CallCentre <mailto:CallCentre@csir.co.za>  


This message has been scanned for viruses and dangerous content by
MailScanner <http://www.mailscanner.info/> , 
and is believed to be clean. 



-- 
This message is subject to the CSIR's copyright, terms and conditions and
e-mail legal notice. Views expressed herein do not necessarily represent the
views of the CSIR.
 
CSIR E-mail Legal Notice
http://mail.csir.co.za/CSIR_eMail_Legal_Notice.html 
 
CSIR Copyright, Terms and Conditions
http://mail.csir.co.za/CSIR_Copyright.html 
 
For electronic copies of the CSIR Copyright, Terms and Conditions and the CSIR
Legal Notice send a blank message with REQUEST LEGAL in the subject line to
CallCentre@csir.co.za.


This message has been scanned for viruses and dangerous content by MailScanner, 
and is believed to be clean.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Mime
View raw message