Transcript Structured-Document Processing Languages
7 XML Web Site Architecture
Example:
Apache Cocoon
, a Web publishing architecture based on XML technology http://xml.apache.org/cocoon – Apache: "XML publishing framework" » runs as a servlet (Java class under the control of a Web server, to handle incoming HTTP request) – Cocoon 1 (1999 –); not supported anymore – Cocoon 2 » more efficient (based on SAX instead of DOM) » better site administration (with "sitemaps") SDPL 2002 Notes 7: Apache Cocoon 1
Cocoon Philosophy (1/2)
Separation of concerns with "pyramid of contracts": SDPL 2002 Notes 7: Apache Cocoon 2
Cocoon Philosophy (2/2)
Different responsibilities <-> different groups – Site administrators, Developers, Content producers, Style designers – related declarations separated in different files – supports co-operation of specialised groups – enhances system modularity and extensibility – allows re-use of solutions to different tasks Content, logic and style merged using XSL transformations SDPL 2002 Notes 7: Apache Cocoon 3
Example of typical use
Automatic generation of HTML from (static or generated) XML documents – client-dependent processing possible, serving, e.g., » HTML to "typical" web browsers » WML to WAP-devices » XML to XML/XSL aware clients – also more sophisticated formatting (FOP -> PDF) In
Cocoon 1
processing of a request (by a sequence of
Processors
and a
Formatter
) controlled by embedded processing instructions (See next) SDPL 2002 Notes 7: Apache Cocoon 4
Example (of Cocoon
1
)
Different views of content for different clients:
cocoon-process
type="xslt"?>
media="wap"
?>
Example (of Cocoon
1
)
Cocoon 1 configured to handle various User Agents of the HTTP request – explorer, opera, lynx, netscape, java, wap Default style sheet welcome.xsl
specifies generation of HTML, and welcome-wml.xsl processing for WAP devices – See next SDPL 2002 Notes 7: Apache Cocoon 6
Stylesheet welcome-wml.xsl
Style sheet welcome-wml.xsl (2)
This page has been transformed from XML into WML by Cocoon's XSLT processor.
SDPL 2002 Notes 7: Apache Cocoon 8Cocoon 2 Pipeline
Pipeline
: sequence of component interactions to process a request
– typical case: SDPL 2002 Notes 7: Apache Cocoon 9
Main Components of Cocoon 2 (1/2)
Generators
create XML as a SAX stream. E.g: – FileGenerator: XML file -> SAX stream – HTMLGenerator: HTML file -> XHTML (as SAX stream) – … (and more components can be added)
Transformers
manipulate a SAX stream and pass the result to the next component – XSLT Transformer (default) – Include Transformers (for XML inclusion via URL) – SQL Transformer (to access a DB, and include results) – … SDPL 2002 Notes 7: Apache Cocoon 10
Components of Cocoon 2 (2)
Serializers
render a SAX stream to some result format (interpretable by the client) – HTML Serializer (default) – XML Serializer, Text Serializer – PDF/PS Serializer (based on FOP) – … Components and pipelines declared in a Sitemap – In XML file sitemap.xmap
(translated to sitemap_xmap.java
) SDPL 2002 Notes 7: Apache Cocoon 11
Selecting a Pipeline
SDPL 2002 Notes 7: Apache Cocoon 12
Declaring Pipelines
Setting up a pipeline
SDPL 2002 Notes 7: Apache Cocoon 14
XSP (Extensible Server Pages)
Cocoon technology for dynamic content Procedural code within static document content – similar with other server pages like JSP or ASP <
xsp:page
xmlns:xsp="
http://apache.org/xsp
language="java"> ...
" – XML document containing tag-based directives for generating dynamic content at request time – translated by XSP processor into Cocoon Generators SDPL 2002 Notes 7: Apache Cocoon 15
XSP: Embedding code into pages
Example ( time.xsp
); Display the time of day:
language="java" xmlns:xsp="
http://www.apache.org/xsp
">
Date now = new Date();
It’s now //Variable for the time of day:
now
XSP processor generates a Generator ...
SDPL 2002 Notes 7: Apache Cocoon 16
XSP page as Generator (fragments of)
public class time_xsp extends XSPGenerator { … //Variable for the time of day: Date now = new Date(); public void generate() throws SAXException { this.contentHandler.startDocument(); AttributesImpl attrs=new AttributesImpl(); attrs.addAttribute("", " title ", " title ", "CDATA", " Time of Day "); this.contentHandler.startElement("", " page ", " page ", attrs); … this.contentHandler.endDocument(); } SDPL 2002 Notes 7: Apache Cocoon 17
XSP to Generated Content to Result
SDPL 2002 Notes 7: Apache Cocoon 18
Example Result
Final HTML page could be:
Time of Day
It's now Thu Dec 23 20:11:18 PST 1999
OK, but can also separate logic from content (See next) SDPL 2002 Notes 7: Apache Cocoon 19Library Tags
Could replace the preceding with a
library tag:
...
It's now
– Separation of concerns: »
programmers
encapsulate behaviour in dynamic tags »
content authors
use application-oriented markup to write XML documents Tag library: set of custom tags – for including code in documents – with its own namespace SDPL 2002 Notes 7: Apache Cocoon 20
Implementation of Tag Libraries
Tag library implemented by a
logic sheet
– XSLT stylesheet translating XSP -> XSP – registered in configuration file cocoon.xconf
xsp:expr
> formatDate(new Date(), "
xsp:expr
> SDPL 2002 Notes 7: Apache Cocoon 21
Using Tag Libraries
SDPL 2002 Notes 7: Apache Cocoon 22
Logic Sheets and Tag Libraries
Separation of document structure and … – presentation:
stylesheets
give
presentation semantics
to tags – processing:
logic sheets
to tags give
procedural semantics Built-in tag libraries
for various dynamic information: – Request: request method & params, protocol, … – Session: methods for HTTP Session – ESQL: SQL database queries SDPL 2002 Notes 7: Apache Cocoon 23
ESQL: Example (1/2)
esql
="
http://apache.org/cocoon/SQL/v2
">
connectionName
SELECT name, addr FROM Emp
…
SDPL 2002 Notes 7: Apache Cocoon 24
ESQL: Example (2/2)
|
|
Sorry, no results!
SDPL 2002 Notes 7: Apache Cocoon 25
Cocoon used in practise?
April 2001:
– 57 Web sites powered by Cocoon 1
April 2002:
– 34 Web sites powered by Cocoon 1 – 17 Web sites powered by Cocoon 2 » (34+17 < 57 !) – 9 service providers offering "Cocoon hosting" SDPL 2002 Notes 7: Apache Cocoon 26
Summary
Apache Cocoon – "Publishing framework" based on XML technology » esp. on XSLT transformations – Configurable architecture » Components » Sitemap – XSP and tag libraries for dynamic content Interesting and promising concept – Ideas may survive, perhaps in different systems » (E.g. IBM ServletManager?) SDPL 2002 Notes 7: Apache Cocoon 27