From 430c6f6b18eab333e0ebd36a4ef6823d42d014db Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Mon, 20 Oct 2008 07:16:47 +0000 Subject: [PATCH] Check for plan namespace to avoid errors while parsing plan XML. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@706135 13f79535-47bb-0310-9956-ffa450edef68 --- .../plan/src/org/apache/fop/plan/PreloaderPlan.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java b/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java index b8a7a612c..f99c94af9 100644 --- a/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java +++ b/examples/plan/src/org/apache/fop/plan/PreloaderPlan.java @@ -30,6 +30,7 @@ import javax.xml.transform.dom.DOMResult; import javax.xml.transform.stream.StreamSource; import org.w3c.dom.Document; +import org.w3c.dom.Element; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -66,7 +67,7 @@ public class PreloaderPlan extends AbstractImagePreloader { return info; } - private ImageInfo getImage(String uri, Source src, ImageContext context) { + private ImageInfo getImage(String uri, Source src, ImageContext context) throws IOException { InputStream in = new UnclosableInputStream(ImageUtil.needInputStream(src)); try { @@ -78,7 +79,14 @@ public class PreloaderPlan extends AbstractImagePreloader { //Have to render the plan to know its size PlanRenderer pr = new PlanRenderer(); - Document svgDoc = pr.createSVGDocument((Document)res.getNode()); + Document planDoc = (Document)res.getNode(); + Element rootEl = planDoc.getDocumentElement(); + if (!PlanElementMapping.NAMESPACE.equals(rootEl.getNamespaceURI())) { + in.reset(); + return null; + } + + Document svgDoc = pr.createSVGDocument(planDoc); float width = pr.getWidth(); float height = pr.getHeight(); -- 2.39.5