Tutorial introduction
Who should take this tutorial?
This tutorial is the second in a series of tutorials on Apache Cocoon 2. It introduces XML Server Pages (XSP), the Cocoon technology for generating dynamic XML content. It is designed to build on the concepts described in the first tutorial, Introducing Cocoon 2; it is therefore recommended that you complete the previous tutorial before progressing further.
This tutorial is based on Cocoon 2. While XSP was present in Cocoon 1, architectural differences mean that the majority of the examples are not applicable to that version.
It is assumed that you are familiar with Java Web development frameworks such as Java Servlets and Java Server Pages (JSP). Where appropriate, parallels are drawn between concepts in these technologies and XSP.
This tutorial will be of interest primarily to developers who have progressed beyond the basic features of Cocoon 2 and want to learn how to add dynamic data to their XML documents to create richer Web sites. The tutorial is also relevant for developers who need to integrate Cocoon 2 with existing data sources and/or APIs to publish their data in multiple formats over the Internet.
To achieve these goals the tutorial will:
- Introduce the basic principles behind XSP
- Review the XSP syntax, allowing developers to begin creating dynamic XML documents
- Introduce custom XSP tag libraries, known as logicsheets
- Summarize the features provided by the default logicsheets that are built into Cocoon 2
- Describe how to create custom logicsheets
The first tutorial in this series described the Apache Cocoon 2 architecture, which is based on a pipeline-processing model. This model breaks down the processing of a Web request into the following basic stages:
- Parsing of XML data to generate input for the pipeline
- Transformation and manipulation of that data
- Serialization of the results, for delivery to the user
XML Server Pages (XSP) is a Cocoon 2 technology that enables the creation of dynamic XML data sources for feeding data into Cocoon 2 pipelines. These data sources are described using a combination of XML markup and application logic that is then automatically compiled into a Java class by the Cocoon 2 engine.
XSP provides a flexible platform for developing applications using Cocoon 2. For example, information in existing application databases can be exposed by Cocoon 2 applications, enabling a greater variety of data-delivery options. XSP allows Cocoon 2 to be used in an application integration environment, such as middleware and document publishing, by providing a means to show the data source through an XML interface.
Java Server Pages (JSP) is the most widely used way of generating dynamic Web interfaces using a combination of Java and HTML or XML. The resulting document is interspersed with custom tags and/or snippets of Java code that add the dynamic sections. Preserving the document structure makes JSP pages easier to maintain for non-programmers. However while the markup is emphasized for the end user, a servlet container will compile a JSP page into a standard Java servlet.
XSP has a lot in common with JSP. Both technologies:
- Consist of a mixture of program code and markup
- Are compiled into a binary form for execution
- Allow the creation of custom tag libraries
Yet XSP differs from JSP in two regards. First, XSP provides a framework for mixing code in any programming language with XML markup. XSP pages in Cocoon 2 are primarily created using Java, though other implementations are possible. For example, the AxKit XML application server (see Resources) provides an implementation of XSP that uses Perl. In contrast, JSP is specifically a Java technology.
The second and more practical difference is that XSP generates dynamic data, not dynamic presentations. JSP, on the other hand, is a presentation layer technology used to produce either HTML or XML, typically at the end of a series of processing steps. XSP pages generate XML data for Cocoon pipelines, which create the desired presentation.
No specific tools are required to complete this tutorial. To experiment with the technologies, however, it is imperative that you read the instructions on installing Cocoon 2 and Jakarta Tomcat servlet engine in the first tutorial. Refer to the "Installing and configuring Cocoon" section in the first tutorial for complete instructions.
Note: The Cocoon 2 project has released at least one new version of the application since the publication of the first tutorial in this series. It is recommended that you upgrade to the new release, which includes a number of bug fixes and enhancements. It is available at http://cocoon.apache.org/. Instructions on upgrading are available in the next panel.
You can also download the source code for examples in this tutorial.
When upgrading, take care to back up any existing configuration, style sheets, and XML documents. Do a fresh install of Cocoon 2 while retaining the existing installation. This allows applications to be migrated over one-by-one. Here are the steps:
- Shut down Tomcat
- Rename the Cocoon webapps directory to something like "old-cocoon"
- Copy the new Cocoon 2.0.2 Web application into the Tomcat webapp directory
- Delete the content of the Tomcat work directory
- Restart Tomcat
Once Tomcat has restarted, both the old and the new versions of Cocoon are available -- the old version
at http://localhost:8080/old-cocoon/ and the new version at
http://localhost:8080/cocoon/.
The following steps demonstrate one way to do this:
$CATALINA_HOME/bin/shutdown.sh
cd $CATALINA_HOME/webapps
mv cocoon old-cocoon
cp $COCOON_HOME/cocooon.war $CATALINA_HOME/webapps
rm -r $CATALINA_HOME/work/*
$CATALINA_HOME/bin/startup.sh
|


