X

Geertjan's Blog

  • November 6, 2007

Groovy Template (Part 2)

Geertjan Wielenga
Product Manager
In Groovy Template (Part 1), I showed a simple yet powerful Groovy script (one that I need to use in real life). However, being able to run Groovy is nice, but better is if you have some user interface on top of the Groovy script. Or, in fact, on top of the compiled Java class because, in fact, that's what my Groovy script has become, thanks to the groovyc Ant task that I ran in the IDE. I also ran a target for Groovydoc. Then I built my application and now I have the Groovydoc in the JAR file (since its not much and this makes it easy to distribute), together with the compiled Java (as well as the Groovy script itself, why not, maybe the end user will enjoy looking at the sources):

Now, in the role of client of my own JAR file, I have a user interface on top of the JAR:

It is not completely complete. Ultimately, one would select a properties file. The properties file would have key/value combinations like this:

copyright=Copyright 1997, FooBla Co. Ltd
author=Mr. Foo Bla

And then each HTML file would include ${copyright} and ${author} at the relevant points in the document. So then, you would use the GUI above to select a folder containing one's HTML files, and the properties file defined as above, and then... when OK is clicked, the Java class (created from Groovy, remember?) in the JAR is called to create new HTML files from the existing ones (with "new" prepended) and with the keys replaced by the values.
So, that's the place of Groovy in the whole picture. Really quite minor, in some ways. In other ways, it's the key to the whole puzzle. Groovy is the engine behind this whole structure. On the other hand, at the same time, it is nothing more than, to use a phrase that is becoming slightly overused... "an implementation detail of my Java API".

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.