From: Jeremias Maerki Date: Mon, 16 Feb 2009 08:31:34 +0000 (+0000) Subject: Added ErrorListener for plan extension's DOM loading because of bugs in some XSLT... X-Git-Tag: fop-1_0~115^2~57 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=108b6a24d4a9483176e84f8094d198f9f59baa8a;p=xmlgraphics-fop.git 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 --- 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; + } + }