You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@cocoon.apache.org by da...@cocoon.zones.apache.org on 2007/05/05 14:31:46 UTC
[DAISY] Updated: Your first XML pipeline (publishing)
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 pipeline)
Document Type: Cocoon Document (unchanged)
Updated on: 5/5/07 12:31:23 PM
Updated by: Reinhard Pötz
A new version has been created, state: publish
Parts
=====
Content
-------
This part has been updated.
Mime type: text/xml (unchanged)
File name: (unchanged)
Size: 8304 bytes (previous version: 2927 bytes)
Content diff:
<html>
<body>
+++ <p class="fixme">The archetype has to use Maven deployer by default.</p>
+++
+++ <p class="fixme">The first tutorial should be split into two parts: one that
+++ only creates a block and a second one, that creates a war. That tutorial should
+++ be stand alone because it is too much to introduce this concept there too IMHO
+++ (rpoetz).</p>
+++
+++ <p class="fixme">The first tutorial should introduce into cocoon:rcl so that
+++ Cocoon becomes useable right away.</p>
+++
+++ <p class="fixme">The first tutorial should be renamed.</p>
+++
<p>This tutorial is based on the <a href="daisy:1159">"Your first Cocoon
application using Maven 2" guide</a> which shows how to bootstrap a Cocoon
project.</p>
(24 equal lines skipped)
<p>First, open <tt>src\main\resources\COB-INF\sitemap.xmap</tt> in your favorite
XML editor. That's your block's base sitemap. There are already some pipelines
--- there (<tt>/sitemap/pipelines</tt>) but for this purpose of this tutorial, let's
+++ there (<tt>/sitemap/pipelines</tt>) but for the sake of this tutorial, let's
create your own pipeline.</p>
<pre><map:sitemap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
(3 equal lines skipped)
<map:pipelines>
<strong> <map:pipeline>
--- <map:match pattern="myFirstPipeline">
--- <map:generate src="myXmlFile.xml"/>
+++ <strong> <map:match pattern="myFirstPipeline">
+++ <map:generate src="myXmlFile.xml" type="file"/>
<map:serialize type="xml"/>
--- </map:match>
+++ </map:match></strong>
</map:pipeline></strong>
[...]
</map:pipelines>
(24 equal lines skipped)
<h1>Adding an XSLT transformation step</h1>
--- <p>TBD</p>
+++ <p>The first pipeline wasn't really exciting, just reading some XML file and
+++ serializing it without changing anything. The second example will add a
+++ transformation step based on <a href="http://www.w3.org/TR/xslt">XSLT</a>:</p>
--- <h1>Using XML templates</h1>
+++ <pre><map:sitemap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+++ xsi:schemaLocation="http://apache.org/cocoon/sitemap/1.0
+++ http://cocoon.apache.org/schema/sitemap/cocoon-sitemap-1.0.xsd"
+++ xmlns:map="http://apache.org/cocoon/sitemap/1.0">
--- <p>TBD</p>
+++ <map:pipelines>
+++ <map:pipeline><strong>
+++ </strong> <map:match pattern="myFirstPipeline">
+++ <map:generate src="myXmlFile.xml" type="file"/>
+++ <map:serialize type="xml"/>
+++ </map:match><strong>
+++ </strong><strong><strong><strong> <map:match pattern="mySecondPipeline">
+++ <map:generate src="myXmlFile.xml" type="file"/>
+++ </strong></strong><strong><strong><strong><strong> <map:transform src="myXsltFile.xslt" type="xslt"/></strong></strong></strong></strong>
+++ <strong><strong> <map:serialize type="html"/>
+++ </map:match></strong></strong></strong>
+++ </map:pipeline>
+++ [...]
+++ </map:pipelines>
+++ </map:sitemap></pre>
+++
+++ <p>The XSLT file is very simple and creates an XML following the structure of
+++ XHTML (though without using any namespaces in order to keep things simple):</p>
+++
+++ <pre>... [put the stylesheet here]</pre>
+++
+++ <p>After saving the sitemap and the XSLT file, you can point you browser to
+++ <tt>http://localhost:8888/myBlock</tt><tt><tt>1</tt>/mySecondPipeline</tt> and
+++ you will see the output, this time its HTML because of the use of the HTML
+++ serializer.</p>
+++
+++ <p class="note">In this tutorial you have already implemented two pipelines but
+++ there is only one pipeline element used in the sitemap. Given this is confusing
+++ when you use Cocoon sitemaps the first time. However, there is a reason for
+++ this: The <tt><pipeline> </tt>element indicates which <em>pipeline
+++ implementation</em> is used. If there is no <tt>@type</tt> attribute, the
+++ generators, tranformers and serializers are invoked from a caching pipeline
+++ implementation. <br/>
+++ When Cocoon developers talk about pipelines, they mean a series of a matcher
+++ that includes at least a generator and a serializer. Transformers and other
+++ sitemap components are optional.</p>
+++
+++ <h1>Creating a PDF</h1>
+++
+++ <p>The first example created XML and the second one HTML. One of the strength 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
+++ <em>myXmlFile.xml</em>:</p>
+++
+++ <pre><map:sitemap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+++ xsi:schemaLocation="http://apache.org/cocoon/sitemap/1.0
+++ http://cocoon.apache.org/schema/sitemap/cocoon-sitemap-1.0.xsd"
+++ xmlns:map="http://apache.org/cocoon/sitemap/1.0">
+++
+++ <map:pipelines>
+++ <map:pipeline><strong>
+++ </strong> <map:match pattern="myFirstPipeline">
+++ <map:generate src="myXmlFile.xml" type="file"/>
+++ <map:serialize type="xml"/>
+++ </map:match><strong>
+++ </strong> <map:match pattern="mySecondPipeline">
+++ <map:generate src="myXmlFile.xml" type="file"/>
+++ <map:transform src="myXsltFile.xslt" type="xslt"/>
+++ <map:serialize type="html"/>
+++ </map:match><strong><strong><strong>
+++ </strong></strong></strong><strong><strong><strong> <map:match pattern="myThirdPipeline">
+++ <map:generate src="myXmlFile.xml" type="file"/>
+++ </strong></strong><strong><strong><strong><strong> <map:transform src="myXml2PdfFile.xslt" type="xslt"/></strong></strong></strong></strong>
+++ <strong><strong> <map:serialize type="fop"/>
+++ </map:match></strong></strong></strong>
+++ </map:pipeline>
+++ [...]
+++ </map:pipelines>
+++
+++ </map:sitemap></pre>
+++
+++ <p>This pipeline needs a different XSLT file which transforms the XML of
+++ myXmlFile.xml to some XML that can be used by
+++ <a href="http://xmlgraphics.apache.org/fop/">FOP</a> to create PDF:</p>
+++
+++ <pre>... [put the stylesheet here]</pre>
+++
+++ <p>You also have to use a different serializer for this example, a serializer
+++ 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 has to be
+++ done before you can test your pipeline. Adding a block requires editing the
+++ pom.xml of your block:</p>
+++
+++ <pre>... [put the pom.xml here]</pre>
+++
+++ <p>Rebuild your block:</p>
+++
+++ <pre>mvn compile</pre>
+++
+++ <p>and start the servlet container again:</p>
+++
+++ <pre>mvn jetty:run</pre>
+++
+++ <p>Now you can point your browser at
+++ <tt>http://localhost:8888/myBlock</tt><tt><tt>1</tt>/myThirdPipeline</tt> and
+++ you will get a PDF as result.</p>
+++
</body>
</html>