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
A
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:
package com.notessensei.fop ;
import java.io.ByteArrayOutputStream ;
import lotus.domino.DocumentCollection ;
import lotus.domino.Session ;
public interface Notes2XML {
public abstract void addForm (Form2XMLDefinition newForm ) ;
public abstract ByteArrayOutputStream renderDocument2DXL (lotus. domino. Document doc ) ;
public abstract ByteArrayOutputStream renderDocument2XML (lotus. domino. Document doc ) ;
public abstract ByteArrayOutputStream renderDocumentCollection2DXL (Session s, DocumentCollection dc ) ;
public abstract ByteArrayOutputStream renderDocumentCollection2XML (DocumentCollection dc, String rootName ) ;
}
I expanded the import java.io.ByteArrayOutputStream ;
import lotus.domino.DocumentCollection ;
import lotus.domino.Session ;
public interface Notes2XML {
public abstract void addForm (Form2XMLDefinition newForm ) ;
public abstract ByteArrayOutputStream renderDocument2DXL (lotus. domino. Document doc ) ;
public abstract ByteArrayOutputStream renderDocument2XML (lotus. domino. Document doc ) ;
public abstract ByteArrayOutputStream renderDocumentCollection2DXL (Session s, DocumentCollection dc ) ;
public abstract ByteArrayOutputStream renderDocumentCollection2XML (DocumentCollection dc, String rootName ) ;
}
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.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 ( ) ;
Posted by Stephan H Wissel on 28 April 2012 | Comments (1) | categories: Show-N-Tell Thursday XPages