Return-Path: Delivered-To: apmail-cocoon-docs-archive@www.apache.org Received: (qmail 97326 invoked from network); 5 May 2007 12:32:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 May 2007 12:32:08 -0000 Received: (qmail 45399 invoked by uid 500); 5 May 2007 12:32:14 -0000 Delivered-To: apmail-cocoon-docs-archive@cocoon.apache.org Received: (qmail 45283 invoked by uid 500); 5 May 2007 12:32:14 -0000 Mailing-List: contact docs-help@cocoon.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: docs@cocoon.apache.org List-Id: Delivered-To: mailing list docs@cocoon.apache.org Received: (qmail 45268 invoked by uid 99); 5 May 2007 12:32:13 -0000 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.67] (HELO cocoon.zones.apache.org) (140.211.11.67) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 05 May 2007 05:32:13 -0700 Message-ID: <30012752.1178368306447.JavaMail.daisy@cocoon.zones.apache.org> Date: Sat, 5 May 2007 12:31:46 +0000 (GMT+00:00) From: daisy@cocoon.zones.apache.org To: docs@cocoon.apache.org Subject: [DAISY] Updated: Your first XML pipeline (publishing) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org A document has been updated: http://cocoon.zones.apache.org/daisy/documentation/1290.html Document ID: 1290 Branch: main Language: default Name: Your first XML pipeline (publishing) (previously Your first XML pipel= ine) Document Type: Cocoon Document (unchanged) Updated on: 5/5/07 12:31:23 PM Updated by: Reinhard P=C3=B6tz A new version has been created, state: publish Parts =3D=3D=3D=3D=3D Content ------- This part has been updated. Mime type: text/xml (unchanged) File name: (unchanged) Size: 8304 bytes (previous version: 2927 bytes) Content diff: =20 +++

The archetype has to use Maven deployer by default.<= /p> +++=20 +++

The first tutorial should be split into two parts: o= ne that +++ only creates a block and a second one, that creates a war. That tutoria= l should +++ be stand alone because it is too much to introduce this concept there t= oo IMHO +++ (rpoetz).

+++=20 +++

The first tutorial should introduce into cocoon:rcl = so that +++ Cocoon becomes useable right away.

+++=20 +++

The first tutorial should be renamed.

+++=20

This tutorial is based on the "Your first Coc= oon application using Maven 2" guide which shows how to bootstrap a Coc= oon project.

(24 equal lines skipped) =20

First, open src\main\resources\COB-INF\sitemap.xmap in your= favorite XML editor. That's your block's base sitemap. There are already some pi= pelines --- there (/sitemap/pipelines) but for this purpose of this tutori= al, let's +++ there (/sitemap/pipelines) but for the sake of this tutorial, = let's create your own pipeline.

=20
<map:sitemap xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-inst=
ance"
(3 equal lines skipped)
   =20
      <map:pipelines>
        <map:pipeline>
---       <map:match pattern=3D"myFirstPipeline">
---         <map:generate src=3D"myXmlFile.xml"/>
+++       <map:match pattern=3D"myFirstPipeline">
+++         <map:generate src=3D"myXmlFile.xml" type=3D"file"/>
            <map:serialize type=3D"xml"/>
---       </map:match>
+++       </map:match>
        </map:pipeline>
        [...]
      </map:pipelines>
(24 equal lines skipped)
   =20
    

Adding an XSLT transformation step

=20 ---

TBD

+++

The first pipeline wasn't really exciting, just reading some XML fil= e and +++ serializing it without changing anything. The second example will add a +++ transformation step based on XSLT= :

=20 ---

Using XML templates

+++
<map:sitemap xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-inst=
ance"
+++  xsi:schemaLocation=3D"http://apache.org/cocoon/sitemap/1.0=20
+++   http://cocoon.apache.org/schema/sitemap/cocoon-sitemap-1.0.xsd"
+++  xmlns:map=3D"http://apache.org/cocoon/sitemap/1.0">
   =20
--- 

TBD

+++ <map:pipelines> +++ <map:pipeline> +++ <map:match pattern=3D"myFirstPipeline"> +++ <map:generate src=3D"myXmlFile.xml" type=3D"file"/> +++ <map:serialize type=3D"xml"/> +++ </map:match> +++ <map:match pattern=3D"mySecon= dPipeline"> +++ <map:generate src=3D"myXmlFile.xml" type=3D"file"/> +++ <map:trans= form src=3D"myXsltFile.xslt" type=3D"xslt"/><= /strong> +++ <map:serialize type=3D"html"/> +++ </map:match> +++ </map:pipeline> +++ [...] +++ </map:pipelines> =20 +++ </map:sitemap>
+++=20 +++

The XSLT file is very simple and creates an XML following the struct= ure of +++ XHTML (though without using any namespaces in order to keep things simp= le):

+++=20 +++
... [put the stylesheet here]
+++=20 +++

After saving the sitemap and the XSLT file, you can point you browse= r to +++ http://localhost:8888/myBlock1/mySecondPipeline and +++ you will see the output, this time its HTML because of the use of the H= TML +++ serializer.

+++=20 +++

In this tutorial you have already implemented two pip= elines but +++ there is only one pipeline element used in the sitemap. Given this is c= onfusing +++ when you use Cocoon sitemaps the first time. However, there is a reason= for +++ this: The <pipeline> element indicates which pipelin= e +++ implementation is used. If there is no @type attribute, t= he +++ generators, tranformers and serializers are invoked from a caching pipe= line +++ implementation.
+++ When Cocoon developers talk about pipelines, they mean a series of a ma= tcher +++ that includes at least a generator and a serializer. Transformers and o= ther +++ sitemap components are optional.

+++=20 +++

Creating a PDF

+++=20 +++

The first example created XML and the second one HTML. One of the st= rength of +++ Cocoon is that it makes it very simple to support many different output= formats. +++ The result of this third example will be a PDF, again based on +++ myXmlFile.xml:

+++=20 +++
<map:sitemap xmlns:xsi=3D"http://www.w3.org/2001/XMLSchema-inst=
ance"
+++  xsi:schemaLocation=3D"http://apache.org/cocoon/sitemap/1.0=20
+++   http://cocoon.apache.org/schema/sitemap/cocoon-sitemap-1.0.xsd"
+++  xmlns:map=3D"http://apache.org/cocoon/sitemap/1.0">
+++=20
+++   <map:pipelines>
+++     <map:pipeline>
+++       <map:match pattern=3D"myFirstPipeline">
+++         <map:generate src=3D"myXmlFile.xml" type=3D"file"/>
+++         <map:serialize type=3D"xml"/>
+++       </map:match>
+++       <map:match pattern=3D"mySecondPipeline">
+++         <map:generate src=3D"myXmlFile.xml" type=3D"file"/>
+++         <map:transform src=3D"myXsltFile.xslt" type=3D"xslt"/>
+++         <map:serialize type=3D"html"/>
+++       </map:match>
+++       <map:match =
pattern=3D"myThirdPipeline">
+++         <map:generate src=3D"myXmlFile.xml" type=3D"file"/>
+++         <map:trans=
form src=3D"myXml2PdfFile.xslt" type=3D"xslt"/>
+++         <map:serialize type=3D"fop"/>
+++       </map:match>
+++     </map:pipeline>
+++     [...]
+++   </map:pipelines>
+++=20
+++ </map:sitemap>
+++=20 +++

This pipeline needs a different XSLT file which transforms the XML o= f +++ myXmlFile.xml to some XML that can be used by +++ FOP to create PDF: +++=20 +++

... [put the stylesheet here]
+++=20 +++

You also have to use a different serializer for this example, a seri= alizer +++ that can use the XML created by the stylesheet and produce PDF based on= it. +++ Cocoon ships this serializer as part of the FOP block. Since the block = that you +++ created probably doesn't have the FOP block added as dependency, this h= as to be +++ done before you can test your pipeline. Adding a block requires editing= the +++ pom.xml of your block:

+++=20 +++
... [put the pom.xml here]
+++=20 +++

Rebuild your block:

+++=20 +++
mvn compile
+++=20 +++

and start the servlet container again:

+++=20 +++
mvn jetty:run
+++=20 +++

Now you can point your browser at +++ http://localhost:8888/myBlock1/myThirdPipeline and +++ you will get a PDF as result.

+++=20