`
sun_cat
  • 浏览: 72723 次
社区版块
存档分类
最新评论

cocoon sitemap 详解

    博客分类:
  • java
阅读更多

 

 

 

这个是sitemap 的总体结构

<!---->
  <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">
    [code]</map:sitemap>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"><?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> </map:sitemap>
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0">[/code]
    <map:views></map:views>
    <map:resources></map:resources>
    <map:action-sets></map:action-sets>
    <map:pipelines></map:pipelines>
  </map:sitemap> 
下面我们来详细的分析Sitemap的各个部分
<map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"> 
这个没什么好说的,标准格式。不要修改</map:sitemap>
 
map:components部分
它的总体机构如下 
 <map:components>
    <map:generators></map:generators>
    <map:transformers></map:transformers>
    <map:serializers></map:serializers>
    <map:readers></map:readers>
    <map:selectors></map:selectors>
    <map:matchers></map:matchers>
    <map:actions></map:actions>
    <map:pipes></map:pipes>
  </map:components>
每个Component都有一些共同的属性
name:这个component的标识名,用来在pipeline里面引用该component
src:实现这个component的class文件名

Generators属性设置(将xml转化成为SAX事件,同时初始化pipeline处理机制)
<map:generators default="file">
  <map:generator name="file"></map:generator>    src="org.apache.cocoon.generation.FileGenerator"/>
  <map:generator name="dir"></map:generator>    src="MyDirGenerator"/>
  <map:generator name="serverpages"></map:generator>    src="org.apache.cocoon.generation.ServerPagesGenerator">
   ...
  </map:generators>

这里面的default就是用来在pipeline里面如果不指定generator的时候自动调用file这种Component.
Transformer属性设置(Transformer就是用来将SAX事件转化成为另外一种SAX事件)
<map:transformers default="xslt">
  <map:transformer name="xslt"></map:transformer>      src="org.apache.cocoon.transformation.TraxTransformer">
    <use-request-parameters></use-request-parameters>false
    <use-browser-capabilities-db></use-browser-capabilities-db>false
       
  </map:transformers>
  <map:transformer name="xinclude"></map:transformer>  src="org.apache.cocoon.transformation.XIncludeTransformer"/>
Serializers设置(Serializers将SAX事件转化成为binary或char Stream)
<map:serializers default="html">
  <map:serializer name="html" mime-type="text/html"></map:serializer>         src="org.apache.cocoon.serialization.HTMLSerializer">
    <doctype-public></doctype-public>-//W3C//DTD HTML 4.0 Transitional//EN
     
    <doctype-system></doctype-system>http://www.w3.org/TR/REC-html40/loose.dtd
     
    <omit-xml-declaration></omit-xml-declaration>true
    <encoding></encoding>UTF-8
    <indent></indent>1
  </map:serializers>

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

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

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

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

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

  <map:selector name="browser"></map:selector>           src="org.apache.cocoon.selection.BrowserSelector">
    <browser name="explorer" useragent="MSIE"></browser>
    <browser name="lynx" useragent="Lynx"></browser>
    <browser name="mozilla5" useragent="Mozilla/5"></browser>
    <browser name="mozilla5" useragent="Netscape6/"></browser>
    <browser name="netscape" useragent="Mozilla"></browser>
   ...
 
 
Matchers设置(Matcher将pattern映射到resource,也就是实现选择功能)
<map:matchers default="wildcard">
  <map:matcher name="wildcard"></map:matcher>          src="org.apache.cocoon.matching.WildcardURIMatcher">
   ...
  </map:matchers>

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

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

  <map:view name="links" from-position="last">
    <map:serialize type="links"></map:serialize>
  </map:view>
</map:views>
这个定义没有搞明白,也许还需要到view这个部分去了解。
map:resources设置
这里面可以定义被重复使用的东东,用于pipeline的复用。
<map:resources>
  <map:resource name="Access refused">
    <map:generate src="./error-pages/restricted.xml"></map:generate>
    <map:transform src="./stylesheets/general-browser.xsl"></map:transform>
    <map:serialize status-code="401"></map:serialize>
  </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>
   <map:act type="del-employee" action="Delete"></map:act>
   <map:act type="upd-employee" action="Update"></map:act>
   <map:act type="sel-employee" action="Select"></map:act>
  </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定义错误处理方法



 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics