One of the ‘new’ features that was requested in our app was the forwarding of screens to email addresses. We discussed this and adding a simple pdf version of the screen as attachment to the mail was ok.
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
output = writer.toString()
This small piece of code will generate the following Xml:
As I installed the Groovy plugin in Eclipse I get errors when my Xml is false. Not bad at all.
The really nice thing about this is that you just initialize your Groovy engine in Java. You add your Java object (in my example blog) and you can use it as if it was a Groovy object. Then I return the output to my Java code.
As this generates Xml I used a simple Xsl stylesheet to generate an intermediate Xml. So all objects get transformed into this intermediate Xml. This xml gets transformed in to FOP xml and with the nice Apache FOP library I generate a simple pdf.
Another added value is that for changing my pdf or Xml I don’t have to restart my application, so no downtime!!