wissel.net

Usability - Productivity - Business - The web - Singapore & Twins

Extracting data from Domino into PDF using XSLT and XSL:FO (Part 4)


This entry is part of the series Domino, XSL:FO and XSLT that dives into the use of XSLT and XSL:FO in IBM Lotus Domino.

So far we had a look at the all over process, some Java to convert FO into PDF and FO Basics. Time to get some Notes data exported. To make the task easier I created a little helper that allows convenient export into XML. Currently it works on a NotesDocument(Collection) basis, but it would be a small step to add a method that uses a view navigator for speed.
The most complete rendering of a NotesDocument is done using the .renderXML method. For a collection you use a NotesDxlExporter. Unfortunatelty both methods are comparable slow. So I added an alternate approach (works only if you don't have RichText for the moment) and export lean XML.
A Form2XMLDefinition class (optional) allows to pick which fields need to be picked in the XML file. It also allows to group those fields (more on that another time - or look at the source). So the methods are:
packagecom.notessensei.fop;

importjava.io.ByteArrayOutputStream;
importlotus.domino.DocumentCollection;
importlotus.domino.Session;

publicinterface Notes2XML {
    publicabstractvoid addForm (Form2XMLDefinition newForm );
    publicabstractByteArrayOutputStream renderDocument2DXL (lotus. domino. Document doc );
    publicabstractByteArrayOutputStream renderDocument2XML (lotus. domino. Document doc );
    publicabstractByteArrayOutputStream renderDocumentCollection2DXL (Session s, DocumentCollection dc );
    publicabstractByteArrayOutputStream renderDocumentCollection2XML (DocumentCollection dc, String rootName );
}
I expanded the PDFReport class with a convenience method: getNotesXMLExporter() to be able to reuse my managed bean (beginnings of a Facade pattern).To render all documents of a database these few lines in an XAgent are sufficient:
var exCon = facesContext. getExternalContext();
var response = exCon. getResponse();
var out = response. getOutputStream();
response. setContentType("application/pdf");
response. setHeader("Content-disposition","inline; filename=fruits.pdf");
response. setHeader("Cache-Control","no-cache");
var dc = database. getAllDocuments(); // <-- Here is your document selection!
var extractor = PDF. getNotesXMLExporter();
try{
    var raw = extractor. renderDocumentCollection2DXL(session ,dc );
   PDF. fopReportFromString(out ,raw. toString(),null);
}catch(e ){
    print(e. message);
}
facesContext. responseComplete();
out. close();
Since I don't provide a stylesheet the Default transformation I coded into the class kicks in and renders a simple table with name and values. In a production like application you need to provide a stylesheet and a document collection based on the user action - the later shouldn't be difficult, it is standard XPages development. For the former you might consider a FO editor to make your life easier, but that's a story for another time. Feel free to experiment with the sources and stay tuned.

Posted by on 28 April 2012 | Comments (1) | categories: Show-N-Tell Thursday XPages

Comments

  1. posted by Schlusi on Tuesday 15 January 2013 AD:
    The links for part 5 & 6 of the series are broken?