Cocoon
Cocoon is a java framework used for making web applications. It is built on the theory of separation of concerns, pipelining and component based web development. Separation of concerns helps in consistent interaction and collaboration of people with the project. And component pipelining is used to implement these concepts.
Cocoon provides a mechanism for the description of structure and semantics of web information items termed as contents, the relationship between content items termed as logic and how they will be presented to the viewer that is style, so it will not be wrong to say that cocoon is an XML-based content management system. The basic purpose of cocoon is to separate the three layers, i.e. content layer, logic layer and style. All these layers are designed, created and managed independently.
Description
Cocoon started as a regular java servlet, and to perform its task cocoon was using W3C components. These W3C components were the document object model (DOM) used for parsing documents, XML used for capturing and formatting data, XSLT used for transforming data and manipulating XML documents, and XSL used to manage presentation of document. To serve a variety of contents, cocoon emerges into a complete XML-based publishing framework, and system.
At the current moment cocoon can be described in different ways, i.e. as an aggregator for data source, as a framework for publishing XML and as an assembly of pipelines and components. Let us have a look on the working of cocoon in these three ways:
- As publishing framework
- As data source aggregator
- As a collection of pipelines and components
Cocoon as a publishing framework
Cocoon functionality depends on pipelined processing of SAX events. When web applications are built with this framework, SAX events provide good performance and scalability. The operation involved in creating, deploying and maintaining web-based application is sustained by a centralized configuration system. Caching system is used, where configuration of components is performed dynamically. When a user requests, it check the cache, for the presence of requested Universal Resource Indicator (URI). If URI is present the contents are delivered without processing from a pipeline.
Cocoon model for publishing work like the XSLT transformation, XSLT just permit the segregation of style and content and Cocoon further defines a method for the segregation of content, style and the programming logic, which makes server side behavior. Cocoon uses XML and XSL, which is supported by major vendors, to integrate them in a publishing infrastructure. The scope of Cocoon is broad enough to cover complete features of web publishing. The basic usage of cocoon is the creation of HTML automatically by processing dynamically or statically produced XML files; still it has capability of performing complicated formatting. It is also capable of applying stylesheets to XML contents.
Cocoon as data source aggregator
Using Java servlet, cocoon can behave as abstract engine; this is rooted in customized protocol handler. Such protocols can processes an external data source using a standard URI. Cocoon has the ability of recursively calling itself to process data streams rapidly and efficiently by using multiple pipeline stages.
Cocoon as a collection of pipelines and components
The basic functionality mechanism of Cocoon architecture is modularity and abstract processing. All of the elements in cocoon pipeline are SAX events; these are formed during the parsing of XML documents. Three types of pipeline elements or components are used in Cocoon, i.e. generators, transformers and serialisers.
Generators, for further processing they produce stream of data, in other words they produce SAX events using the requested URI. The stream is either generated by existing XML document or by creating XML document from start.
Transformers, use the SAX events or stream of data to produce a new SAX event. XSLT is preferred type used for transformation of XML format, some even process data of other types like SQL etc.
Serializers, take the SAX events in the form of data stream, manipulate it and produce some kind of response to the client. Some serialisers can process different kinds of data formats, like HTML, XHTML, PDF, RTF, plain text, etc.
Internal mechanism
The implementation of Cocoon is as abstract Java engine that can be executed within as application server or by using command line. Cocoon uses the concept of component pipelines and cocoon flow for building the web application, this way it form a robust architecture. It gives a way for easy aggregation of contents, XML transformation, pluggable multi channeling, internationalization, centralized application flow logic and develop handling and validation.

This figure shows the basic internal mechanism of Cocoon. As the cocoon is component based framework, it has many pluggable components. Components basic task is to consume or produce stream of data (SAX events) so it is good practice to put them in a chain, which form SAX processing pipelines.
A particular component in a pipeline is dedicated to perform tasks of particular concern. This way style layer will work independently from content and content will work independently from logic. Individually pipelined components in cocoon can be assembled in a verity of ways, depending upon the request, and results in desired XML solution. Existing components can be extended to customer component by the web developer, or can implement the suitable component interface.
Cocoon pipeline accumulate the data sources that are generating similar XML SAX events, these are piped together via required transform components and then in serialization XML is transformed to the desired format. There are many components available for the web developers, for example, server pages generator component, extensible server pages etc.
Cocoon sitemap is used for mapping component pipelines to URI. The main configuration file for cocoon is sitemap.xmap, here web developers define specific component pipelines. Cocoon facilitates the developer by providing them mountable sub-sitemaps to divide single application.
Cocoon flow is implemented as Model View Controller (MVC), this form a control layer over sitemap. In Cocoon the flow logic is defined at a single location and sequentially. Java code form the Model, the component pipelines serve as view and flow controller behave as controller in cocoon MVC. The flow controller is implemented at server side in the form of Java Script.
Cocoon features
- Component based web development: Cocoon is developed on the concept of component based development and segregation of concerns. In this way project is divided into modules, or components and every component perform its particular task. This enhances the method of interaction and collaboration among users and system.
- Use pipelines: In cocoon component based development is implemented by pipelines, every component on one pipeline is devoted to perform one particular task. This can be termed as building block approach as different components can be hooked together into pipelines without programming effort.
- Advanced flow control: Cocoon use the continuation based page flow, which help in reducing the request response processing time and complexity. Logic complexities are totally isolated from data and view.
- Open source software: Cocoon is open source software.
- Many companies use cocoon: Cocoon is used by many live sites and companies.
What is good about Cocoon?
Cocoon has many advantages for large web applications. It is more useful for large web application where many developers are working simultaneously on a single application for development, maintenance and most appropriate for applications that need multi channeling, XML transformation, content aggregation and internalization.
What is bad about Cocoon?
One big problem of this framework is that very few people are expert in XML and XSL, as these are new formats. This mechanism has complex processing, operations included in layers processing are complex and not suitable for real time operations. Cocoon is not suitable for the transformation of simple HTML pages until XML is included in it.


Leave a comment