diff options
author | Keiron Liddle <keiron@apache.org> | 2002-03-08 11:00:20 +0000 |
---|---|---|
committer | Keiron Liddle <keiron@apache.org> | 2002-03-08 11:00:20 +0000 |
commit | f0e488222854d0a838094936b6929e083c15230b (patch) | |
tree | fff738398f5429595b48cfe4270ab9cd91ef98f6 /src/org/apache/fop/image/analyser/XMLReader.java | |
parent | 8f766d59eba2df9b0600b2fad11b098cb589a64f (diff) | |
download | xmlgraphics-fop-f0e488222854d0a838094936b6929e083c15230b.tar.gz xmlgraphics-fop-f0e488222854d0a838094936b6929e083c15230b.zip |
renders images and ifo to pdf doc
added xml reader for external graphics
git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194696 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/org/apache/fop/image/analyser/XMLReader.java')
-rw-r--r-- | src/org/apache/fop/image/analyser/XMLReader.java | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/src/org/apache/fop/image/analyser/XMLReader.java b/src/org/apache/fop/image/analyser/XMLReader.java new file mode 100644 index 000000000..ab66be981 --- /dev/null +++ b/src/org/apache/fop/image/analyser/XMLReader.java @@ -0,0 +1,98 @@ +/* + * $Id$ + * Copyright (C) 2001 The Apache Software Foundation. All rights reserved. + * For details on use and redistribution please refer to the + * LICENSE file included with these sources. + */ + +package org.apache.fop.image.analyser; + +// Java +import java.io.BufferedInputStream; +import java.io.IOException; + +import org.xml.sax.InputSource; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.w3c.dom.*; +import org.w3c.dom.DOMImplementation; + +import java.io.File; +import java.net.URL; +import java.util.HashMap; + +import org.apache.fop.image.FopImage; +import org.apache.fop.fo.FOUserAgent; +import org.apache.fop.image.XMLImage; + +/** + * ImageReader object for XML document image type. + */ +public class XMLReader implements ImageReader { + private static HashMap converters = new HashMap(); + + public static void setConverter(String ns, Converter conv) { + converters.put(ns, conv); + } + + public XMLReader() { + } + + public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream fis, + FOUserAgent ua) throws IOException { + return loadImage(uri, fis, ua); + } + + public String getMimeType() { + return "text/xml"; + } + + /** + * This means the external svg document will be loaded twice. + * Possibly need a slightly different design for the image stuff. + */ + protected FopImage.ImageInfo loadImage(String uri, BufferedInputStream fis, + FOUserAgent ua) { + return createDocument(fis, ua); + } + + public FopImage.ImageInfo createDocument(BufferedInputStream is, FOUserAgent ua) { + Document doc = null; + FopImage.ImageInfo info = new FopImage.ImageInfo(); + info.mimeType = getMimeType(); + + try { + int length = is.available(); + is.mark(length); + + DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); + doc = dbf.newDocumentBuilder().parse(is); + info.data = doc; + + Element root = doc.getDocumentElement(); + ua.getLogger().debug("ns:" + root.getAttribute("xmlns")); + String ns = root.getAttribute("xmlns"); + info.str = ns; + + Converter conv = (Converter)converters.get(ns); + if(conv != null) { + FopImage.ImageInfo i = conv.convert(doc); + if(i != null) { + info = i; + } + } + } catch (Exception e) { + e.printStackTrace(); + try { + is.reset(); + } catch (IOException ioe) { } + return null; + } + return info; + } + + public static interface Converter { + public FopImage.ImageInfo convert(Document doc); + } +} + |