// this is the object used to render forms from their definitions
screens.getContext().put("formStringRenderer", new FoFormRenderer(request, response));
screens.render(page);
} catch (Throwable t) {
throw new ViewHandlerException("Problems with the response writer/output stream", t);
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
TransformerFactory transFactory = TransformerFactory.newInstance();
try {
Fop fop = fopFactory.newFop(contentType, out);
Transformer transformer = transFactory.newTransformer();
// set the input source (XSL-FO) and generate the output stream of contentType
Reader reader = new StringReader(writer.toString());
Source src = new StreamSource(reader);
/*
try {
String buf = writer.toString();
java.io.FileWriter fw = new java.io.FileWriter(new java.io.File("/tmp/xslfo.out"));
fw.write(buf.toString());
fw.close();
} catch (IOException e) {
throw new ViewHandlerException("Unable write to browser OutputStream", e);
}
*/
// Get handler that is used in the generation process
Result res = new SAXResult(fop.getDefaultHandler());
try {
// Transform the FOP XML source
transformer.transform(src, res);
// We don't want to cache the images that get loaded by the FOP engine
fopFactory.getImageFactory().clearCaches();
// set the content type and length
response.setContentType(contentType);
response.setContentLength(out.size());
// write to the browser
try {
out.writeTo(response.getOutputStream());
response.getOutputStream().flush();
} catch (IOException e) {
throw new ViewHandlerException("Unable write to browser OutputStream", e);
}
} catch (TransformerException e) {
Debug.logError("FOP transform failed:" + e, module );
throw new ViewHandlerException("Unable to transform FO to " + contentType, e);
}
} catch (TransformerConfigurationException e) {
Debug.logError("FOP TransformerConfiguration Exception " + e, module);
throw new ViewHandlerException("Transformer Configuration Error", e);
} catch (FOPException e) {
Debug.logError("FOP Exception " + e, module);
throw new ViewHandlerException("FOP Error", e);
} finally {
try {
out.close();
} catch (IOException e) {
Debug.logError("Unable to close output stream " + e, module);