From 108b6a24d4a9483176e84f8094d198f9f59baa8a Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Mon, 16 Feb 2009 08:31:34 +0000 Subject: [PATCH] Added ErrorListener for plan extension's DOM loading because of bugs in some XSLT implementations. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/Temp_AreaTreeNewDesign@744860 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/fop/plan/PreloaderPlan.java | 32 +++++++++++++------ 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java b/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java index f99c94af9..8544ce544 100644 --- a/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java +++ b/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java @@ -22,6 +22,7 @@ package org.apache.fop.plan; import java.io.IOException; import java.io.InputStream; +import javax.xml.transform.ErrorListener; import javax.xml.transform.Source; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; @@ -43,6 +44,7 @@ import org.apache.xmlgraphics.image.loader.impl.AbstractImagePreloader; import org.apache.xmlgraphics.image.loader.impl.ImageXMLDOM; import org.apache.xmlgraphics.image.loader.util.ImageUtil; +import org.apache.fop.util.DefaultErrorListener; import org.apache.fop.util.UnclosableInputStream; /** @@ -71,21 +73,16 @@ public class PreloaderPlan extends AbstractImagePreloader { InputStream in = new UnclosableInputStream(ImageUtil.needInputStream(src)); try { - TransformerFactory tFactory = TransformerFactory.newInstance(); - Transformer transformer = tFactory.newTransformer(); - Source source = new StreamSource(in); - DOMResult res = new DOMResult(); - transformer.transform(source, res); - - //Have to render the plan to know its size - PlanRenderer pr = new PlanRenderer(); - Document planDoc = (Document)res.getNode(); + Document planDoc = getDocument(in); Element rootEl = planDoc.getDocumentElement(); - if (!PlanElementMapping.NAMESPACE.equals(rootEl.getNamespaceURI())) { + if (!PlanElementMapping.NAMESPACE.equals( + rootEl.getNamespaceURI())) { in.reset(); return null; } + //Have to render the plan to know its size + PlanRenderer pr = new PlanRenderer(); Document svgDoc = pr.createSVGDocument(planDoc); float width = pr.getWidth(); float height = pr.getHeight(); @@ -119,4 +116,19 @@ public class PreloaderPlan extends AbstractImagePreloader { } } + private Document getDocument(InputStream in) throws TransformerException { + TransformerFactory tFactory = TransformerFactory.newInstance(); + //Custom error listener to minimize output to console + ErrorListener errorListener = new DefaultErrorListener(log); + tFactory.setErrorListener(errorListener); + Transformer transformer = tFactory.newTransformer(); + transformer.setErrorListener(errorListener); + Source source = new StreamSource(in); + DOMResult res = new DOMResult(); + transformer.transform(source, res); + + Document doc = (Document)res.getNode(); + return doc; + } + } -- 2.39.5