Monday, June 11, 2007

[Tech] Cocoon 2.2 Version ahead

In the current magazine I published an article about Apache Cocoon. Cocoon is a fascinating XML Framework. However it is a little bit difficult to explain the capacity of Cocoon as it is conceptional quite different from other "Web-Frameworks" like Struts, myFaces, Wicket, Tapestry and whatnot.

Hello World...

The core concept of Cocoon are XML-processing pipelines: in short, a Pipeline is responsible for handling one request to the Cocoon server (which is actually a Servlet running in a servlet container like Tomcat or Jetty). Within a pipeline a set of different sitemap components can be used to produce a response. Typically a pipeline starts with a generator, that creates an XML stream, then one or more transformers can manipulate the stream (e.g. XSLT transformers) and finally a serializer component serialises the XML stream to the desired output format (e.g. XML, HTML, SVG, PDF, JPEG, ...).

Which pipeline feels responsible for which request is managed by pipeline matchers. To give a "hello world" example:

In this case this matcher might react at requests like "". In that case the generator would load the document "article-123.xml" and apply the XSLT transformation with the XSLT script "article.xsl" on the document. This transformation supposedly will generate XHTML and the HTML serializer will serialise this to HTML. A lot of different sitemap components are available "out of the box" that can also be combined, and own components can be written when needed, but this is only one side of the story:

...and beyond

The previous example gives a very brief idea about the core concept of Cocoon, the sitemap. But Cocoon is a full-blown web-framework. It can be used for cross-publishing issues but just relying on the sitemap idea and a lot of components that help in that context (to process SVG, PDF, HTML...), but can also be used for developing Web-applications. It has components to access relational databases, supports complex caching strategies and offers a solid form framework, Cocoon Forms: Cocoon Forms abstracts from concrete form implementations like HTML forms by defining Widgets and supports strong typing, validation and events (e.g. handled by Javascript in the browser).

Additionally Cocoon Flow allows to model the "flow" of webpages, e.g., a "wizard" like series of forms, where the path through the forms is depending on data entered in previous forms can be described very elegantly with server-side Javascript or Java code using continuations.

And Version 2.2?

Version 2.2. will be released soon and is long anticipated. Previous Cocoon versions had some issues particularly when it came to modularisation. Cocoon 2.2. has (beside several other enhancements) the advantage to use Apache Maven 2 for build management, and perfectly integrates with the Springframework. Hence it is very easy now to use arbitrary Spring beans within a Cocon application. Also the integration into Eclipse as IDE got a lot simpler. Modularisation did not stop before the Cocoon pipeline that was in previous version a little bit of a hodgepodge of various configurations and pretty hard to understand for non-experts. The same was true for the decisions which Cocoon modules to use in the own applications. Cocoon blocks does a good job in version 2.2 to make these nasty configuration issues much easier to handle and understand.

The usage of Maven also makes "startup" easier, as the Cocoon team provides Maven archetypes that generate a "hello world" Cocoon application from which starting own development becomes much more straightforward compared to earlier 2.1 releases.


Cocoon is a powerful cross-publishing XML and web-application framework . It is easy to integrate several systems using Cocoon sitemap components. In the new version the modularisation including Spring and usage of Maven as build-environment and configuration management tool are a large step forward. Several other tools build upon Cocoon like Apache Forrest or the Daisy content management system.

However, Cocoon is not a simple framework (which web-framework is?) and it needs some time to get familiar with the concepts.

1 comment:

Anonymous said...

Rails is easy... and it has a lot of code-gen features.