Title: Experiences using Apache Cocoon
1Experiences using Apache Cocoon Matthew
Mascord 21st January 2004
2Slide 1
Structure
- Context
- Survey of Web Architectures
- Apache Cocoon
- Experiences
3Slide 2
Context Publication Archive
- Data-driven system, many output formats
- Small code footprint gt modification easier, so
- Maximize code reuse, integrate with off-the-shelf
components - Favour declarative solutions over procedural
- Use open standards
- Separate concerns
4Slide 3
Web Architectures Model 1
- Collection of JSPs/ASPs/PHPs
- Support classes (beans)
- Simple but
- business logic mixed with presentation
- Lots of Java code intermixed with HTML
(scriplets) - Difficult to maintain lacks SoC
5Slide 4
Web Architectures Tag Libraries
- Tag libraries bundle common operations
- Coded in Java
- JSTL standardises common tags
- Expression Language to query Beans
6Slide 5
Model 2 In Pictures
- Based on Model-View-Controller (MVC)
- Apache Struts as a very popular framework
Controller
View
Struts Controller
Action Class
JSP
HTTP Request
Model
HTTP Response
Form Bean
Result Bean
7Slide 6
Model 2 - Assessed
- Logic presentation separated but
- can still hack the JSP
- Struts APIs complex
- JSP limited as view e.g. not pipelined
- JSP compilation error reporting still a problem
- JSP tags JSTL can help but tags written in Java
hard to define tags in terms of other tags.
8Slide 7
XSLT
- Declarative (functional) language for
transforming XML - Very powerful expression language XPath
- Transforms XML to many formats TXT, HTML, XML,
CSV, SVG, PDF (via XSL-FO), MS EXCEL etc etc - Model 2X proposed to integrate XSLT with Struts
Model 2 architecture
9Slide 8
Apache Cocoon
- Web development framework built around Separation
of Concerns (SoC) and component-based development
(COP) - Lego -like approach to development minimal
coding - XML publishing framework with XSLT and pipelined
SAX processing - Data integration framework RDBMS, LDAP, XMLDB
etc ? HTML, WML, PDF, RTF etc
10Slide 9
Apache Cocoon - Concepts
- Sitemap
- Readers
- Matchers Selectors
- Generators
- Transformers
- Serializers
- Actions
- XSPs Logicsheets
11Slide 10
Cocoon Pipeline Example
ltmappipelinegt ltmapmatch pattern"search"gt ltma
pact type"search"gt ltmapgenerate
type"serverpages" src"xsp/search.xsp"
/gt ltmaptransform src"xsl/search.xsl"/gt ltma
pserialize/gt lt/mapactgt lt/mapmatchgt lt/mappip
elinegt
12Slide 11
Cocoon XML Example
ltpublicationgt lttitlegtFoundation for Future
Database Systemslt/titlegt ltcontributorgt ltpersonn
amegtC J Datelt/personnamegt ltrolegtAUTHORlt/rolegt lt
/contributorgt ltcontributorgt ltpersonnamegtHugh
Darwenlt/personnamegt ltrolegtAUTHORlt/rolegt lt/contr
ibutorgt ltcontributorgt ltpersonnamegtFabian
Pascallt/personnamegt ltrolegtEDITORlt/rolegt lt/contr
ibutorgt lt/publicationgt
13Slide 12
Cocoon XSLT Example
ltxsltemplate match"publication"gt ltpgt Title
ltinput type"text" name"title"
value"title"/gt lt/pgt ltpgt Authors
ltxslfor-each select"contributorrole'AUTHOR'
"gt ltxslvalue-of select"personname"/gt ltxsl
if test"not(position()last())"gt ltxsltextgt,
lt/xsltextgt lt/xslifgt lt/xslfor-eachgt lt/pgt lt/xs
ltemplategt
14Slide 13
Cocoon Example Result
Title Foundation for Future Database
Systems Authors C J Date, Hugh Darwen
15Slide 14
Cocoon Decision to Use
- Many frameworks need to make decision
- Cocoon is mature popular
- Well supported resources, newsgroups, Wiki
- Open Source modular
- Many output formats
- Minimal coding
- RDBMS -gt XML conversion
16Slide 15
Cocoon Usage
- Tomcat DBCP datasource exposed using JNDI
- XSPs logicsheets for each page
- ESQL translates RDBMS data to XML
- Cocoon Actions call BL
17Slide 16
Cocoon - Benefits
- Sitemap pipelines very powerful MVC controller
- Excellent for prototyping
- Extremely customizable nearly all components
are replaceable - Ties together disparate data sources
- Delivers content to disparate devices
18Slide 17
Cocoon - Drawbacks
- XSP mixes syntax
- Logicsheets difficult to debug. Like C STL.
- ESQL not ideal
- Tries to do everything (monolithic) gt
integration challenges - Aim to use as presentation layer only
- Have separate layer that generates XML
19Slide 18
Conclusions
- Lots of choice too much
- XSLT simplifies presentation layer
- Cocoon provides framework to do XSLT with minimal
coding - Keep to the core features
20Slide 19
References
- http//java.sun.com/blueprints/patterns/MVC-detail
ed.html - http//www.w3.org/TR/xslt
- http//cocoon.apache.org/2.0/
- http//www.javaworld.com/javaworld/jw-12-1999/jw-1
2-ssj-jspmvc.html - http//www.javaworld.com/javaworld/jw-02-2002/jw-0
201-strutsxslt.html