diff options
author | Jeremias Maerki <jeremias@apache.org> | 2009-02-16 08:31:34 +0000 |
---|---|---|
committer | Jeremias Maerki <jeremias@apache.org> | 2009-02-16 08:31:34 +0000 |
commit | 108b6a24d4a9483176e84f8094d198f9f59baa8a (patch) | |
tree | e9e21539e0d1b29572414c3c71d62e746911e9b9 | |
parent | 59d51cf45b180e8e849aa44fe7a0ade4424e09b0 (diff) | |
download | xmlgraphics-fop-108b6a24d4a9483176e84f8094d198f9f59baa8a.tar.gz xmlgraphics-fop-108b6a24d4a9483176e84f8094d198f9f59baa8a.zip |
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
-rw-r--r-- | examples/plan/src/org/apache/fop/plan/PreloaderPlan.java | 32 |
1 files 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; + } + } |