Ignore:
Timestamp:
2013-06-11T01:01:28+02:00 (11 years ago)
Author:
Don-vip
Message:

fix #8742 - update svgsalamander to release 0.1.18+patch (fix bug SVGSALAMANDER-26) -> allow to open more SVG files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/kitfox/svg/SVGUniverse.java

    r4256 r6002  
    11/*
    2  * SVGUniverse.java
     2 * SVG Salamander
     3 * Copyright (c) 2004, Mark McKay
     4 * All rights reserved.
    35 *
     6 * Redistribution and use in source and binary forms, with or
     7 * without modification, are permitted provided that the following
     8 * conditions are met:
    49 *
    5  *  The Salamander Project - 2D and 3D graphics libraries in Java
    6  *  Copyright (C) 2004 Mark McKay
     10 *   - Redistributions of source code must retain the above
     11 *     copyright notice, this list of conditions and the following
     12 *     disclaimer.
     13 *   - Redistributions in binary form must reproduce the above
     14 *     copyright notice, this list of conditions and the following
     15 *     disclaimer in the documentation and/or other materials
     16 *     provided with the distribution.
    717 *
    8  *  This library is free software; you can redistribute it and/or
    9  *  modify it under the terms of the GNU Lesser General Public
    10  *  License as published by the Free Software Foundation; either
    11  *  version 2.1 of the License, or (at your option) any later version.
    12  *
    13  *  This library is distributed in the hope that it will be useful,
    14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    16  *  Lesser General Public License for more details.
    17  *
    18  *  You should have received a copy of the GNU Lesser General Public
    19  *  License along with this library; if not, write to the Free Software
    20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    21  *
    22  *  Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
    23  *  projects can be found at http://www.kitfox.com
     18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
     21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
     22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     27 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
     29 * OF THE POSSIBILITY OF SUCH DAMAGE.
     30 *
     31 * Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
     32 * projects can be found at http://www.kitfox.com
    2433 *
    2534 * Created on February 18, 2004, 11:43 PM
    2635 */
    27 
    2836package com.kitfox.svg;
    2937
     
    3644import java.io.ByteArrayInputStream;
    3745import java.io.ByteArrayOutputStream;
    38 import java.io.File;
    3946import java.io.IOException;
    4047import java.io.InputStream;
     
    4653import java.net.MalformedURLException;
    4754import java.net.URI;
     55import java.net.URISyntaxException;
    4856import java.net.URL;
    4957import java.net.URLConnection;
     
    5159import java.util.HashMap;
    5260import java.util.Iterator;
     61import java.util.logging.Level;
     62import java.util.logging.Logger;
    5363import java.util.zip.GZIPInputStream;
    5464import javax.imageio.ImageIO;
     
    6171
    6272/**
    63  * Many SVG files can be loaded at one time.  These files will quite likely
    64  * need to reference one another.  The SVG universe provides a container for
    65  * all these files and the means for them to relate to each other.
     73 * Many SVG files can be loaded at one time. These files will quite likely need
     74 * to reference one another. The SVG universe provides a container for all these
     75 * files and the means for them to relate to each other.
    6676 *
    6777 * @author Mark McKay
     
    7080public class SVGUniverse implements Serializable
    7181{
     82
    7283    public static final long serialVersionUID = 0;
    73    
    7484    transient private PropertyChangeSupport changes = new PropertyChangeSupport(this);
    75    
    76     /**
    77      * Maps document URIs to their loaded SVG diagrams.  Note that URIs for
     85    /**
     86     * Maps document URIs to their loaded SVG diagrams. Note that URIs for
    7887     * documents loaded from URLs will reflect their URLs and URIs for documents
    7988     * initiated from streams will have the scheme <i>svgSalamander</i>.
    8089     */
    8190    final HashMap loadedDocs = new HashMap();
    82    
    8391    final HashMap loadedFonts = new HashMap();
    84    
    8592    final HashMap loadedImages = new HashMap();
    86    
    8793    public static final String INPUTSTREAM_SCHEME = "svgSalamander";
    88    
    89     /**
    90      * Current time in this universe.  Used for resolving attributes that
    91      * are influenced by track information.  Time is in milliseconds.  Time
    92      * 0 coresponds to the time of 0 in each member diagram.
     94    /**
     95     * Current time in this universe. Used for resolving attributes that are
     96     * influenced by track information. Time is in milliseconds. Time 0
     97     * coresponds to the time of 0 in each member diagram.
    9398     */
    9499    protected double curTime = 0.0;
    95    
    96100    private boolean verbose = false;
    97 
    98101    //Cache reader for efficiency
    99102    XMLReader cachedReader;
    100    
    101     /** Creates a new instance of SVGUniverse */
     103
     104    /**
     105     * Creates a new instance of SVGUniverse
     106     */
    102107    public SVGUniverse()
    103108    {
    104109    }
    105    
     110
    106111    public void addPropertyChangeListener(PropertyChangeListener l)
    107112    {
    108113        changes.addPropertyChangeListener(l);
    109114    }
    110    
     115
    111116    public void removePropertyChangeListener(PropertyChangeListener l)
    112117    {
    113118        changes.removePropertyChangeListener(l);
    114119    }
    115    
     120
    116121    /**
    117122     * Release all loaded SVG document from memory
     
    123128        loadedImages.clear();
    124129    }
    125    
     130
    126131    /**
    127132     * Returns the current animation time in milliseconds.
    128133     */
    129134    public double getCurTime()
    130     { 
    131         return curTime; 
    132     }
    133    
     135    {
     136        return curTime;
     137    }
     138
    134139    public void setCurTime(double curTime)
    135140    {
    136141        double oldTime = this.curTime;
    137         this.curTime = curTime; 
     142        this.curTime = curTime;
    138143        changes.firePropertyChange("curTime", new Double(oldTime), new Double(curTime));
    139144    }
    140    
     145
    141146    /**
    142147     * Updates all time influenced style and presentation attributes in all SVG
     
    147152        for (Iterator it = loadedDocs.values().iterator(); it.hasNext();)
    148153        {
    149             SVGDiagram dia = (SVGDiagram)it.next();
     154            SVGDiagram dia = (SVGDiagram) it.next();
    150155            dia.updateTime(curTime);
    151156        }
    152157    }
    153    
     158
    154159    /**
    155160     * Called by the Font element to let the universe know that a font has been
     
    160165        loadedFonts.put(font.getFontFace().getFontFamily(), font);
    161166    }
    162    
     167
    163168    public Font getDefaultFont()
    164169    {
    165170        for (Iterator it = loadedFonts.values().iterator(); it.hasNext();)
    166171        {
    167             return (Font)it.next();
     172            return (Font) it.next();
    168173        }
    169174        return null;
    170175    }
    171    
     176
    172177    public Font getFont(String fontName)
    173178    {
    174         return (Font)loadedFonts.get(fontName);
     179        return (Font) loadedFonts.get(fontName);
    175180    }
    176181
     
    188193            {
    189194                content = content.substring(6);
    190                 try {
     195                try
     196                {
    191197                    byte[] buf = new sun.misc.BASE64Decoder().decodeBuffer(content);
    192198                    ByteArrayInputStream bais = new ByteArrayInputStream(buf);
     
    209215
    210216                    return url;
    211                 } catch (IOException ex) {
    212                     ex.printStackTrace();
     217                } catch (IOException ex)
     218                {
     219                    Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     220                        "Could not decode inline image", ex);
    213221                }
    214222            }
    215223            return null;
    216         }
    217         else
    218         {
    219             try {
     224        } else
     225        {
     226            try
     227            {
    220228                URL url = imageURI.toURL();
    221229                registerImage(url);
    222230                return url;
    223             } catch (MalformedURLException ex) {
    224                 ex.printStackTrace();
     231            } catch (MalformedURLException ex)
     232            {
     233                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     234                    "Bad url", ex);
    225235            }
    226236            return null;
     
    230240    void registerImage(URL imageURL)
    231241    {
    232         if (loadedImages.containsKey(imageURL)) return;
    233        
     242        if (loadedImages.containsKey(imageURL))
     243        {
     244            return;
     245        }
     246
    234247        SoftReference ref;
    235248        try
     
    240253                SVGIcon icon = new SVGIcon();
    241254                icon.setSvgURI(imageURL.toURI());
    242                
     255
    243256                BufferedImage img = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
    244257                Graphics2D g = img.createGraphics();
     
    246259                g.dispose();
    247260                ref = new SoftReference(img);
    248             }
    249             else
     261            } else
    250262            {
    251263                BufferedImage img = ImageIO.read(imageURL);
     
    253265            }
    254266            loadedImages.put(imageURL, ref);
    255         }
    256         catch (Exception e)
    257         {
    258             System.err.println("Could not load image: " + imageURL);
    259             e.printStackTrace();
    260         }
    261     }
    262    
     267        } catch (Exception e)
     268        {
     269            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     270                "Could not load image: " + imageURL, e);
     271        }
     272    }
     273
    263274    BufferedImage getImage(URL imageURL)
    264275    {
    265         SoftReference ref = (SoftReference)loadedImages.get(imageURL);
    266         if (ref == null) return null;
    267        
    268         BufferedImage img = (BufferedImage)ref.get();
     276        SoftReference ref = (SoftReference) loadedImages.get(imageURL);
     277        if (ref == null)
     278        {
     279            return null;
     280        }
     281
     282        BufferedImage img = (BufferedImage) ref.get();
    269283        //If image was cleared from memory, reload it
    270284        if (img == null)
     
    273287            {
    274288                img = ImageIO.read(imageURL);
    275             }
    276             catch (Exception e)
    277             { e.printStackTrace(); }
     289            } catch (Exception e)
     290            {
     291                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     292                    "Could not load image", e);
     293            }
    278294            ref = new SoftReference(img);
    279295            loadedImages.put(imageURL, ref);
    280296        }
    281        
     297
    282298        return img;
    283299    }
    284    
    285     /**
    286      * Returns the element of the document at the given URI.  If the document
    287      * is not already loaded, it will be.
     300
     301    /**
     302     * Returns the element of the document at the given URI. If the document is
     303     * not already loaded, it will be.
    288304     */
    289305    public SVGElement getElement(URI path)
     
    291307        return getElement(path, true);
    292308    }
    293    
     309
    294310    public SVGElement getElement(URL path)
    295311    {
     
    298314            URI uri = new URI(path.toString());
    299315            return getElement(uri, true);
    300         }
    301         catch (Exception e)
    302         {
    303             e.printStackTrace();
     316        } catch (Exception e)
     317        {
     318            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     319                "Could not parse url " + path, e);
    304320        }
    305321        return null;
    306322    }
    307    
    308     /**
    309      * Looks up a href within our universe.  If the href refers to a document that
    310      * is not loaded, it will be loaded.  The URL #target will then be checked
    311      * against the SVG diagram's index and the coresponding element returned.
    312      * If there is no coresponding index, null is returned.
     323
     324    /**
     325     * Looks up a href within our universe. If the href refers to a document
     326     * that is not loaded, it will be loaded. The URL #target will then be
     327     * checked against the SVG diagram's index and the coresponding element
     328     * returned. If there is no coresponding index, null is returned.
    313329     */
    314330    public SVGElement getElement(URI path, boolean loadIfAbsent)
     
    318334            //Strip fragment from URI
    319335            URI xmlBase = new URI(path.getScheme(), path.getSchemeSpecificPart(), null);
    320            
    321             SVGDiagram dia = (SVGDiagram)loadedDocs.get(xmlBase);
     336
     337            SVGDiagram dia = (SVGDiagram) loadedDocs.get(xmlBase);
    322338            if (dia == null && loadIfAbsent)
    323339            {
     
    325341//javax.swing.JOptionPane.showMessageDialog(null, xmlBase.toString());
    326342                URL url = xmlBase.toURL();
    327                
     343
    328344                loadSVG(url, false);
    329                 dia = (SVGDiagram)loadedDocs.get(xmlBase);
    330                 if (dia == null) return null;
    331             }
    332            
     345                dia = (SVGDiagram) loadedDocs.get(xmlBase);
     346                if (dia == null)
     347                {
     348                    return null;
     349                }
     350            }
     351
    333352            String fragment = path.getFragment();
    334353            return fragment == null ? dia.getRoot() : dia.getElement(fragment);
    335         }
    336         catch (Exception e)
    337         {
    338             e.printStackTrace();
    339             return null;
    340         }
    341     }
    342    
     354        } catch (Exception e)
     355        {
     356            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     357                "Could not parse path " + path, e);
     358            return null;
     359        }
     360    }
     361
    343362    public SVGDiagram getDiagram(URI xmlBase)
    344363    {
    345364        return getDiagram(xmlBase, true);
    346365    }
    347    
    348     /**
    349      * Returns the diagram that has been loaded from this root.  If diagram is
     366
     367    /**
     368     * Returns the diagram that has been loaded from this root. If diagram is
    350369     * not already loaded, returns null.
    351370     */
    352371    public SVGDiagram getDiagram(URI xmlBase, boolean loadIfAbsent)
    353372    {
    354         if (xmlBase == null) return null;
    355 
    356         SVGDiagram dia = (SVGDiagram)loadedDocs.get(xmlBase);
    357         if (dia != null || !loadIfAbsent) return dia;
    358        
     373        if (xmlBase == null)
     374        {
     375            return null;
     376        }
     377
     378        SVGDiagram dia = (SVGDiagram) loadedDocs.get(xmlBase);
     379        if (dia != null || !loadIfAbsent)
     380        {
     381            return dia;
     382        }
     383
    359384        //Load missing diagram
    360385        try
     
    372397            }
    373398
    374            
     399
    375400            loadSVG(url, false);
    376             dia = (SVGDiagram)loadedDocs.get(xmlBase);
     401            dia = (SVGDiagram) loadedDocs.get(xmlBase);
    377402            return dia;
    378         }
    379         catch (Exception e)
    380         {
    381             e.printStackTrace();
    382         }
    383        
     403        } catch (Exception e)
     404        {
     405            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     406                "Could not parse", e);
     407        }
     408
    384409        return null;
    385410    }
    386    
    387     /**
    388      * Wraps input stream in a BufferedInputStream.  If it is detected that this
     411
     412    /**
     413     * Wraps input stream in a BufferedInputStream. If it is detected that this
    389414     * input stream is GZIPped, also wraps in a GZIPInputStream for inflation.
    390      * 
     415     *
    391416     * @param is Raw input stream
    392417     * @return Uncompressed stream of SVG data
     
    406431            GZIPInputStream iis = new GZIPInputStream(bin);
    407432            return iis;
    408         }
    409         else
     433        } else
    410434        {
    411435            //Plain text
     
    413437        }
    414438    }
    415    
     439
    416440    public URI loadSVG(URL docRoot)
    417441    {
    418442        return loadSVG(docRoot, false);
    419443    }
    420    
     444
    421445    /**
    422446     * Loads an SVG file and all the files it references from the URL provided.
    423447     * If a referenced file already exists in the SVG universe, it is not
    424448     * reloaded.
     449     *
    425450     * @param docRoot - URL to the location where this SVG file can be found.
    426451     * @param forceLoad - if true, ignore cached diagram and reload
     
    432457        {
    433458            URI uri = new URI(docRoot.toString());
    434             if (loadedDocs.containsKey(uri) && !forceLoad) return uri;
    435            
     459            if (loadedDocs.containsKey(uri) && !forceLoad)
     460            {
     461                return uri;
     462            }
     463
    436464            InputStream is = docRoot.openStream();
    437465            return loadSVG(uri, new InputSource(createDocumentInputStream(is)));
    438         }
    439         catch (Throwable t)
    440         {
    441             t.printStackTrace();
    442         }
    443        
     466        } catch (URISyntaxException ex)
     467        {
     468            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     469                "Could not parse", ex);
     470        } catch (IOException e)
     471        {
     472            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     473                "Could not parse", e);
     474        }
     475
    444476        return null;
    445477    }
    446    
    447    
     478
    448479    public URI loadSVG(InputStream is, String name) throws IOException
    449480    {
    450481        return loadSVG(is, name, false);
    451482    }
    452    
     483
    453484    public URI loadSVG(InputStream is, String name, boolean forceLoad) throws IOException
    454485    {
    455486        URI uri = getStreamBuiltURI(name);
    456         if (uri == null) return null;
    457         if (loadedDocs.containsKey(uri) && !forceLoad) return uri;
    458        
     487        if (uri == null)
     488        {
     489            return null;
     490        }
     491        if (loadedDocs.containsKey(uri) && !forceLoad)
     492        {
     493            return uri;
     494        }
     495
    459496        return loadSVG(uri, new InputSource(createDocumentInputStream(is)));
    460497    }
    461    
     498
    462499    public URI loadSVG(Reader reader, String name)
    463500    {
    464501        return loadSVG(reader, name, false);
    465502    }
    466    
     503
    467504    /**
    468505     * This routine allows you to create SVG documents from data streams that
    469      * may not necessarily have a URL to load from.  Since every SVG document
    470      * must be identified by a unique URL, Salamander provides a method to
    471      * fake this for streams by defining it's own protocol - svgSalamander -
    472      * for SVG documents without a formal URL.
     506     * may not necessarily have a URL to load from. Since every SVG document
     507     * must be identified by a unique URL, Salamander provides a method to fake
     508     * this for streams by defining it's own protocol - svgSalamander - for SVG
     509     * documents without a formal URL.
    473510     *
    474511     * @param reader - A stream containing a valid SVG document
    475      * @param name - <p>A unique name for this document.  It will be used to
     512     * @param name - <p>A unique name for this document. It will be used to
    476513     * construct a unique URI to refer to this document and perform resolution
    477      * with relative URIs within this document.</p>
    478      * <p>For example, a name of "/myScene" will produce the URI
    479      * svgSalamander:/myScene.  "/maps/canada/toronto" will produce
    480      * svgSalamander:/maps/canada/toronto.  If this second document then
    481      * contained the href "../uk/london", it would resolve by default to
    482      * svgSalamander:/maps/uk/london.  That is, SVG Salamander defines the
    483      * URI scheme svgSalamander for it's own internal use and uses it
    484      * for uniquely identfying documents loaded by stream.</p>
    485      * <p>If you need to link to documents outside of this scheme, you can
    486      * either supply full hrefs (eg, href="url(http://www.kitfox.com/index.html)")
    487      * or put the xml:base attribute in a tag to change the defaultbase
    488      * URIs are resolved against</p>
    489      * <p>If a name does not start with the character '/', it will be automatically
    490      * prefixed to it.</p>
     514     * with relative URIs within this document.</p> <p>For example, a name of
     515     * "/myScene" will produce the URI svgSalamander:/myScene.
     516     * "/maps/canada/toronto" will produce svgSalamander:/maps/canada/toronto.
     517     * If this second document then contained the href "../uk/london", it would
     518     * resolve by default to svgSalamander:/maps/uk/london. That is, SVG
     519     * Salamander defines the URI scheme svgSalamander for it's own internal use
     520     * and uses it for uniquely identfying documents loaded by stream.</p> <p>If
     521     * you need to link to documents outside of this scheme, you can either
     522     * supply full hrefs (eg, href="url(http://www.kitfox.com/index.html)") or
     523     * put the xml:base attribute in a tag to change the defaultbase URIs are
     524     * resolved against</p> <p>If a name does not start with the character '/',
     525     * it will be automatically prefixed to it.</p>
    491526     * @param forceLoad - if true, ignore cached diagram and reload
    492527     *
     
    498533        //Synthesize URI for this stream
    499534        URI uri = getStreamBuiltURI(name);
    500         if (uri == null) return null;
    501         if (loadedDocs.containsKey(uri) && !forceLoad) return uri;
    502        
     535        if (uri == null)
     536        {
     537            return null;
     538        }
     539        if (loadedDocs.containsKey(uri) && !forceLoad)
     540        {
     541            return uri;
     542        }
     543
    503544        return loadSVG(uri, new InputSource(reader));
    504545    }
    505    
     546
    506547    /**
    507548     * Synthesize a URI for an SVGDiagram constructed from a stream.
     549     *
    508550     * @param name - Name given the document constructed from a stream.
    509551     */
    510552    public URI getStreamBuiltURI(String name)
    511553    {
    512         if (name == null || name.length() == 0) return null;
    513        
    514         if (name.charAt(0) != '/') name = '/' + name;
    515        
     554        if (name == null || name.length() == 0)
     555        {
     556            return null;
     557        }
     558
     559        if (name.charAt(0) != '/')
     560        {
     561            name = '/' + name;
     562        }
     563
    516564        try
    517565        {
    518566            //Dummy URL for SVG documents built from image streams
    519567            return new URI(INPUTSTREAM_SCHEME, name, null);
    520         }
    521         catch (Exception e)
    522         {
    523             e.printStackTrace();
    524             return null;
    525         }
    526     }
    527    
     568        } catch (Exception e)
     569        {
     570            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     571                "Could not parse", e);
     572            return null;
     573        }
     574    }
     575
    528576    private XMLReader getXMLReaderCached() throws SAXException
    529577    {
     
    534582        return cachedReader;
    535583    }
    536    
    537 //    protected URI loadSVG(URI xmlBase, InputStream is)
     584
    538585    protected URI loadSVG(URI xmlBase, InputSource is)
    539586    {
    540587        // Use an instance of ourselves as the SAX event handler
    541588        SVGLoader handler = new SVGLoader(xmlBase, this, verbose);
    542        
     589
    543590        //Place this docment in the universe before it is completely loaded
    544591        // so that the load process can refer to references within it's current
    545592        // document
    546 //System.err.println("SVGUniverse: loading dia " + xmlBase);
    547593        loadedDocs.put(xmlBase, handler.getLoadedDiagram());
    548        
    549         // Use the default (non-validating) parser
    550 //        SAXParserFactory factory = SAXParserFactory.newInstance();
    551 //        factory.setValidating(false);
    552 //        factory.setNamespaceAware(true);
    553        
     594
    554595        try
    555596        {
     
    564605                        return new InputSource(new ByteArrayInputStream(new byte[0]));
    565606                    }
    566                 }
    567             );
     607                });
    568608            reader.setContentHandler(handler);
    569609            reader.parse(is);
    570            
    571 //            SAXParser saxParser = factory.newSAXParser();
    572 //            saxParser.parse(new InputSource(new BufferedReader(is)), handler);
     610
     611            handler.getLoadedDiagram().updateTime(curTime);
    573612            return xmlBase;
    574         }
    575         catch (SAXParseException sex)
     613        } catch (SAXParseException sex)
    576614        {
    577615            System.err.println("Error processing " + xmlBase);
    578616            System.err.println(sex.getMessage());
    579            
     617
    580618            loadedDocs.remove(xmlBase);
    581619            return null;
    582         }
    583         catch (Throwable t)
    584         {
    585             t.printStackTrace();
    586         }
    587        
     620        } catch (Throwable e)
     621        {
     622            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     623                "Could not load SVG " + xmlBase, e);
     624        }
     625
    588626        return null;
    589627    }
    590    
    591     public static void main(String argv[])
    592     {
    593         try
    594         {
    595             URL url = new URL("svgSalamander", "localhost", -1, "abc.svg",
    596                     new URLStreamHandler()
    597             {
    598                 protected URLConnection openConnection(URL u)
    599                 {
    600                     return null;
    601                 }
    602             }
    603             );
    604 //            URL url2 = new URL("svgSalamander", "localhost", -1, "abc.svg");
    605            
    606             //Investigate URI resolution
    607             URI uriA, uriB, uriC, uriD, uriE;
    608            
    609             uriA = new URI("svgSalamander", "/names/mySpecialName", null);
    610 //            uriA = new URI("http://www.kitfox.com/salamander");
    611 //            uriA = new URI("svgSalamander://mySpecialName/grape");
    612             System.err.println(uriA.toString());
    613             System.err.println(uriA.getScheme());
    614            
    615             uriB = uriA.resolve("#begin");
    616             System.err.println(uriB.toString());
    617            
    618             uriC = uriA.resolve("tree#boing");
    619             System.err.println(uriC.toString());
    620            
    621             uriC = uriA.resolve("../tree#boing");
    622             System.err.println(uriC.toString());
    623         }
    624         catch (Exception e)
    625         {
    626             e.printStackTrace();
    627         }
    628     }
    629 
     628
     629//    public static void main(String argv[])
     630//    {
     631//        try
     632//        {
     633//            URL url = new URL("svgSalamander", "localhost", -1, "abc.svg",
     634//                    new URLStreamHandler()
     635//            {
     636//                protected URLConnection openConnection(URL u)
     637//                {
     638//                    return null;
     639//                }
     640//            }
     641//            );
     642////            URL url2 = new URL("svgSalamander", "localhost", -1, "abc.svg");
     643//           
     644//            //Investigate URI resolution
     645//            URI uriA, uriB, uriC, uriD, uriE;
     646//           
     647//            uriA = new URI("svgSalamander", "/names/mySpecialName", null);
     648////            uriA = new URI("http://www.kitfox.com/salamander");
     649////            uriA = new URI("svgSalamander://mySpecialName/grape");
     650//            System.err.println(uriA.toString());
     651//            System.err.println(uriA.getScheme());
     652//           
     653//            uriB = uriA.resolve("#begin");
     654//            System.err.println(uriB.toString());
     655//           
     656//            uriC = uriA.resolve("tree#boing");
     657//            System.err.println(uriC.toString());
     658//           
     659//            uriC = uriA.resolve("../tree#boing");
     660//            System.err.println(uriC.toString());
     661//        }
     662//        catch (Exception e)
     663//        {
     664//            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
     665//                "Could not parse", e);
     666//        }
     667//    }
    630668    public boolean isVerbose()
    631669    {
     
    637675        this.verbose = verbose;
    638676    }
    639    
     677
    640678    /**
    641679     * Uses serialization to duplicate this universe.
     
    650688        ByteArrayInputStream bin = new ByteArrayInputStream(bs.toByteArray());
    651689        ObjectInputStream is = new ObjectInputStream(bin);
    652         SVGUniverse universe = (SVGUniverse)is.readObject();
     690        SVGUniverse universe = (SVGUniverse) is.readObject();
    653691        is.close();
    654692
Note: See TracChangeset for help on using the changeset viewer.