Friday, June 11, 2004

Why I love Java: somethings are so easy to do...

I am working on a GPLed web-based knowledge management system, and this morning I wanted to add an administrative task: downloading all data (about users, projects, etc., but not the actual content being managed: Word, OpenOffice, PDF, etc. documents) for backup purposes.

I can't believe how easy it was to write (back to the user's PC) a zip output stream containing compressed XML files (one XML file per business class):

1. I used Brendan Macmillan's utility to write plain old Java objects to an XML stream. I wrapped this in class ArchiveToXml to save all business data objects
2. In a JSP page, I added 3 lines:

response.setHeader("Content-disposition", "attachment; filename=\"alldata.xml\"");
new ArchiveToXml().saveData(response.getOutputStream());

Something that I thought might take a few hours, took 30 minutes - love it!

No comments: