A Gentle Introduction to Cocoon.
Compelling reasons to be cheerful when faced with new Web Publishing
Challenges
1. Why So?
It's too New.
1999, Stefano Mazzocchi, MIT, Apache Board Member
http://cocoon.apache.org/2.1/userdocs/concepts/index.html
It's strange.
Unix pipelines
It's different.
XML++
It's compulsive.
My eyesight is deteriorating
It's weird, Euro trash
So was Lego, in the beginning
They eat their own dog food over there
Mighty nutritious and delicious
2. Complexity demands Architecture
Pyramid of Contracts
Separate 4 major Concerns with 5 Comprehensible Contracts
Mix 'em at your Peril
Functional, Declarative Pipelines enforce side-effect-less-ness
KISS
Follow a piece of string
Service Oriented
Web, EJB, Internal protocol and External proxy
3. XML at the top of the Stack
Impedance Mismatch
XML from the top down maintains consistency
The Climate Changed
We aren't standing on OO land anymore - afloat on the monster mashup blogosphere
Greater Agility Required
Let the framework do the heavy lifting
Ruby on Rails vs Grails vs Cocoon
A developer writes 10 lines of working code a day
10 lines of Java doing something arcane to the business DOM
clientElement = ElementHelper.getElement( updatedRiskData.getRootElement(), "//client" ); processDataElement.add( clientElement.detach() ); // clear modified flags modifiedItems = processDataElement.selectNodes( "//*[@modified='true']" ); if ( ( modifiedItems != null ) && !modifiedItems.isEmpty() ) { Iterator itemIter = modifiedItems.iterator(); while ( itemIter.hasNext() ) { // remove attribute ( (Element) itemIter.next() ).addAttribute( "modified", null ); } }
A 10 line pipeline that invokes EJB services, builds a view of the results and re-uses a presentation resource
<map:match pattern="logQuote"> <map:generate type="jx" src="newclientpolicy.xml"/> <map:transform type="ejb"> <map:parameter name="application" value="BarclaysHNW"/> </map:transform> <map:transform src="dayState.xsl"/> <map:transform type="xmldb"/> <map:call resource="dayViewRes"/> </map:match>
Mixing-up mental models
Uniformity of approach costs less in the long run
4. Pipes
Unix Pipes, Yahoo Pipes, Teqlo, Drain Pipes, Half-Pipes
grep index.html access.log | awk {print $2 } | sort | uniq | wc -l
Tools to build hosted mashup applications
Cocoon patterns are merging into the mainstream. Pipes mashes up data feeds, Teqlo orchestrates the inputs and outputs of widgets
Paloose is a simplified (much simplified) version of Cocoon using PHP. There are relatively few ISPs who will support Java/Tomcat for web sites and this is the authors solution to that dilemma
XProc - An XML Pipeline Language
http://www.w3.org/TR/xproc/
The Sitemap is a Plan of the pipelines
5. Pipeline Detail
The Pipelines that generate this presentation; dynamically or statically
Produces the Index of available presentations
<map:match pattern="index.html"> <map:generate type="directory" src="presentations"/> <map:transform src="stylesheets/dir-to-html.xsl"> <map:parameter name="baseDir" value="presentations"/> </map:transform> <map:serialize type="html"/> </map:match>
Produces the Raw ASCII data of a complete presentation
<map:match pattern="presentations/**/txt/presentation.html"> <map:read src="presentations/{1}.txt" mime-type="text/plain"/> </map:match>
Produces the XML data of a complete presentation
<map:match pattern="presentations/**/xml/presentation.html"> <map:generate type="slop" src="presentations/{1}.txt"> <map:parameter name="encoding" value="iso-8859-1"/> <map:parameter name="preserve-space" value="true"/> </map:generate> <map:transform src="stylesheets/filter-slop-output.xsl"/> <map:serialize type="xml"/> </map:match>
Produces the XML data of a single slide
<map:match pattern="presentations/**/xml/slide-*.html"> <map:generate src="cocoon:/presentations/{1}/xml/presentation.html"/> <map:transform src="stylesheets/select-slide.xsl"> <map:parameter name="slideId" value="{2}"/> </map:transform> <map:serialize type="xml"/> </map:match>
Produces the Index (list of slides) of a presentation
<map:match pattern="presentations/**/html/index.html"> <map:generate src="cocoon:/presentations/{1}/xml/presentation.html"/> <map:transform src="stylesheets/html-index.xsl"/> <map:serialize type="html"/> </map:match>
Produces a Single slide or full presentation in HTML
<map:match pattern="presentations/**/html/*.html"> <map:generate src="cocoon:/presentations/{1}/xml/{2}.html"/> <map:transform src="stylesheets/html-slides.xsl"/> <map:serialize type="html"/> </map:match>
Simple Line Oriented Parser
Yet Another Presentation Tool
Stand on the shoulders of Giants and recurse
6. CLI mode for generating static content
cocoon cli -x query.xconf -n wiley
<uris name="wiley" follow-links="true" confirm-extensions="false" src-prefix="wiley/" dest="build/dest/wiley/" type="append"> <uri src="index.html"/> </uris>
7. Components
Generators
in the Beginning
Transformers
there was the Word
Serializers
and it was Good
8. Next Steps
Generate a static page for each book in collection
Develop workflow applications
Content Management System
Presentation wizard to automatically generate complicated flashy layouts with lots of gee-whiz transition effects. Just kidding.