From: Kal A. <ka...@te...> - 2004-09-28 08:37:55
|
On Tue, 2004-09-28 at 05:47, Conal Tuohy wrote: > It's only vaguely related to Kal's post, but I thought I'd mention: > > I haven't used the velocity templating engine, but I have used Cocoon to do templating. I've used Cocoon's JXTemplateGenerator, which is rather like XSLT with JXPath instead of XPath. JXPath gives you path-based access to Java object-graphs, e.g. x.getFoo().getBar() => "x/foo/bar". So this is similar to Velocity, and similarly I have templates associated with various topic map objects. > > I am keeping references to the individual JXTemplate files in the actual topic map, where they appear as occurrences of class topics. I had considered keeping a list of templates associated with different topics when I realised that this is what topic maps are for :-) I don't have a very sophisticated setup yet, but it does seem to me that referring to templates in the map itself is potentially a powerful technique. How does it work with the Velocity integration? Can you attach Velocity templates to particular classes of topics, for instance? > > That sounds interesting - I haven't got really deeply into Cocoon so JXPath just completely passed me by :) In terms of associating templates with classes of topics for the Velocity integration, currently that is done by an external (XML) configuration file. The format allows you to specify a topic by its subject indicator and then specify a template. You can scope the application of the template to apply to: 1) Just the specified topic 2) Any instance of the topic 3) Any subclass of the topic (2) respects the subclass-superclass hierarchy, and the code attempts to locate the closest class in the hierarchy. So if you have a template person.vm scoped for instances of a topic 'Person' and then have 'Man' and 'Woman' as subclasses, person.vm would be used to render instances of 'Person', 'Man' and 'Woman'. One thing that I have found really useful in the Velocity framework is the concept of the toolbox that contains utility classes that are initialised either per-app, per-session or per-request. It makes it quite easy to integrate helpers like the TologTool. Also I find it useful to have a simple Factory helper (because there doesn't seem to be a way to initialise new objects in Velocity's templating language) - when you combine this with Mango's functional classes you can make lots of reusable helper objects that make writing the templates quite easy. Does the Cocoon framework have similar helpers ? Cheers, Kal -- Kal Ahmed <ka...@te...> techquila |