Using controller.xql to simplify resource linking, and other progress
In Cocoon, I've always used the sitemap to simplify the linking of resources, so that (for instance) you can ask for a .css file from anywhere in the site structure, without worrying about the actual relative path, and the system knows where to find it and serves it up. I've implemented the same thing in eXist 1.5 using controller.xql
. The code is below. The initial stanza, handling images, is slightly more complicated than the CSS and JS stanzas because there are subcollections inside /images/
.
[...] (: All images are to be served from the /site/images collection. :) else if (contains($currentUri, 'images/')) then <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> <forward url="{concat('/images/', substring-after($currentUri, 'images/'))}"/> </dispatch> (: All CSS files will live in /site/css, so find them there. :) else if (ends-with($currentUri, '.css')) then <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> <forward url="{concat('/css/', $exist:resource)}"/> </dispatch> (: All JS files will live in /site/js, so find them there. :) else if (ends-with($currentUri, '.js')) then <dispatch xmlns="http://exist.sourceforge.net/NS/exist"> <forward url="{concat('/js/', $exist:resource)}"/> </dispatch> [...]
Inside WEB-INF/controller-config.xml, I had to comment out this line, which is mysterious to me but which was sending requests for things in /images to I-know-not-where:
<!-- Comment out the following line or it will screw with images stored in your db. --> <forward pattern="/images" servlet="ScaleImageJAI"/>
I've also got the main webapp working, with nothing at all outside WEB-INF, so it's very clean and simple. I have an includes.xql module which handles the header, footer etc., and I'm now in a position to start figuring out how best to structure the app. I want to have proper .htm URLs if possible for every page that isn't a search, so I might use something like /pages/[filename].htm
for every [filename].xml
in the db. All of these can redirect to index.xql with an appropriate set of parameters, which would make things very simple.