Tutorial introduction
Cocoon is a Java server framework that allows the dynamic publishing of XML content using XSLT (XML Stylesheet Language-Transformation) transformations. By relying on XML to describe content, and XSLT as a means of transforming that content into multiple formats, Cocoon provides a platform for building applications with strong separation between content, logic, and presentation.
Cocoon uses the concept of a pipeline to describe the process of publishing content to the Web. A wide variety of reusable components are included, which can be configured to produce complex behavior with a minimum of Java development. For example, using XML and XSLT alone, Cocoon can be used to:
- Serve static files as well as dynamically generated responses
- Map user requests transparently onto physical resources with an arbitrary amount of processing
- Perform both simple and multistage XSLT transformations
- Pass parameters dynamically to XSLT transformations
- Generate a wide variety of output formats including XML, HTML, PNG, JPEG, SVG, and PDF
This all adds up to a great deal of power that can be put to work using existing skills in XML and XSLT. Cocoon lets you produce dynamic Web sites with a minimum of fuss.
Cocoon is an open-source project being developed as part of the Apache XML effort. Cocoon 2 is a complete rewrite of the original Cocoon application and is the recommended version. New users should start directly with Cocoon 2, while existing Cocoon 1 users are encouraged to upgrade.
The aim of the Cocoon 2 project was to take the lessons learned during Cocoon 1 development and use them to engineer a more efficient and scalable platform. In particular, Cocoon 1 relied on the Document Object Model (DOM) API to pass XML data between components. The DOM is an inefficient means of passing data because a typical DOM tree can consume several times more memory than the original XML document. This severely limited Cocoon's scalability. Cocoon 2 is built around the SAX API, which is a more lightweight means of manipulating XML data.
Another key difference between the two versions of Cocoon centers on application management. In Cocoon 1, individual XML documents declared how they should be processed by including Cocoon processing instructions. This tied documents to specific processing, greatly restricting flexibility to reuse content in different ways. Cocoon 2 factors out management of processing into a configuration file known as a sitemap. This separates out the processing logic from the content itself, which in turn separates concerns among content, logic, and presentation.
Cocoon 2, because it is a more scalable and flexible platform than the original Cocoon application, is the focus of this tutorial.
Who should take this tutorial?
To get the most from this tutorial, and Cocoon 2, readers should already be familiar with XML and XSLT. While Cocoon is a Java application, you don't need any in-depth Java experience to use it.
This tutorial covers the following:
- How to install and configure Cocoon
- An introduction to the principles of the Cocoon 2 architecture and its key components
- An introduction to the sitemap -- the means of managing Cocoon Web applications
- Example pipeline configurations that demonstrate how to construct a dynamic Web site using Cocoon and XSLT
Cocoon is a Java Web application and must be run within a Java-Servlet-2.2-compliant servlet engine. The next section, Installing and configuring Cocoon , includes details on how to download and install Jakarta Tomcat 4.0.1, the latest reference implementation of the servlet API.
Both Tomcat and Cocoon require installation of a Java 2 development kit. The Java 2 SDK, 1.3.1 can be downloaded from http://java.sun.com/j2se/.
To fetch the Cocoon source code so the application can be built locally, CVS also needs to be installed. See the CVS Web site, http://www.cvshome.org/, for further information.





