DOMResult domres = new DOMResult();
ElementListCollector elCollector = new ElementListCollector();
ElementListObserver.addObserver(elCollector);
Fop fop;
try {
Document testDoc = env.loadTestCase(testFile);
FopFactory effFactory = env.getFopFactory(testDoc);
//Setup Transformer to convert the testcase XML to XSL-FO
Transformer transformer = env.getTestcase2FOStylesheet().newTransformer();
Source src = new DOMSource(testDoc);
//Setup Transformer to convert the area tree to a DOM
TransformerHandler athandler;
athandler = env.getTransformerFactory().newTransformerHandler();
athandler.setResult(domres);
//Setup FOP for area tree rendering
FOUserAgent ua = effFactory.newFOUserAgent();
ua.setBaseURL(testFile.getParentFile().toURL().toString());
ua.getEventBroadcaster().addEventListener(
new ConsoleEventListenerForTests(testFile.getName(), EventSeverity.WARN));
XMLRenderer atrenderer = new XMLRenderer();
atrenderer.setUserAgent(ua);
atrenderer.setContentHandler(athandler);
ua.setRendererOverride(atrenderer);
fop = effFactory.newFop(ua);
SAXResult fores = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, fores);
} finally {
ElementListObserver.removeObserver(elCollector);
}
Document doc = (Document)domres.getNode();
if (this.areaTreeBackupDir != null) {
env.saveDOM(doc,
new File(this.areaTreeBackupDir, testFile.getName() + ".at.xml"));
}
FormattingResults results = fop.getResults();
LayoutResult result = new LayoutResult(doc, elCollector, results);
checkAll(testFile, result);
}