| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> |
| <html> |
| <head> |
| <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <title>EncodeURL Transformer</title> |
| <link href="http://purl.org/DC/elements/1.0/" rel="schema.DC"> |
| <meta content="in @doctitle@" name="DC.Subject"> |
| <meta content="Bernhard Huber" name="DC.Creator"> |
| <meta content="This document describes the EncodeURL transformer." name="DC.Description"> |
| </head> |
| <body> |
| |
| <h1>EncodeURL Transformer</h1> |
| |
| <p> |
| 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. |
| </p> |
| |
| <p> |
| 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. |
| </p> |
| |
| <p> |
| You can specify which attributes hold URL values in order to restrict |
| URL rewriting to specific attributes and values only. In the current implementation |
| you specify include, and exclude patterns as regular expressions, concatting |
| element-name-regexp + "/@" + attribute-name-regexp [ + "=" + attribute-value-regexp ] |
| whereas the part in brackets [] are optional. |
| </p> |
| |
| <p> |
| The EncodeURLTransformer has several configuration options. These options |
| may be specified in the sitemap, or by each request. |
| </p> |
| |
| <dl> |
| |
| <dt>include-name</dt> |
| |
| <dd>RE pattern for including attributes for encode URL rewriting, |
| The attribute values are encoded, if an |
| expressions of the form |
| <span class="codefrag">element-name-regexp/@attribute-name-regexp[=attribute-value-regexp]</span> |
| matches. |
| <br> |
| By default <span class="codefrag">include-name</span> is defined as |
| <span class="codefrag">.*/@href|.*/@action|frame/@src</span>. |
| </dd> |
| |
| <dt>exclude-name</dt> |
| |
| <dd>RE pattern for excluding attributes from encode URL rewriting, |
| The attribute values are not encoded, if an |
| expressions of the form |
| <span class="codefrag">element-name-regexp/@attribute-name-regexp[=attribute-value-regexp]</span> |
| matches. |
| <br> |
| By default <span class="codefrag">exclude-name</span> is defined as |
| <span class="codefrag">img/@src</span>. |
| </dd> |
| |
| </dl> |
| |
| <ul> |
| |
| <li>Name : encodeURL</li> |
| |
| <li>Class: org.apache.cocoon.transformation.EncodeURLTransformer</li> |
| |
| <li>Cacheable: yes.</li> |
| |
| </ul> |
| |
| <p> |
| A simple example might help to use the EncodeURLTransformer effectivly: |
| </p> |
| |
| <p> |
| Add the EncodeURLTransformer to the components in your sitemap.xmap |
| </p> |
| |
| <pre class="code"> |
| ... |
| <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|(a/@href|iframe/@src)=.*adserver</exclude-name> |
| </map:transformer> |
| ... |
| </pre> |
| |
| <p> |
| Next define in your pipeline to use the EncodeURLTransformer |
| </p> |
| |
| <pre class="code"> |
| <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> |
| </pre> |
| |
| |
| <p> |
| In this example pipeline it is assumed that the attribute |
| <span class="codefrag">href</span> of element <span class="codefrag">a</span> contains an URL which should get |
| encoded. |
| Moreover the attribute <span class="codefrag">action</span> of any element contains an URL |
| which should get encoded, too. |
| Finally the attribute <span class="codefrag">src</span> of element |
| <span class="codefrag">frame</span> should get encoded, too. |
| </p> |
| |
| <p> |
| The attribute <span class="codefrag">src</span> of element <span class="codefrag">img</span> is excluded from |
| encoding. |
| </p> |
| |
| <p> |
| 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. |
| </p> |
| |
| <p> |
| The encoding itself applies the servlet method <span class="codefrag">response.encodeURL()</span> |
| upon the URL. |
| </p> |
| |
| |
| </body> |
| </html> |