Page title (cookbook approach, tutorial , ...)

  • TARGET-AUDIENCE: beginner *advanced* expert
  • DOCUMENT-STATUS: *draft* reviewed released

What you will get from this page

The ability to generate static Websites that are independent of their context. Due to this independence they can be run on a Servlet Engine (Tomcat/Jetty) in a context (i.e. http://<test-server>/<your-context>/first-level/index.html), as well as generated to the root of a website (i.e. http://your-web-server/first-level/index.html)

Your basic skills

Cocoon sitemap, CSS, Forrest Menu system, based on LinkRewriter

Technical prerequisites

Cocoon 2.1.4 or newer, LinkRewriter sytem like in the LinkRwriter example

Links to other information sources

The Issue

You want to address static resources like /resources/theme/main.css and /resources/images/logo.png in your website. However, you don't want to modify your main sitemap.xmap and route these absolute Request to the appropriate project sitemap (because I have more than one of these for different projects).

The solution(s) (I came up with)

First, use the LinkRewrite mechanism from Forrest and address these things using site:main.css and site:logo.png with
your site.xml file looking like this

<resources href="resources/">
	<images href="images/">
		<logo.png href="logo.png"/>
	<theme href="theme/">
		<main.css href="main.css"/>

If you want to add such references in the xslt transformations, then you need to make sure you make the LinkRewriting Transformation last.

This leaves resources in the CSS files like

.back_xxx {
	BACKGROUND-IMAGE: url(/resources/images/background.png);

out in the dark. The LinkRewriter does operate on attributes of xml elements. Therefore, I can't just transform my stylesheet with it. But stylesheets allow relative URLs (and interprets them relative to the stylesheet location). Now my stylesheet looks like this

.back_xxx {
	BACKGROUND-IMAGE: url(../images/background.png);

This is acceptable, because the stylesheet is itself a single (static)resource.

Comments are welcome!

page metadata

  • No labels