1 / 27

7 XML Web Site Architecture

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)

suchin
Download Presentation

7 XML Web Site Architecture

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 7 XML Web Site Architecture • Example: Apache Cocoon, a Web publishing architecture based on XML technologyhttp://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") Notes 7: Apache Cocoon

  2. Cocoon Philosophy (1/2) • Separation of concerns with "pyramid of contracts": Notes 7: Apache Cocoon

  3. 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 Notes 7: Apache Cocoon

  4. 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) Notes 7: Apache Cocoon

  5. Example (of Cocoon 1) • Different views of content for different clients: <?xml version = "1.0"?> <!-- Fig. 16.1 in Deitel et al. --> <!-- Pass document through an XSLT processor: --> <?cocoon-process type="xslt"?> <?xml-stylesheet href="welcome.xsl" type="text/xsl"?> <!-- default view --> <?xml-stylesheet href = "welcome-wml.xsl" type="text/xsl" media="wap"?> <!-- wap-view --> <myMessage> <message>Welcome to XML!</message> </myMessage> Notes 7: Apache Cocoon

  6. 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 Notes 7: Apache Cocoon

  7. Stylesheet welcome-wml.xsl <!-- Fig. 16.4 in Deitel et al. --> <xsl:stylesheet version = "1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match = "myMessage"> <!-- Add a Cocoon instruction to format the result as WML: --> <xsl:processing-instruction name = "cocoon-format">type = "text/wml" </xsl:processing-instruction> … Notes 7: Apache Cocoon

  8. Style sheet welcome-wml.xsl (2) <wml><card> <p><xsl:value-of select="message"/></p> <p>This page has been transformed from XML into WML by Cocoon's XSLT processor. </p> </card> </wml> </xsl:template> <!-- for 'myMessage' --> </xsl:stylesheet> Notes 7: Apache Cocoon

  9. Cocoon 2 Pipeline • Pipeline: sequence of component interactions to process a request • typical case: Notes 7: Apache Cocoon

  10. 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) • … Notes 7: Apache Cocoon

  11. 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) Notes 7: Apache Cocoon

  12. Selecting a Pipeline Notes 7: Apache Cocoon

  13. Declaring Pipelines <!-- Fragment of sitemap.xmap: --> <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"><map:components> … </map:components> <!-- Select pipeline based on request URI: --> <map:match pattern="hello.html"> <map:generate src="docs/hello-page.xml" /> <map:transform src="style/simpl2html.xsl"/> <map:serialize type="html" /> </map:match> … </map:sitemap> Notes 7: Apache Cocoon

  14. Setting up a pipeline Notes 7: Apache Cocoon

  15. 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 Notes 7: Apache Cocoon

  16. XSP: Embedding code into pages • Example (time.xsp); Display the time of day: <xsp:page language="java" xmlns:xsp="http://www.apache.org/xsp"> <xsp:logic>//Variable for the time of day: Date now = new Date(); </xsp:logic> <!-- root of resulting document: --> <page title="Time of Day"> <p>It’s now<xsp:expr>now</xsp:expr></p> </page> </xsp:page> • XSP processor generates a Generator ... Notes 7: Apache Cocoon

  17. 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(); } Notes 7: Apache Cocoon

  18. XSP to Generated Content to Result Notes 7: Apache Cocoon

  19. Example Result • Final HTML page could be: <html> <head><title>Time of Day</title></head> <body> <h3 style="color: navy; text-align: center">Time of Day</h3> <p>It's now Thu Dec 23 20:11:18 PST 1999</p> </body> </html> • OK, but can also separate logic from content (See next) Notes 7: Apache Cocoon

  20. Library Tags • Could replace the preceding with a library tag: ...<p>It's now <util:date format="…"/></p> ... • 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 Notes 7: Apache Cocoon

  21. Implementation of Tag Libraries • Tag library implemented by a logic sheet • XSLT stylesheet translating XSP -> XSP • registered in configuration file cocoon.xconf <util:date format="yy/MM/dd hh:mm:ss aa" /> could be implemented by template <xsl:template match="util:date" > <xsp:expr> formatDate(new Date(), "<xsl:value-of select='@format' />"); </xsp:expr> </xsl:template> Notes 7: Apache Cocoon

  22. Using Tag Libraries Notes 7: Apache Cocoon

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

  24. ESQL: Example (1/2) <?xml version="1.0" ?> <xsp:page language="java" xmlns:xsp="http://www.apache.org/xsp" xmlns:esql="http://apache.org/cocoon/SQL/v2"> <esql:connection> <esql:pool>connectionName</esql:pool> <esql:execute-query> <esql:query> SELECT name, addr FROM Emp </esql:query> … Notes 7: Apache Cocoon

  25. ESQL: Example (2/2) <esql:results> <table><esql:row-results> <tr><td><esql:get-string column="name"/></td> <td><esql:get-string column="addr"/></td> </tr></esql:row-results> </table> </esql:results> <esql:no-results> <p>Sorry, no results!</p> </esql:no-results> </esql:execute-query> </esql:connection> </xsp:page> Notes 7: Apache Cocoon

  26. 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" Notes 7: Apache Cocoon

  27. 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?) Notes 7: Apache Cocoon

More Related