Tuesday, 13 April 2004
Rapid prototyping blojsom plugins using Groovy
blojsom already has a GroovyDispatcher which uses their template engine to allow you to develop templates using Groovy. So, what about plugins? Mark mentioned the idea for a GroovyPlugin a few weeks back and here's the relevant code for such a plugin.
<The-How-do-you-say-Ah-yes-Show-with-Antonio-Banderas>
Oh no! It's too sexy!
</The-How-do-you-say-Ah-yes-Show-with-Antonio-Banderas>
...
Class clazz = groovyClassLoader.parseClass(groovyPlugin);
plugin = (BlojsomPlugin) clazz.newInstance();
plugin.init(_servletConfig, _blojsomConfiguration);
entries = plugin.process(httpServletRequest, httpServletResponse, user, context, entries);
plugin.cleanup();
plugin.destroy();
...
This would allow rapid prototyping of blojsom plugins without having to go through the "pains" of recompilation or restarting your application server. That's kind of neat in and of itself.
And then I got to thinking, "What if I wanted to include the Groovy plugin more than once in my plugin chain and have it execute different scripts?" One way I thought of doing that would be to accept a comma-separated URL parameter, say "groovy-plugin-scripts=script1,script2". In the individual user's plugin.properties file, you might have the following:
html.blojsom-plugin-chain=...,groovy-plugin,...,groovy-plugin,...
Each time the Groovy plugin was executed, increment a counter placed in the context and execute the 1st script for the 1st execution, execute the 2nd script for the 2nd execution, and so on. Got all that?
Grooooooooooooooovy baby Oh no! It's too sexy!
</The-How-do-you-say-Ah-yes-Show-with-Antonio-Banderas>
Posted by at 2:35 PM in blojsom ... all blojsom
