cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andreas Hartmann <>
Subject Interest in link rewriting transformer?
Date Wed, 26 Aug 2009 12:17:19 GMT
Hi Cocoon devs,

Lenya contains an AbstractLinkTransformer for link rewriting purposes. 
I'm using it for other Cocoon projects too.

To be able to rewrite links in arbitrary XML formats, the transformer is 
configured with a set of attribute configurations which can contain 
links. Here's an example how you would configure your custom transformer 
to rewrite links in XHTML streams:

<map:transformer name="links-xhtml"

   <transform namespace="" element="a" 
   <transform namespace="" element="object" 
   <transform namespace="" element="img" 
   <transform namespace="" element="link" 
   <transform namespace="" element="form" 
   <transform namespace="" element="script" 
   <transform namespace="" element="input" 
   <transform namespace="" element="input" 


The AbstractLinkTransformer subclass must provide a link rewriter object 
implementing the LinkRewriter interface. Usually the LinkRewriter 
matches a particular protocol, extension or other parts of the URI.

public interface LinkRewriter {

      * @param url The URL.
      * @return If this rewriter feels responsible for the URL.
     boolean matches(String url);

      * @param url The original URL.
      * @return The rewritten URL or <code>null</code> if the URL could 
not be rewritten (i.e., the link is broken).
     String rewrite(String url);


IMO the link rewriting transformer is quite useful and generic enough to 
be used for various purposes, so it would probably make sense to move it 
from Lenya to Cocoon. In my experience it makes life much easier to use 
specific link protocols (e.g., internal:/) and have a single link 
rewriting step at the end of the page processing pipeline(s). The module 
also contains a ChainLinkRewriter to apply multiple rewriting steps in a 
single SAX transformation.

If anyone is interested, I could commit a Cocoon 2.2 block to the 
whiteboard. The JAR will be compatible with Cocoon 2.1.x too.

-- Andreas

Andreas Hartmann, CTO
BeCompany GmbH
Tel.: +41 (0) 43 818 57 01

View raw message