Cocoon的sitemap详解

Sitemap特点

   1. minimal verbosity is of maximum importance.
   2. the schema should be sufficiently expressive to allow learning by examples.
   3. sitemap authoring should not require assistive tools, but be sufficiently 
      future-compatible to allow them.
   4. sitemaps must scale along with the site and should not impose growth limitation 
      to the site as a whole nor limit its administration with size increase.
   5. sitemaps should contain all the information required to Cocoon to generate all
      the requests it receives.
   6. sitemaps should contain information for both dynamic operation as well as offline generation.
   7. uri mapping should be powerful enough to allow every possible mapping need.
   8. basic web-serving functionalities (redirection, error pages, resource authorisation)
      should be provided.
   9. sitemaps should not limit Cocoon's intrinsic modular extensibility.
  10. resources must be matched with all possible state variables, not only with URI
      (http parameters, environment variables, server parameters, time, etc...).
  11. sitemaps should embed the notion of "semantic resources" to be future-compatible 
      with semantic crawling and indexing.
  12. sitemaps should be flexible enough to allow a complete web site to be built with Cocoon.

Sitemap的Structor

<?xml version="1.0"?>
  <map:sitemap 
      xmlns:map="http://apache.org/cocoon/sitemap/1.0">
    <map:components/>
    <map:views/>
    <map:resources/>
    <map:action-sets/>
    <map:pipelines/>
  </map:sitemap> 

下面我们来详细的分析Sitemap的各个部分

<map:sitemap 
    xmlns:map="http://apache.org/cocoon/sitemap/1.0"> 
这个没什么好说的,标准格式。不要修改

map:component部分

 
 <map:components>
    <map:generators/>
    <map:transformers/>
    <map:serializers/>
    <map:readers/>
    <map:selectors/>
    <map:matchers/>
    <map:actions/>
    <map:pipes/>
  </map:components>
每个Component都有一些共同的属性
name:这个component的标识名,用来在pipeline里面引用该component
src:实现这个component的class文件名

每个Component也都有参数可以设置,例如
<map:components>
  <map:transformer name="xslt"
     src="org.apache.cocoon.transformation.TraxTransformer">
     <!-- This is a parameter to the transformer component -->
     <use-request-parameters>false</use-request-parameters>
  </map:transformer>
</map:components> 
不同的Component可以设置不同的参数。

Generators属性设置(将xml转化成为SAX事件,同时初始化pipeline处理机制)
<map:generators default="file">
  <map:generator name="file"
    src="org.apache.cocoon.generation.FileGenerator"/>
  <map:generator name="dir"
    src="MyDirGenerator"/>
  <map:generator name="serverpages"
    src="org.apache.cocoon.generation.ServerPagesGenerator">
   ...
  </map:generator>
</map:generators> 
这里面的default就是用来在pipeline里面如果不指定generator的时候自动调用file这种Component.

Transformer属性设置(Transformer就是用来将SAX事件转化成为另外一种SAX事件)
<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="xinclude" 
  src="org.apache.cocoon.transformation.XIncludeTransformer"/>
</map:transformers> 

Serializers设置(Serializers将SAX事件转化成为binary或char Stream)
<map:serializers default="html">
  <map:serializer name="html" mime-type="text/html" 
         src="org.apache.cocoon.serialization.HTMLSerializer">
    <doctype-public>-//W3C//DTD HTML 4.0 Transitional//EN
      </doctype-public>
    <doctype-system>http://www.w3.org/TR/REC-html40/loose.dtd
      </doctype-system>
    <omit-xml-declaration>true</omit-xml-declaration>
    <encoding>UTF-8</encoding>
    <indent>1</indent>
  </map:serializer>

  <map:serializer name="wap" mime-type="text/vnd.wap.wml" 
         src="org.apache.cocoon.serialization.XMLSerializer">
    <doctype-public>-//WAPFORUM//DTD WML 1.1//EN
      </doctype-public>
    <doctype-system>http://www.wapforum.org/DTD/wml_1.1.xml
      </doctype-system>
    <encoding>UTF-8</encoding>
  </map:serializer>

  <map:serializer name="svg2jpeg" mime-type="image/jpeg" 
         src="org.apache.cocoon.serialization.SVGSerializer">
    <parameter name="background_color" 
               type="color" value="#00FF00"/>
  </map:serializer>

  <map:serializer name="svg2png" mime-type="image/png" 
          src="org.apache.cocoon.serialization.SVGSerializer">
  </map:serializer>
</map:serializers>

Selectors设置(用来在sitemap里面实现简单的逻辑选择,例如if-then-else)
<map:selectors default="browser">
  <map:selector name="load"
      src="org.apache.cocoon.selection.MachineLoadSelector">
   ...
  </map:selector>

  <map:selector name="user"
    src="org.apache.cocoon.selection.AuthenticationSelector">
   ...
  </map:selector>

  <map:selector name="browser" 
           src="org.apache.cocoon.selection.BrowserSelector">
    <browser name="explorer" useragent="MSIE"/>
    <browser name="lynx" useragent="Lynx"/>
    <browser name="mozilla5" useragent="Mozilla/5"/>
    <browser name="mozilla5" useragent="Netscape6/"/>
    <browser name="netscape" useragent="Mozilla"/>
   ...
  </map:selection>
</map:selection>  

Matchers设置(Matcher将pattern映射到resource,也就是实现选择功能)
<map:matchers default="wildcard">
  <map:matcher name="wildcard" 
          src="org.apache.cocoon.matching.WildcardURIMatcher">
   ...
  </map:matcher>

  <map:matcher name="regexp" 
          src="org.apache.cocoon.matching.RegexpURIMatcher">
   ...
  </map:matcher>
</map:matchers> 

Actions设置(Action是用来运行时参数的,也就是request过来的参数)
她的表现形式为name/value对
<map:actions>
  <map:action name="add-employee"
          src="org.apache.cocoon.acting.DatabaseAddAction"/>
  <map:action name="locale"
          src="org.apache.cocoon.acting.LocaleAction"/>
  <map:action name="request"
          src="org.apache.cocoon.acting.RequestParamAction"/>
  <map:action name="form-validator"
          src="org.apache.cocoon.acting.FormValidatorAction"/>
</map:actions> 

map:views定义

 view是用来定义站点不同的表现形式的。她与pipeline无关,同时可以被sitemap里面的所有的pipeline使用
<map:views>
  <map:view name="content" from-label="content">
    <map:serialize type="xml"/>
  </map:view>

  <map:view name="links" from-position="last">
    <map:serialize type="links"/>
  </map:view>
</map:views>
这个定义没有搞明白,也许还需要到view这个部分去了解。RR

map:resources设置

 这里面可以定义被重复使用的东东,用于pipeline的复用。
<map:resources>
  <map:resource name="Access refused">
    <map:generate src="./error-pages/restricted.xml"/>
    <map:transform src="./stylesheets/general-browser.xsl"/>
    <map:serialize status-code="401"/>
  </map:resource>
</map:resources> 

map:action-sets设置

用于将action组织起来使用。
<map:action-sets>
  <map:action-set name="employee">
   <map:act type="add-employee" action="Add"/>
   <map:act type="del-employee" action="Delete"/>
   <map:act type="upd-employee" action="Update"/>
   <map:act type="sel-employee" action="Select"/>
  </map:action-set>
</map:action-sets> 

Pipeline详解

    Cocoon依赖于Pipeline这个模型:一个xml文件通过管道,经过几个流程的处理,然后输出。
这个就是我们使用Cocoon时候的基本流程。
    一个Pipeline一般由一个generator开始,跟着0到n个transformer,然后以serializer结束。
当然了,这中间还可能会有pipeline的错误处理。
    除了使用各种部件以外,你还可以以matcher或selector来选择某个特定的pipeline.
Aggregation允许你将几个Pipeline合并起来一起使用。
views定义pipeline的退出点
元素 作用
map:match 根据matching选择pipeline
map:select, map:when, map:otherwise 根据selector选择pipeline
map:mount 装载一个下属sitemap
map:redirect-to 重定向到另外一个uri
map:call 调用另外一个pipeline处理
map:parameter 定义不同的参数
map:act 调用action处理
map:generate 调用Generator处理
map:aggregate, map:part 将几个pipeline聚合起来使用
map:transform 定义Transformer处理
map:serialize 定义序列化处理器
map:handle-errors 定义错误处理方法

posted on 2004-09-15 22:29  笨笨  阅读(813)  评论(0编辑  收藏  举报

导航