Presentation is loading. Please wait.

Presentation is loading. Please wait.

SDPL 2002Notes 7: Apache Cocoon1 7 XML Web Site Architecture Example: Apache Cocoon, a Web publishing architecture based on XML technology

Similar presentations


Presentation on theme: "SDPL 2002Notes 7: Apache Cocoon1 7 XML Web Site Architecture Example: Apache Cocoon, a Web publishing architecture based on XML technology"— Presentation transcript:

1 SDPL 2002Notes 7: Apache Cocoon1 7 XML Web Site Architecture Example: Apache Cocoon, a Web publishing architecture based on XML technology http://xml.apache.org/cocoon 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")

2 SDPL 2002Notes 7: Apache Cocoon2 Cocoon Philosophy (1/2) n Separation of concerns with "pyramid of contracts":

3 SDPL 2002Notes 7: Apache Cocoon3 Cocoon Philosophy (2/2) Different responsibilities  different groups 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 n Content, logic and style merged using XSL transformations

4 SDPL 2002Notes 7: Apache Cocoon4 Example of typical use n 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) n In Cocoon 1 processing of a request (by a sequence of Processors and a Formatter) controlled by embedded processing instructions (See next)

5 SDPL 2002Notes 7: Apache Cocoon5 Example (of Cocoon 1) n Different views of content for different clients: <?xml-stylesheet href = "welcome-wml.xsl" type="text/xsl" media="wap"?> type="text/xsl" media="wap"?> <myMessage> Welcome to XML! Welcome to XML! </myMessage>

6 SDPL 2002Notes 7: Apache Cocoon6 Example (of Cocoon 1) Cocoon 1 configured to handle various User- Agents of the HTTP request 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 Default style sheet welcome.xsl specifies generation of HTML, and welcome-wml.xsl processing for WAP devices –See next

7 SDPL 2002Notes 7: Apache Cocoon7 Stylesheet welcome-wml.xsl <xsl:stylesheet version = "1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <!-- Add a Cocoon instruction to format the result as WML: --> type = "text/wml" type = "text/wml" … …

8 SDPL 2002Notes 7: Apache Cocoon8 Style sheet welcome-wml.xsl (2) <wml><card> This page has been transformed This page has been transformed from XML into WML by Cocoon's XSLT processor. from XML into WML by Cocoon's XSLT processor. </xsl:stylesheet>

9 SDPL 2002Notes 7: Apache Cocoon9 Cocoon 2 Pipeline n Pipeline: sequence of component interactions to process a request –typical case:

10 SDPL 2002Notes 7: Apache Cocoon10 Main Components of Cocoon 2 (1/2) n 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) n 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) –…

11 SDPL 2002Notes 7: Apache Cocoon11 Components of Cocoon 2 (2) n 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) –… n Components and pipelines declared in a Sitemap –In XML file sitemap.xmap (translated to sitemap_xmap.java )

12 SDPL 2002Notes 7: Apache Cocoon12 Selecting a Pipeline

13 SDPL 2002Notes 7: Apache Cocoon13 Declaring Pipelines <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0" > … xmlns:map="http://apache.org/cocoon/sitemap/1.0" > … … …

14 SDPL 2002Notes 7: Apache Cocoon14 Setting up a pipeline

15 SDPL 2002Notes 7: Apache Cocoon15 XSP (Extensible Server Pages) n Cocoon technology for dynamic content n Procedural code within static document content –similar with other server pages like JSP or ASP...... –XML document containing tag-based directives for generating dynamic content at request time –translated by XSP processor into Cocoon Generators

16 SDPL 2002Notes 7: Apache Cocoon16 XSP: Embedding code into pages Example ( time.xsp ); Display the time of day: Example ( time.xsp ); Display the time of day: //Variable for the time of day: //Variable for the time of day: Date now = new Date(); Date now = new Date(); It’s now now It’s now now </xsp:page> n XSP processor generates a Generator...

17 SDPL 2002Notes 7: Apache Cocoon17 XSP page as Generator (fragments of) public class time_xsp extends XSPGenerator { … //Variable for the time of day: … //Variable for the time of day: Date now = new Date(); Date now = new Date(); public void generate() throws SAXException { public void generate() throws SAXException {this.contentHandler.startDocument(); AttributesImpl attrs=new AttributesImpl(); attrs.addAttribute("", "title", "title", "CDATA", "Time of Day"); "CDATA", "Time of Day");this.contentHandler.startElement("", "page", "page", attrs); …this.contentHandler.endDocument();}

18 SDPL 2002Notes 7: Apache Cocoon18 XSP to Generated Content to Result

19 SDPL 2002Notes 7: Apache Cocoon19 Example Result n Final HTML page could be: <html> Time of Day Time of Day <body> It's now Thu Dec 23 20:11:18 PST 1999 It's now Thu Dec 23 20:11:18 PST 1999 </body></html> n OK, but can also separate logic from content (See next)

20 SDPL 2002Notes 7: Apache Cocoon20 Library Tags n 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 n Tag library: set of custom tags –for including code in documents –with its own namespace

21 SDPL 2002Notes 7: Apache Cocoon21 Implementation of Tag Libraries n Tag library implemented by a logic sheet –XSLT stylesheet translating XSP  XSP –registered in configuration file cocoon.xconf could be implemented by template formatDate(new Date(), "<xsl:value-of formatDate(new Date(), "<xsl:value-of select='@format' />"); </xsl:template>

22 SDPL 2002Notes 7: Apache Cocoon22 Using Tag Libraries

23 SDPL 2002Notes 7: Apache Cocoon23 Logic Sheets and Tag Libraries n Separation of document structure and … –presentation: stylesheets give presentation semantics to tags –processing: logic sheets give procedural semantics to tags n Built-in tag libraries for various dynamic information: –Request: request method & params, protocol, … –Session: methods for HTTP Session –ESQL: SQL database queries

24 SDPL 2002Notes 7: Apache Cocoon24 ESQL: Example (1/2) <xsp:page language="java" xmlns:xsp="http://www.apache.org/xsp" xmlns:esql="http://apache.org/cocoon/SQL/v2"> xmlns:esql="http://apache.org/cocoon/SQL/v2"> connectionName connectionName <esql:query> SELECT name, addr FROM Emp SELECT name, addr FROM Emp</esql:query> …

25 SDPL 2002Notes 7: Apache Cocoon25 ESQL: Example (2/2) Sorry, no results! Sorry, no results! </esql:connection></xsp:page>

26 SDPL 2002Notes 7: Apache Cocoon26 Cocoon used in practise? n April 2001: –57 Web sites powered by Cocoon 1 n 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"

27 SDPL 2002Notes 7: Apache Cocoon27 Summary n Apache Cocoon –"Publishing framework" based on XML technology »esp. on XSLT transformations –Configurable architecture » Components » Sitemap –XSP and tag libraries for dynamic content n Interesting and promising concept –Ideas may survive, perhaps in different systems »(E.g. IBM ServletManager?)


Download ppt "SDPL 2002Notes 7: Apache Cocoon1 7 XML Web Site Architecture Example: Apache Cocoon, a Web publishing architecture based on XML technology"

Similar presentations


Ads by Google