主题:response.encodeURL
cifeng
[专家分:0] 发布于 2007-09-21 14:26:00
有没有人能够告诉我response.encodeURL的具体功能,还有用法
看了一些介绍,感觉不是很详细
回复列表 (共1个回复)
沙发
yiyi735 [专家分:680] 发布于 2007-09-26 10:21:00
The encodeURL transformer emits encoded URLs. This transformer applies encodeURL method to URLs. You may want to use this transform to avoid doing the manually encodeURL() call.
Usually this transformer is appended as last transformer before the serialization process. In this case it is possible to encode URLs introduced in the generator, and xslt transformer phase.
You can specify which attributes hold URL values in order to restrict URL rewriting to specific attributes only. In the current implementation you specify include, and exclude patterns as regular expressions, concatting element-name + "/@" + attribute-name.
The EncodeURLTransformer has serveral configuration options. These options may be specified in the sitemap, or by each request.
include-name -
RE pattern for including attributes from encode URL rewriting, The attribute values are encoded, if an expressions of the form element-name/@attribute-name matches.
By default include-name is defined as .*/@href|.*/@action|frame/@src.
exclude-name -
RE pattern for excluding attributes from encode URL rewriting, The attribute values are not encoded, if an expressions of the form element-name/@attribute-name matches.
By default exclude-name is defined as img/@src.
* Name : encodeURL
* Class: org.apache.cocoon.transformation.EncodeURLTransformer
* Cacheable: yes.
A simple example might help to use the EncodeURLTransformer effectivly:
Add the EncodeURLTransformer to the components in your sitemap.xmap
...
<map:components>
...
<map:transformers default="xslt">
...
<map:transformer name="encodeURL"
src="org.apache.cocoon.transformation.EncodeURLTransformer">
<!-- default configuration, explicitly defined -->
<include-name>.*/@href|.*/@action|frame/@src</include-name>
<exclude-name>img/@src</exclude-name>
</map:transformer>
...
Next define in your pipeline to use the EncodeURLTransformer
<map:match pattern="*.xsp">
<map:generate type="serverpages" name="docs/samples/xsp/{1}.xsp"/>
<map:transform src="stylesheets/page/simple-page2html.xsl"/>
<map:transform type="encodeURL"/>
<map:serialize/>
</map:match>
In this example pipeline it is assumed that the attribute href of element a contains an URL which should get encoded. Moreover the attribute action of any element contains an URL which should get encoded, too. Finally the attribute src of element frame should get encoded, too.
The attribute src of element img is excluded from encoding.
In other words, images are served regardless of the current session, in contrast anchor links, form actions, and frame src are served depending on the current session.
The encoding itself applies the servlet method response.encodeURL() upon the URL.
我来回复