Basic Components of cocoon

Source: Internet
Author: User
Tags xsl file xslt
ArticleDirectory
    • Exsp
    • Code Generator (xsp processing)
    • Several xsp Architectures
    • Sitemap
    • Matchers
    • Generators
    • Transformers (converter)
    • Serializers
    • Pipeline Processing
    • Logicsheets
    • Apache cocoon configuration (cocoon configuration)
Cocoon basic component exsp
<? XML version = "1.0" encoding = "ISO-8859-1"?> <Xsp: Page Language = "Java" xmlns: xsp = "http://apache.org/xsp"> <xsp: logic> static private int counter = 0; private synchronized int count () {return counter ++ ;}</xsp: logic> <page> <p> I have been requested <xsp: expr> count () </xsp: expr> times. </P> </Page> </xsp: Page> exsp is an XML file that meets the following requirements:. the root of the document must be <xsp: Page> B. you must have a language statement in <xsp: Page> C. <xsp: Page> The namespace attribute D must exist. if an xsp needs to have some practical functions, it must contain the <xsp: logic> <xsp: expr>
Code Generator (xsp processing)
Package org.apache.cocoon.www.doc S. samples. xsp; import Java. io. file; // a bunch of other imports public class counter_xsp extends xspgenerator {//.. bookkeeping stuff commented out. /* User class declarations */static private int counter = 0; private synchronized int count () {return counter ++;}/* generate XML data. */Public void generate () throws saxexception {This. contenthandler. startdocument (); attributesimpl xspattr = new attributesimpl (); this. contenthandler. startprefixmapping ("xsp", "http://apache.org/xsp"); this. contenthandler. startelement ("", "page", "page", xspattr); // statements to build the XML document (Omitted) This. contenthandler. endelement ("", "page", "page"); this. contenthandler. endprefixmapping ("xsp"); this. contenthandler. enddocument ();} Here is the converter that converts xsp to an XML file.
Embeded Logic
A.CodePut them in a file B. The content and logic are not separated C. Suitable for small projects, not suitable for large projects


Included logicsheet

 
A. Code is stored in a separate XSL file B. Separation of content and logic c. Better implementation of xsp


Logicsheet as tag Library

 
A. logicsheet is packaged and registered to cocoon. in xconf, B is reused. the tag library has a namespace. You can reference C. the separation of content, logic, and management is optimal.


Sitemap

<? XML version = "1.0"?> <Map: sitemap xmlns: Map = "http://apache.org/cocoon/sitemap/1.0"> <map: Components>... </map: Components> <map: Views>... </map: Views> <map: pipelines> <map: Pipeline> <map: Match>... </map: Match>... </map: Pipeline>... </map: pipelines>... </map: sitemap> sitemap contains the following content: * List of matchers * List of generators * List of transformers * List of readers * List of serializers * List of selectors * List of processing pipelines with match patterns *...
Matchers
Matcher matches URI information according to certain rules, two matcher * wildcard matcher * Regexp matchersitemap entries for different types of matchers are available for distributing * requests * to different processing Pipelines Based on matching results. <map: matchers default = "wildcard"> <map: matcher name = "wildcard" factory = "org. apache. cocoon. matching. wildcardurimatcher "/> <map: matcher name =" Regexp "factory =" org. apache. cocoon. matching. regexpurimatcher "/> </map: matchers> pipeline entries in sitemap file <map: Match pattern =" JSP/* "> <map: generate type = "jsp" src = "/docs/samples/JSP/{1 }. JSP "/>... </map: Match> <map: Match pattern = "hellotern"> </map: Match
Generators
The purpose of the generator is to specify different input content (file, directory, stream, and so on) the XML document is generated using the following generators: * file Generator * directory Generator * xsp Generator * JSP Generator * request Generator *... sitemap entries for different types of generators <map: generators default = "file"> <map: generator name = "file" src = "org. apache. cocoon. generation. filegenerator "label =" content "/> <map: generator name =" directory "src =" org. apache. cocoon. generation. directorygenerator "label =" content "/> <map: generator name =" serverpages "src =" org. apache. cocoon. generation. serverpagesgenerator "label =" content "/> <map: generator name =" request "src =" org. apache. cocoon. generation. requestgenerator "/>... </map: generators> A sample generator entries in a pipeline <map: Match pattern = "hello.html"> <map: generate src = "docs/samples/hello-page.xml"/> <map: Transform src = "stylesheets/page/simple-page2html.xsl"/> <map: serialize type = "html"/> </map: Match>
Transformers (converter)
 
The function of the converter is to convert the XML document format into another document format. The following types of converters are available: * XSLT transformer * log transformer * SQL transformer * i18n transformer *... sitemap entries for different types of transformers <map: transformers default = "XSLT"> <map: transformer name = "XSLT" src = "org. apache. cocoon. transformation. traxtransformer "> <use-request-parameters> false </use-request-parameters> <use-browser-capabilities-DB> false </use-browser-capabilities-DB> </map: transformer> <map: transformer name = "log" src = "org. apache. cocoon. transformation. logtransformer "/>... </map: transformers> A sample transformer entry in a pipeline <map: Match pattern = "hello.html"> <map: generate src = "docs/samples/hello-page.xml"/> <map: Transform src = "stylesheets/page/simple-page2html.xsl"/> <map: serialize type = "html"/> </map: Match>
Serializers
To convert the XML file format to other formats (such as HTML, XML, PDF, etc.), there are the following types of converters: * HTML serializer * fop serializer * Text serializer * XML serializer *... sitemap entries for different types of serializers <map: serializers default = "html"> <map: serializer name = "XML" mime-type = "text/XML" src = "org. apache. cocoon. serialization. xmlserializer "/> <map: serializer name =" html "mime-type =" text/html "src =" org. apache. cocoon. serialization. htmlserializer "/> <map: serializer name =" fo2pdf "mime-type =" application/pdf "src =" org. apache. cocoon. serialization. fopserializer "/> <map: serializer name =" Fig "mime-type =" model/fig "src =" org. apache. cocoon. serialization. textserializer "/>... </map: serializers> A sample serializer entry in a pipeline <map: Match pattern = "hello.html"> <map: generate src = "docs/samples/hello-page.xml"/> <map: Transform src = "stylesheets/page/simple-page2html.xsl"/> <map: serialize type = "html"/> </map: Match>
Pipeline Processing
 
Haha, the core part. The above components are combined, and the pipeline operation is configured by sitemap_xmap.java, which is generated by the sitemap. xmap file.


Logicsheets

Logicsheet is an XSL file with a corresponding namespace. Haha, very interesting. This is the main way to add logical processing to xsp. Of course, this also needs to be registered in cocoon. xconf before using logicsheet is used by generator to generate Program Before conversion. Cocoon comes with the following types of logicsheet * requests. XSL * response. XSL * session. XSL * cookie. XSL * esql. XSL * log. XSL *... log. XSL structure <XSL: stylesheet version = "1.0" xmlns: xsp = "http://apache.org/xsp" xmlns: log = "http://apache.org/xsp/log" xmlns: XSL = "http://www.w3.org/1999/XSL/Transform"> <XSL: template match = "log: logger">... variable and xsp: logic statements... </XSL: Template> <XSL: template match = "log: Debug"> <xsp: Logic> If (getlogger ()! = NULL) getlogger (). debug ("<XSL: value-of select = ". "/>"); </xsp: logic> </XSL: Template> <XSL: template match = "log: error">... </XSL: Template> </XSL: stylesheet> A sample use <xsp: Page Language = "Java" xmlns: xsp = "http://apache.org/xsp" xmlns: log = "http://apache.org/xsp/log"> <page> <log: logger name = "test" filename = "test. log "/> <log: Debug> Test message </log: Debug> </Page> </xsp: Page>
Apache cocoon configuration (cocoon configuration)
 
Cocoon height configurable. Here we assume that our program is released to Tomcat. * Sitemap. xmap: Apparently, the main configuration file * cocoon. xconf: Register logicsheet and configure sitemap. xmap and other configuration files * web. XML: servlet configuration file, specifying cocoon. location of the xconf file and log * cocoon. roles: used to configure the core components of cocoon. If you want to customize cocoon, You need to modify it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.