You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ke...@apache.org on 2002/02/22 10:09:35 UTC

cvs commit: xml-fop/src/org/apache/fop/image/analyser SVGReader.java

keiron      02/02/22 01:09:35

  Modified:    src/org/apache/fop/image SVGImage.java
               src/org/apache/fop/image/analyser SVGReader.java
  Log:
  fix for no class def found error if no batik
  
  Revision  Changes    Path
  1.10      +2 -2      xml-fop/src/org/apache/fop/image/SVGImage.java
  
  Index: SVGImage.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/SVGImage.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- SVGImage.java	21 Feb 2002 09:54:27 -0000	1.9
  +++ SVGImage.java	22 Feb 2002 09:09:35 -0000	1.10
  @@ -1,5 +1,5 @@
   /*
  - * $Id: SVGImage.java,v 1.9 2002/02/21 09:54:27 keiron Exp $
  + * $Id: SVGImage.java,v 1.10 2002/02/22 09:09:35 keiron Exp $
    * 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.
  @@ -29,7 +29,7 @@
       public SVGImage(URL href, ImageReader imgReader) {
           super(href, imgReader);
           if(imgReader instanceof SVGReader) {
  -            doc = ((SVGReader)imgReader).getDocument();
  +            doc = (SVGDocument)((SVGReader)imgReader).getDocument();
           }
       }
   
  
  
  
  1.18      +72 -46    xml-fop/src/org/apache/fop/image/analyser/SVGReader.java
  
  Index: SVGReader.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/org/apache/fop/image/analyser/SVGReader.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- SVGReader.java	21 Feb 2002 09:54:27 -0000	1.17
  +++ SVGReader.java	22 Feb 2002 09:09:35 -0000	1.18
  @@ -1,5 +1,5 @@
   /*
  - * $Id: SVGReader.java,v 1.17 2002/02/21 09:54:27 keiron Exp $
  + * $Id: SVGReader.java,v 1.18 2002/02/22 09:09:35 keiron Exp $
    * 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.
  @@ -55,7 +55,10 @@
   public class SVGReader extends AbstractImageReader {
       public static final String SVG_MIME_TYPE = "image/svg+xml";
       FOUserAgent userAgent;
  -    SVGDocument doc;
  +    Document doc;
  +
  +    public SVGReader() {
  +    }
   
       public boolean verifySignature(String uri, BufferedInputStream fis,
                                      FOUserAgent ua) throws IOException {
  @@ -68,7 +71,7 @@
           return SVG_MIME_TYPE;
       }
   
  -    public SVGDocument getDocument() {
  +    public Document getDocument() {
           return doc;
       }
   
  @@ -77,53 +80,76 @@
        * Possibly need a slightly different design for the image stuff.
        */
       protected boolean loadImage(String uri) {
  -        // parse document and get the size attributes of the svg element
           try {
  -            int length = imageStream.available();
  -            imageStream.mark(length);
  -            SAXSVGDocumentFactory factory =
  -              new SAXSVGDocumentFactory(SVGImage.getParserName());
  -            doc = factory.createDocument(uri, imageStream);
  -
  -            Element e = ((SVGDocument) doc).getRootElement();
  -            String s;
  -            SVGUserAgent userAg = new SVGUserAgent(new AffineTransform());
  -            userAg.setLogger(userAgent.getLogger());
  -            BridgeContext ctx = new BridgeContext(userAg);
  -            UnitProcessor.Context uctx =
  -              UnitProcessor.createContext(ctx, e);
  -
  -            // 'width' attribute - default is 100%
  -            s = e.getAttributeNS(null, SVGOMDocument.SVG_WIDTH_ATTRIBUTE);
  -            if (s.length() == 0) {
  -                s = SVGOMDocument.SVG_SVG_WIDTH_DEFAULT_VALUE;
  -            }
  -            width = (int) UnitProcessor.svgHorizontalLengthToUserSpace (
  -                      s, SVGOMDocument.SVG_WIDTH_ATTRIBUTE, uctx);
  -
  -            // 'height' attribute - default is 100%
  -            s = e.getAttributeNS(null, SVGOMDocument.SVG_HEIGHT_ATTRIBUTE);
  -            if (s.length() == 0) {
  -                s = SVGOMDocument.SVG_SVG_HEIGHT_DEFAULT_VALUE;
  -            }
  -            height = (int) UnitProcessor.svgVerticalLengthToUserSpace (
  -                       s, SVGOMDocument.SVG_HEIGHT_ATTRIBUTE, uctx);
  -
  -            return true;
  -        } catch (NoClassDefFoundError ncdfe) {
  -            //userAgent.getLogger().error("Batik not in class path", ncdfe);
  +            Loader loader = new Loader();
  +            return loader.getImage(uri);
  +        } catch (NoClassDefFoundError e) {
  +            //userAgent.getLogger().error("Batik not in class path", e);
               return false;
           }
  -        catch (Exception e) {
  -            //userAgent.getLogger().error("Could not load external SVG: " +
  -            //                       e.getMessage(), e);
  -            // assuming any exception means this document is not svg
  -            // or could not be loaded for some reason
  -            try {
  -                imageStream.reset();
  -            } catch (IOException ioe) { }
  +    }
   
  -            return false;
  +    /**
  +     * This method is put in another class so that the classloader
  +     * does not attempt to load batik related classes when constructing
  +     * the SVGReader class.
  +     */
  +    class Loader {
  +        private boolean getImage(String uri) {
  +            // parse document and get the size attributes of the svg element
  +
  +            try {
  +                int length = imageStream.available();
  +                imageStream.mark(length);
  +                SAXSVGDocumentFactory factory = new SAXSVGDocumentFactory(
  +                                                  SVGImage.getParserName());
  +                doc = factory.createDocument(uri, imageStream);
  +
  +                Element e = ((SVGDocument) doc).getRootElement();
  +                String s;
  +                SVGUserAgent userAg =
  +                  new SVGUserAgent(new AffineTransform());
  +                userAg.setLogger(userAgent.getLogger());
  +                BridgeContext ctx = new BridgeContext(userAg);
  +                UnitProcessor.Context uctx =
  +                  UnitProcessor.createContext(ctx, e);
  +
  +                // 'width' attribute - default is 100%
  +                s = e.getAttributeNS(null,
  +                                     SVGOMDocument.SVG_WIDTH_ATTRIBUTE);
  +                if (s.length() == 0) {
  +                    s = SVGOMDocument.SVG_SVG_WIDTH_DEFAULT_VALUE;
  +                }
  +                width = (int) UnitProcessor.svgHorizontalLengthToUserSpace (
  +                          s, SVGOMDocument.SVG_WIDTH_ATTRIBUTE, uctx);
  +
  +                // 'height' attribute - default is 100%
  +                s = e.getAttributeNS(null,
  +                                     SVGOMDocument.SVG_HEIGHT_ATTRIBUTE);
  +                if (s.length() == 0) {
  +                    s = SVGOMDocument.SVG_SVG_HEIGHT_DEFAULT_VALUE;
  +                }
  +                height = (int) UnitProcessor.svgVerticalLengthToUserSpace (
  +                           s, SVGOMDocument.SVG_HEIGHT_ATTRIBUTE, uctx);
  +
  +                return true;
  +            } catch (NoClassDefFoundError ncdfe) {
  +                //userAgent.getLogger().error("Batik not in class path", ncdfe);
  +                return false;
  +            }
  +            catch (Exception e) {
  +                // If the svg is invalid then it throws an IOException
  +                // so there is no way of knowing if it is an svg document
  +
  +                // userAgent.getLogger().error("Could not load external SVG: " +
  +                //                       e.getMessage(), e);
  +                // assuming any exception means this document is not svg
  +                // or could not be loaded for some reason
  +                try {
  +                    imageStream.reset();
  +                } catch (IOException ioe) { }
  +                return false;
  +            }
           }
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: fop-cvs-help@xml.apache.org