From: Keiron Liddle Date: Mon, 21 May 2001 12:10:31 +0000 (+0000) Subject: now passes in url string to the analyser X-Git-Tag: PRE_CODEFORMATTING~118 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=522e44c74514d18bd0b8678356a34969ae488df3;p=xmlgraphics-fop.git now passes in url string to the analyser some readers may need the url eg. svg document creator git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@194261 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/org/apache/fop/image/AbstractFopImage.java b/src/org/apache/fop/image/AbstractFopImage.java index ba79849c0..c5616e1fd 100644 --- a/src/org/apache/fop/image/AbstractFopImage.java +++ b/src/org/apache/fop/image/AbstractFopImage.java @@ -1,41 +1,7 @@ -/* - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache - Software Foundation, please see . +/* $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; @@ -113,7 +79,7 @@ public abstract class AbstractFopImage implements FopImage { public AbstractFopImage(URL href) throws FopImageException { this.m_href = href; try { - this.m_imageReader = ImageReaderFactory.Make(this.m_href.openStream()); + this.m_imageReader = ImageReaderFactory.Make(this.m_href.toExternalForm(), this.m_href.openStream()); } catch (Exception e) { throw new FopImageException(e.getMessage()); } diff --git a/src/org/apache/fop/image/FopImageFactory.java b/src/org/apache/fop/image/FopImageFactory.java index 0707ecbae..dc4678ba1 100644 --- a/src/org/apache/fop/image/FopImageFactory.java +++ b/src/org/apache/fop/image/FopImageFactory.java @@ -1,41 +1,7 @@ -/*-- $Id$ -- - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache - Software Foundation, please see . +/* $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; @@ -52,6 +18,7 @@ import java.util.Hashtable; import org.apache.fop.messaging.MessageHandler; import org.apache.fop.image.analyser.ImageReaderFactory; import org.apache.fop.image.analyser.ImageReader; +import org.apache.fop.configuration.Configuration; /** * create FopImage objects (with a configuration file - not yet implemented). @@ -59,146 +26,143 @@ import org.apache.fop.image.analyser.ImageReader; */ public class FopImageFactory { - private static Hashtable m_urlMap = new Hashtable(); + private static Hashtable m_urlMap = new Hashtable(); - /** - * create an FopImage objects. - * @param href image URL as a String - * @return a new FopImage object - * @exception java.net.MalformedURLException bad URL - * @exception FopImageException an error occured during construction - */ - public static FopImage Make(String href) - throws MalformedURLException, FopImageException { + /** + * create an FopImage objects. + * @param href image URL as a String + * @return a new FopImage object + * @exception java.net.MalformedURLException bad URL + * @exception FopImageException an error occured during construction + */ + public static FopImage Make(String href) + throws MalformedURLException, FopImageException { - // Get the absolute URL - URL absoluteURL = null; - // try { - absoluteURL = new URL(href); - /* - } - catch (MalformedURLException e) { - // maybe relative - URL context_url = null; - try { - context_url = new URL(); // how to get the context URL ? - try { - absoluteURL = new URL(context_url, ref); - } - catch (MalformedURLException e_abs) { - // not found - MessageHandler.errorln( - "Invalid Image URL : " + - e_abs.getMessage() + - "(base URL " + context_url.toString() + ")" - ); - return null; - } - } - catch (MalformedURLException e_context) { - // pb context url - MessageHandler.errorln("Invalid Image URL - error on relative URL : " + e_context.getMessage()); - return null; - } - } - */ + // Get the absolute URL + URL absoluteURL = null; + InputStream imgIS = null; + try { + absoluteURL = new URL(href); + imgIS = absoluteURL.openStream(); + } catch (Exception e) { + // maybe relative + URL context_url = null; + try { + String baseDir = Configuration.getStringValue("baseDir"); + context_url = new URL(baseDir); // how to get the context URL ? + try { + absoluteURL = new URL(context_url, href); + } catch (MalformedURLException e_abs) { + // not found + throw new FopImageException( "Invalid Image URL : " + + e_abs.getMessage() + "(base URL " + + context_url.toString() + ")"); + } + } catch (MalformedURLException e_context) { + // pb context url + throw new FopImageException( + "Invalid Image URL - error on relative URL : " + + e_context.getMessage()); + } + } - // check if already created - FopImage imageObject = - (FopImage) m_urlMap.get(absoluteURL.toString()); - if (imageObject != null) - return imageObject; + // check if already created + FopImage imageObject = + (FopImage) m_urlMap.get(absoluteURL.toString()); + if (imageObject != null) + return imageObject; - // If not, check image type - ImageReader imgReader = null; - InputStream imgIS = null; - try { - imgIS = absoluteURL.openStream(); - imgReader = ImageReaderFactory.Make(imgIS); - } catch (Exception e) { - throw new FopImageException( - "Error while recovering Image Informations (" + - absoluteURL.toString() + ") : " + e.getMessage()); - } finally { - if (imgIS != null) { - try {imgIS.close();} catch (IOException e) {} - } - } - if (imgReader == null) - throw new FopImageException("No ImageReader for this type of image (" + - absoluteURL.toString() + ")"); - // Associate mime-type to FopImage class - String imgMimeType = imgReader.getMimeType(); - String imgClassName = null; - if ("image/gif".equals(imgMimeType)) { - imgClassName = "org.apache.fop.image.GifJpegImage"; -// imgClassName = "org.apache.fop.image.JAIImage"; - } else if ("image/jpeg".equals(imgMimeType)) { - imgClassName = "org.apache.fop.image.GifJpegImage"; -// imgClassName = "org.apache.fop.image.JAIImage"; - } else if ("image/bmp".equals(imgMimeType)) { - imgClassName = "org.apache.fop.image.BmpImage"; -// imgClassName = "org.apache.fop.image.JAIImage"; - } else if ("image/png".equals(imgMimeType)) { - imgClassName = "org.apache.fop.image.JimiImage"; -// imgClassName = "org.apache.fop.image.JAIImage"; - } else if ("image/tga".equals(imgMimeType)) { - imgClassName = "org.apache.fop.image.JimiImage"; -// imgClassName = "org.apache.fop.image.JAIImage"; - } else if ("image/tiff".equals(imgMimeType)) { - imgClassName = "org.apache.fop.image.JimiImage"; -// imgClassName = "org.apache.fop.image.JAIImage"; - } else if ("image/svg-xml".equals(imgMimeType)) { - imgClassName = "org.apache.fop.image.SVGImage"; - } - if (imgClassName == null) - throw new FopImageException("Unsupported image type (" + - absoluteURL.toString() + ") : " + imgMimeType); + // If not, check image type + ImageReader imgReader = null; + try { + if (imgIS == null) { + imgIS = absoluteURL.openStream(); + } + imgReader = ImageReaderFactory.Make(absoluteURL.toExternalForm(), imgIS); + } catch (Exception e) { + throw new FopImageException( + "Error while recovering Image Informations (" + + absoluteURL.toString() + ") : " + e.getMessage()); + } + finally { if (imgIS != null) { + try { + imgIS.close(); + } catch (IOException e) {} + } + } if (imgReader == null) + throw new FopImageException( + "No ImageReader for this type of image (" + + absoluteURL.toString() + ")"); + // Associate mime-type to FopImage class + String imgMimeType = imgReader.getMimeType(); + String imgClassName = null; + if ("image/gif".equals(imgMimeType)) { + imgClassName = "org.apache.fop.image.GifJpegImage"; + // imgClassName = "org.apache.fop.image.JAIImage"; + } else if ("image/jpeg".equals(imgMimeType)) { + imgClassName = "org.apache.fop.image.GifJpegImage"; + // imgClassName = "org.apache.fop.image.JAIImage"; + } else if ("image/bmp".equals(imgMimeType)) { + imgClassName = "org.apache.fop.image.BmpImage"; + // imgClassName = "org.apache.fop.image.JAIImage"; + } else if ("image/png".equals(imgMimeType)) { + imgClassName = "org.apache.fop.image.JimiImage"; + // imgClassName = "org.apache.fop.image.JAIImage"; + } else if ("image/tga".equals(imgMimeType)) { + imgClassName = "org.apache.fop.image.JimiImage"; + // imgClassName = "org.apache.fop.image.JAIImage"; + } else if ("image/tiff".equals(imgMimeType)) { + imgClassName = "org.apache.fop.image.JimiImage"; + // imgClassName = "org.apache.fop.image.JAIImage"; + } else if ("image/svg-xml".equals(imgMimeType)) { + imgClassName = "org.apache.fop.image.SVGImage"; + } + if (imgClassName == null) + throw new FopImageException("Unsupported image type (" + + absoluteURL.toString() + ") : " + imgMimeType); - // load the right image class - // return new - Object imageInstance = null; - Class imageClass = null; - try { - imageClass = Class.forName(imgClassName); - Class[] imageConstructorParameters = new Class[2]; - imageConstructorParameters[0] = Class.forName("java.net.URL"); - imageConstructorParameters[1] = Class.forName("org.apache.fop.image.analyser.ImageReader"); - Constructor imageConstructor = - imageClass.getDeclaredConstructor( - imageConstructorParameters); - Object[] initArgs = new Object[2]; - initArgs[0] = absoluteURL; - initArgs[1] = imgReader; - imageInstance = imageConstructor.newInstance(initArgs); - } catch (java.lang.reflect.InvocationTargetException ex) { - Throwable t = ex.getTargetException(); - String msg; - if (t != null) { - msg = t.getMessage(); - } - else { - msg = ex.getMessage(); - } - throw new FopImageException( - "Error creating FopImage object (" + - absoluteURL.toString() + ") : " + msg - ); - } catch (Exception ex) { - throw new FopImageException( - "Error creating FopImage object (" + - "Error creating FopImage object (" + - absoluteURL.toString() + ") : " + ex.getMessage() - ); - } - if (! (imageInstance instanceof org.apache.fop.image.FopImage)) { - throw new FopImageException( - "Error creating FopImage object (" + - absoluteURL.toString() + ") : " + "class " + - imageClass.getName() + " doesn't implement org.apache.fop.image.FopImage interface"); - } - m_urlMap.put(absoluteURL.toString(), imageInstance); - return (FopImage) imageInstance; - } + // load the right image class + // return new + Object imageInstance = null; + Class imageClass = null; + try { + imageClass = Class.forName(imgClassName); + Class[] imageConstructorParameters = new Class[2]; + imageConstructorParameters[0] = Class.forName("java.net.URL"); + imageConstructorParameters[1] = Class.forName("org.apache.fop.image.analyser.ImageReader"); + Constructor imageConstructor = + imageClass.getDeclaredConstructor( + imageConstructorParameters); + Object[] initArgs = new Object[2]; + initArgs[0] = absoluteURL; + initArgs[1] = imgReader; + imageInstance = imageConstructor.newInstance(initArgs); + } catch (java.lang.reflect.InvocationTargetException ex) { + Throwable t = ex.getTargetException(); + String msg; + if (t != null) { + msg = t.getMessage(); + } else { + msg = ex.getMessage(); + } + throw new FopImageException( + "Error creating FopImage object (" + + absoluteURL.toString() + ") : " + msg); + } + catch (Exception ex) { + throw new FopImageException( + "Error creating FopImage object (" + + "Error creating FopImage object (" + + absoluteURL.toString() + ") : " + ex.getMessage()); + } + if (! (imageInstance instanceof org.apache.fop.image.FopImage)) { + throw new FopImageException( + "Error creating FopImage object (" + + absoluteURL.toString() + ") : " + "class " + + imageClass.getName() + " doesn't implement org.apache.fop.image.FopImage interface"); + } + m_urlMap.put(absoluteURL.toString(), imageInstance); + return (FopImage) imageInstance; + } } diff --git a/src/org/apache/fop/image/SVGImage.java b/src/org/apache/fop/image/SVGImage.java index b88a7b92a..f39ce2430 100644 --- a/src/org/apache/fop/image/SVGImage.java +++ b/src/org/apache/fop/image/SVGImage.java @@ -11,7 +11,6 @@ import java.net.URL; import org.w3c.dom.svg.SVGDocument; // FOP -import org.apache.fop.svg.SVGDriver; import org.apache.fop.messaging.*; import org.apache.fop.datatypes.ColorSpace; import org.apache.fop.pdf.PDFColor; @@ -20,6 +19,8 @@ import org.apache.fop.image.analyser.ImageReader; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; +import org.apache.batik.dom.svg.SAXSVGDocumentFactory; + /** * @see AbstractFopImage * @see FopImage @@ -42,38 +43,18 @@ public class SVGImage extends AbstractFopImage { * * @return the created SAX parser */ - public static XMLReader createParser() { + public static String getParserName() { String parserClassName = System.getProperty("org.xml.sax.parser"); if (parserClassName == null) { parserClassName = "org.apache.xerces.parsers.SAXParser"; } - MessageHandler.logln("using SAX parser " + parserClassName); - - try { - return (XMLReader) Class.forName( - parserClassName).newInstance(); - } catch (ClassNotFoundException e) { - MessageHandler.errorln("Could not find " + parserClassName); - } catch (InstantiationException e) { - MessageHandler.errorln("Could not instantiate " + - parserClassName); - } catch (IllegalAccessException e) { - MessageHandler.errorln("Could not access " + parserClassName); - } catch (ClassCastException e) { - MessageHandler.errorln(parserClassName + " is not a SAX driver"); - } - return null; + return parserClassName; } protected void loadImage() throws FopImageException { try { - SVGDriver driver = new SVGDriver(); - driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); - driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping"); - XMLReader parser = createParser(); - driver.buildSVGTree(parser, - new InputSource(this.m_href.toString())); - doc = driver.getSVGDocument(); + SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(SVGImage.getParserName()); + doc = factory.createDocument(this.m_href.toExternalForm()); } catch (Exception e) { MessageHandler.errorln("ERROR LOADING EXTERNAL SVG: " + e.getMessage()); diff --git a/src/org/apache/fop/image/analyser/AbstractImageReader.java b/src/org/apache/fop/image/analyser/AbstractImageReader.java index 0bcf7bab4..d5ff4131c 100644 --- a/src/org/apache/fop/image/analyser/AbstractImageReader.java +++ b/src/org/apache/fop/image/analyser/AbstractImageReader.java @@ -1,41 +1,7 @@ -/* - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache - Software Foundation, please see . +/* $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; @@ -64,7 +30,7 @@ public abstract class AbstractImageReader implements ImageReader { */ protected BufferedInputStream imageStream = null; - public abstract boolean verifySignature(BufferedInputStream fis) throws IOException; + public abstract boolean verifySignature(String uri, BufferedInputStream fis) throws IOException; public int getHeight() { return this.height; diff --git a/src/org/apache/fop/image/analyser/BMPReader.java b/src/org/apache/fop/image/analyser/BMPReader.java index 1ab5a8256..ad4c0a131 100644 --- a/src/org/apache/fop/image/analyser/BMPReader.java +++ b/src/org/apache/fop/image/analyser/BMPReader.java @@ -1,41 +1,7 @@ -/* - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache - Software Foundation, please see . +/* $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; @@ -54,7 +20,7 @@ public class BMPReader extends AbstractImageReader { protected byte[] header; - public boolean verifySignature(BufferedInputStream fis) + public boolean verifySignature(String uri, BufferedInputStream fis) throws IOException { this.imageStream = fis; this.setDefaultHeader(); diff --git a/src/org/apache/fop/image/analyser/GIFReader.java b/src/org/apache/fop/image/analyser/GIFReader.java index a1973e81a..bb267755e 100644 --- a/src/org/apache/fop/image/analyser/GIFReader.java +++ b/src/org/apache/fop/image/analyser/GIFReader.java @@ -1,41 +1,7 @@ -/* - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache - Software Foundation, please see . +/* $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; @@ -53,7 +19,7 @@ public class GIFReader extends AbstractImageReader { static protected final int GIF_SIG_LENGTH = 10; protected byte[] header; - public boolean verifySignature(BufferedInputStream fis) + public boolean verifySignature(String uri, BufferedInputStream fis) throws IOException { this.imageStream = fis; this.setDefaultHeader(); diff --git a/src/org/apache/fop/image/analyser/ImageReader.java b/src/org/apache/fop/image/analyser/ImageReader.java index bdeffc35e..edf0ce96d 100644 --- a/src/org/apache/fop/image/analyser/ImageReader.java +++ b/src/org/apache/fop/image/analyser/ImageReader.java @@ -1,41 +1,7 @@ -/* - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache - Software Foundation, please see . +/* $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; @@ -56,7 +22,7 @@ public interface ImageReader { * @return true if image type is the handled one * @exception IOException io error */ - public boolean verifySignature(BufferedInputStream bis) + public boolean verifySignature(String uri, BufferedInputStream bis) throws IOException; /** diff --git a/src/org/apache/fop/image/analyser/ImageReaderFactory.java b/src/org/apache/fop/image/analyser/ImageReaderFactory.java index 5593be778..c650c7235 100644 --- a/src/org/apache/fop/image/analyser/ImageReaderFactory.java +++ b/src/org/apache/fop/image/analyser/ImageReaderFactory.java @@ -1,41 +1,7 @@ -/* - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache - Software Foundation, please see . +/* $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; @@ -65,7 +31,7 @@ public class ImageReaderFactory { * @exception FopImageException an error occured during creation or * image type is not supported */ - static public ImageReader Make(InputStream in) + static public ImageReader Make(String uri, InputStream in) throws FopImageException { // need to use a config file and remove static methods @@ -84,7 +50,7 @@ public class ImageReaderFactory { try { while (itr.hasMoreElements()) { reader = (ImageReader) itr.nextElement(); - if (reader.verifySignature(bis)) { + if (reader.verifySignature(uri, bis)) { return reader; } } diff --git a/src/org/apache/fop/image/analyser/JPEGReader.java b/src/org/apache/fop/image/analyser/JPEGReader.java index e7370ae4e..5f1949288 100644 --- a/src/org/apache/fop/image/analyser/JPEGReader.java +++ b/src/org/apache/fop/image/analyser/JPEGReader.java @@ -1,41 +1,7 @@ -/* - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache - Software Foundation, please see . +/* $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; @@ -71,7 +37,7 @@ public class JPEGReader extends AbstractImageReader { protected byte[] header; - public boolean verifySignature(BufferedInputStream fis) + public boolean verifySignature(String uri, BufferedInputStream fis) throws IOException { this.imageStream = fis; this.setDefaultHeader(); diff --git a/src/org/apache/fop/image/analyser/PNGReader.java b/src/org/apache/fop/image/analyser/PNGReader.java index 2d617454e..8020cdf6a 100644 --- a/src/org/apache/fop/image/analyser/PNGReader.java +++ b/src/org/apache/fop/image/analyser/PNGReader.java @@ -1,41 +1,7 @@ -/* - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache - Software Foundation, please see . +/* $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; @@ -53,7 +19,7 @@ public class PNGReader extends AbstractImageReader { static protected final int PNG_SIG_LENGTH = 24; protected byte[] header; - public boolean verifySignature(BufferedInputStream fis) throws IOException { + public boolean verifySignature(String uri, BufferedInputStream fis) throws IOException { this.imageStream = fis; this.setDefaultHeader(); boolean supported = ((header[0] == (byte) 0x89) && diff --git a/src/org/apache/fop/image/analyser/SVGReader.java b/src/org/apache/fop/image/analyser/SVGReader.java index ef4d77e97..31e01e015 100644 --- a/src/org/apache/fop/image/analyser/SVGReader.java +++ b/src/org/apache/fop/image/analyser/SVGReader.java @@ -14,22 +14,22 @@ import org.w3c.dom.svg.SVGDocument; import org.w3c.dom.svg.SVGSVGElement; // FOP -import org.apache.fop.svg.SVGDriver; import org.apache.fop.messaging.*; import org.apache.fop.image.SVGImage; import org.xml.sax.InputSource; import org.xml.sax.XMLReader; +import org.apache.batik.dom.svg.SAXSVGDocumentFactory; + /** * ImageReader object for SVG document image type. */ public class SVGReader extends AbstractImageReader { - - public boolean verifySignature(BufferedInputStream fis) + public boolean verifySignature(String uri, BufferedInputStream fis) throws IOException { this.imageStream = fis; - return loadImage(); + return loadImage(uri); } public String getMimeType() { @@ -40,16 +40,12 @@ public class SVGReader extends AbstractImageReader { * This means the external svg document will be loaded twice. * Possibly need a slightly different design for the image stuff. */ - protected boolean loadImage() { + protected boolean loadImage(String uri) { // parse document and get the size attributes of the svg element try { + SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(SVGImage.getParserName()); + SVGDocument doc = factory.createDocument(uri, imageStream); // should check the stream contains text data - SVGDriver driver = new SVGDriver(); - driver.addElementMapping("org.apache.fop.svg.SVGElementMapping"); - driver.addPropertyList("org.apache.fop.svg.SVGPropertyListMapping"); - XMLReader parser = SVGImage.createParser(); - driver.buildSVGTree(parser, new InputSource(this.imageStream)); - SVGDocument doc = driver.getSVGDocument(); SVGSVGElement svg = doc.getRootElement(); this.width = (int) svg.getWidth().getBaseVal().getValue() * 1000; diff --git a/src/org/apache/fop/image/analyser/TIFFReader.java b/src/org/apache/fop/image/analyser/TIFFReader.java index be95ad3ac..d6b9eea16 100644 --- a/src/org/apache/fop/image/analyser/TIFFReader.java +++ b/src/org/apache/fop/image/analyser/TIFFReader.java @@ -1,41 +1,7 @@ -/* - ============================================================================ - The Apache Software License, Version 1.1 - ============================================================================ - Copyright (C) 1999 The Apache Software Foundation. All rights reserved. - Redistribution and use in source and binary forms, with or without modifica- - tion, are permitted provided that the following conditions are met: - 1. Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - 2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - 3. The end-user documentation included with the redistribution, if any, must - include the following acknowledgment: "This product includes software - developed by the Apache Software Foundation (http://www.apache.org/)." - Alternately, this acknowledgment may appear in the software itself, if - and wherever such third-party acknowledgments normally appear. - 4. The names "Fop" and "Apache Software Foundation" must not be used to - endorse or promote products derived from this software without prior - written permission. For written permission, please contact - apache@apache.org. - 5. Products derived from this software may not be called "Apache", nor may - "Apache" appear in their name, without prior written permission of the - Apache Software Foundation. - THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, - INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- - DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON - ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF - THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - This software consists of voluntary contributions made by many individuals - on behalf of the Apache Software Foundation and was originally created by - James Tauber . For more information on the Apache - Software Foundation, please see . +/* $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; @@ -54,7 +20,7 @@ public class TIFFReader extends AbstractImageReader static protected final int TIFF_SIG_LENGTH = 8; protected byte[] header; - public boolean verifySignature( BufferedInputStream fis ) throws IOException + public boolean verifySignature(String uri, BufferedInputStream fis ) throws IOException { this.imageStream = fis; this.setDefaultHeader();