Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Publish dynamic XML content with Cocoon 2, Part 2: Working with XSP in Apache Cocoon 2

Generate dynamic XML content with XML Server Pages

Leigh Dodds (leigh@xmlhack.com), Developer and editor, Ingenta, Ltd.
Photo of Leigh Dodds
Leigh Dodds is team leader of the Research and Technology Group at Ingenta, Ltd. He has five years of experience in developing on the Java platform, and he has spent the last three years working with XML and related technologies. Leigh is also a contributing editor to xmlhack.com, and has been writing the regular "XML-Deviant" column on XML.com since February 2000. He holds a bachelor's degree in biological science, and a master's in computing. When he's not wrestling with pointy brackets, Leigh can be found making silly noises with his son, Ethan.

Summary:  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, and 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.

View more content in this series

Date:  23 Apr 2002
Level:  Introductory PDF:  A4 and Letter (108 KB | 32 pages)Get Adobe® Reader®

Activity:  6350 views
Comments:  

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

What is XSP?

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.


XSP and JSP

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.


Tools

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.


Upgrading Cocoon 2

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
            

1 of 9 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML
ArticleID=138580
TutorialTitle=Publish dynamic XML content with Cocoon 2, Part 2: Working with XSP in Apache Cocoon 2
publish-date=04232002
author1-email=leigh@xmlhack.com
author1-email-cc=dwxed@us.ibm.com

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.