A document has been updated: http://cocoon.zones.apache.org/daisy/documentation/1488.html
Document ID: 1488 Branch: main Language: default Name: ServletLinkrewriteTransformer (unchanged) Document Type: Sitemap Component (unchanged) Updated on: 8/17/08 2:59:00 PM Updated by: Lukas Lang A new version has been created, state: draft Parts ===== Short description ----------------- This part has been updated. Mime type: text/xml (unchanged) File name: (unchanged) Size: 273 bytes (previous version: 278 bytes) Content diff: (2 equal lines skipped) <p>ServletLinkrewriteTransformer can be used as a sitemap component to rewrite links, <br/> --- occuring in attributes of tags, which don't necessarily need to be HTML tags. --- <br/> +++ occuring in attributes of tags, which don't necessarily need to be HTML. <br/> As an example, links to style specific resources can be rewritten.</p> </body> (1 equal lines skipped) Long description ---------------- This part has been added. Mime type: text/xml File name: null Size: 3772 bytes Content: <html> <body> <h3>Example</h3> <p>In this example, we have two SitemapServlets defined as Spring beans:</p> <ul> <li>org.apache.cocoon.servletservice.sample.linkrewriter-content (mounted at: /cocoon-servlet-service-components-sample/linkrewriter-content)</li> <li>org.apache.cocoon.servletservice.sample.linkrewriter-style (mounted at: /cocoon-servlet-service-components-sample/linkrewriter-style)</li> </ul> <p>Assume, a HTML document, available via the content servlet, contains style specific information like an external cascading style sheet:</p> <pre><html> <head> <link rel="stylesheet" type="text/css" href="servlet:style:/skin.css" /> </head> <body> <h1>This heading should occur red</h1> <p>This is simple content</p> </body> </html></pre> <p>This document can not be served as it is, as servlets are only available internally. The <em>href </em>attribute of the <em>link </em>tag must first be resolved by the ServletLinkrewriteTransformer, as it referrs to a servlet URI. The link points to the servlet <em>style</em>, providing the <em>skin.css</em> file. Using the configuration provided at the bottom of the page, this link would be rewritten into:</p> <pre><link rel="stylesheet" type="text/css" href="/cocoon-servlet-service-components/linkrewriter-style/skin.css" /></pre> <p>By this, the resource is now available for clients. For more information, including the full sources of this example, see the Cocoon Service Servlet Components sample.</p> <h3>Configuration</h3> <p>The transformer is configured, using Spring's dependency injection mechanism. The XML tag attributes to be taken into account and the servlets to be rewritten must be specified. The Spring configuration file for this example would look like:</p> <pre><bean name="org.apache.cocoon.transformation.Transformer/servletLinkRewriter" class="org.apache.cocoon.servletservice.linkrewrite.ServletLinkrewriteTransformer"> <property name="inputModule" ref="org.apache.cocoon.components.modules.input.InputModule/servlet" /> <property name="rewriteAttributes"> <util:set set-class="java.util.HashSet"> <value>src</value> <value>ref</value> <value>href</value> </util:set> </property> <property name="rewriteServlets"> <util:set set-class="java.util.HashSet"> <value>style</value> </util:set> </property> </bean></pre> <p>At least, the following configuration details must be provided:</p> <ul> <li>an InputModule</li> <li>one attribute being taken into account</li> <li>one servlet name to be considered for rewriting</li> </ul> <p>As the ServletLinkrewriteTransformer processes the attributes of XML elements, the InputModule is asked to resolve the servlet URI, if all of the following conditions hold:</p> <ul> <li>the attribut is in the <em>rewriteAttributes </em>set</li> <li>the value of the attribute is a servlet URI. e.g. <em>servlet:</em></li> <li>referenced servlet is in the <em>rewriteServlets </em>set</li> </ul> <h3>Additional information</h3> <p>Please keep in mind, LinkrewriteTransformer is capable to rewrite transitive links. It is a matter of the referenced servlet to resolve the specified resource. Saying, the <em>style </em>servlet has an additional servlet connection to an <em>endpoint </em>servlet and uses the following sitemap (excerpt only):</p> <pre><map:pipelines> <map:pipeline> <map:match pattern="skin.css"> <map:read src="servlet:endpoint:/{0}"/> </map:match> </map:pipeline> </map:pipelines></pre> </body> </html>