NOTE: This module is no longer of any use. An extension to the RequestModule has been implemented; You can now use {request:sitemapURIPrefix}

This is an input module that determines the absolute URI to the base of the sitemap. It can help you to make your Cocoon application relocatable. The problem with this was described by Gianugo http://www.rabellino.it/blog/?p=68:

Always take relocability of your Cocoon application into account, from the very beginning of your project. Your application should work from the webapp root (mounted as /), under a context path (/whatever) or as a sub-sitemap (/whatever/the/user/wants). This means that you should always pass a "mount-point" attribute within your rendering pipelines and components, calculating where your application has been mounted, and building paths accordingly. Unfortunately the current Cocoon API will only tell you the full request path and the URI handled by the sitemap, so you need to mangle those data by substracting (string-wise) the sitemap URI from the request URI in order to obtain the path you're looking for. That is, if your sitemap is mounted on /context/foo and your request is for /context/foo/bar/baz, the sitemap URI will be bar/baz, while the data you need is actually /context/foo to build your links properly.

The SitemapURIModule takes care of the calculation mentioned in the quotation.

Thus, if you use {sitemap-uri:}, it will be substituted by /whatever/ or /whatever/the/user/wants/. You can append a relative URI within the sitemap, as in {sitemap-uri:you/like}, which gives /whatever/you/like.

The code for this input module is attached to this page (see 'attachments' under 'more actions').

Problems

This module does not work correctly if the sitemap-URI changes during the request. Such a change may occur because of a sitemap-redirection or a call to Flowscript. The cause for this problem is, that the SitemapURIModule computes the sitemap-base-URI by subtracting the sitemap-URI from the request-URI:

request-URI - sitemap-URI = sitemap-base-URI

For example, suppose that you have a sitemap mounted at "/a/b/", and the request-URI is "/a/b/c/d", you get

"/a/b/c/d" - "c/d" = "/a/b/"

If the pipeline redirects "c/d" to "e",

<map:match pattern="c/d">
<map:redirect-to uri="e"/>
</map:match>

the sitemap-URI changes to "e". In this case, the base-sitemap-URI cannot be computed:

"/a/b/c/d" - "e" = ???

As far as I can see, this is not easily solved in the input module itself. However, the sitemap-base-URI is available internally in the Environment of the Request, through the getURIPrefix() method. This could be accessed through the RequestModule.

  • No labels