]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Check for plan namespace to avoid errors while parsing plan XML.
authorJeremias Maerki <jeremias@apache.org>
Mon, 20 Oct 2008 07:16:47 +0000 (07:16 +0000)
committerJeremias Maerki <jeremias@apache.org>
Mon, 20 Oct 2008 07:16:47 +0000 (07:16 +0000)
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@706135 13f79535-47bb-0310-9956-ffa450edef68

examples/plan/src/org/apache/fop/plan/PreloaderPlan.java

index b8a7a612cce52d19cc2fe1a05c4db9664fd0f51a..f99c94af91e49113dc0da2b01a377837e108e54b 100644 (file)
@@ -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();