Ignore:
Timestamp:
2017-02-02T00:08:08+01:00 (9 years ago)
Author:
Don-vip
Message:

see #14319 - update to latest version of svgSalamander (2017-01-07, patched)

File:
1 edited

Legend:

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

    r8084 r11525  
    44 * All rights reserved.
    55 *
    6  * Redistribution and use in source and binary forms, with or 
     6 * Redistribution and use in source and binary forms, with or
    77 * without modification, are permitted provided that the following
    88 * conditions are met:
    99 *
    10  *   - Redistributions of source code must retain the above 
     10 *   - Redistributions of source code must retain the above
    1111 *     copyright notice, this list of conditions and the following
    1212 *     disclaimer.
    1313 *   - Redistributions in binary form must reproduce the above
    1414 *     copyright notice, this list of conditions and the following
    15  *     disclaimer in the documentation and/or other materials 
     15 *     disclaimer in the documentation and/or other materials
    1616 *     provided with the distribution.
    1717 *
     
    2727 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
    2828 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
    29  * OF THE POSSIBILITY OF SUCH DAMAGE. 
    30  * 
     29 * OF THE POSSIBILITY OF SUCH DAMAGE.
     30 *
    3131 * Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
    3232 * projects can be found at http://www.kitfox.com
     
    3838
    3939
    40 import java.util.*;
    41 import java.net.*;
    42 import org.xml.sax.*;
    43 import org.xml.sax.helpers.DefaultHandler;
    44 
     40import java.net.URI;
     41import java.util.HashMap;
     42import java.util.HashSet;
     43import java.util.LinkedList;
    4544import java.util.logging.Level;
    4645import java.util.logging.Logger;
     46
     47import org.xml.sax.Attributes;
     48import org.xml.sax.SAXException;
     49import org.xml.sax.helpers.DefaultHandler;
    4750
    4851/**
     
    5255public class SVGLoader extends DefaultHandler
    5356{
    54     final HashMap nodeClasses = new HashMap();
     57    final HashMap<String, Class<?>> nodeClasses = new HashMap<>();
    5558    //final HashMap attribClasses = new HashMap();
    56     final LinkedList buildStack = new LinkedList();
    57 
    58     final HashSet ignoreClasses = new HashSet();
     59    final LinkedList<SVGElement> buildStack = new LinkedList<>();
     60
     61    final HashSet<String> ignoreClasses = new HashSet<>();
    5962
    6063    final SVGLoaderHelper helper;
     
    7376
    7477    final boolean verbose;
    75    
     78
    7679    /** Creates a new instance of SVGLoader */
    7780    public SVGLoader(URI xmlBase, SVGUniverse universe)
     
    7982        this(xmlBase, universe, false);
    8083    }
    81    
     84
    8285    public SVGLoader(URI xmlBase, SVGUniverse universe, boolean verbose)
    8386    {
    8487        this.verbose = verbose;
    85        
     88
    8689        diagram = new SVGDiagram(xmlBase, universe);
    8790
     
    138141        return sb.toString();
    139142    }
    140    
     143
     144    @Override
    141145    public void startDocument() throws SAXException
    142146    {
     
    146150    }
    147151
     152    @Override
    148153    public void endDocument() throws SAXException
    149154    {
     
    151156    }
    152157
     158    @Override
    153159    public void startElement(String namespaceURI, String sName, String qName, Attributes attrs) throws SAXException
    154160    {
     
    158164        }
    159165        indent++;
    160        
     166
    161167        if (skipNonSVGTagDepth != 0 || (!namespaceURI.equals("") && !namespaceURI.equals(SVGElement.SVG_NS)))
    162168        {
     
    164170            return;
    165171        }
    166        
     172
    167173        sName = sName.toLowerCase();
    168174
     
    187193
    188194        try {
    189             Class cls = (Class)obj;
     195            Class<?> cls = (Class<?>)obj;
    190196            SVGElement svgEle = (SVGElement)cls.newInstance();
    191197
    192198            SVGElement parent = null;
    193             if (buildStack.size() != 0) parent = (SVGElement)buildStack.getLast();
     199            if (buildStack.size() != 0) parent = buildStack.getLast();
    194200            svgEle.loaderStartElement(helper, attrs, parent);
    195201
     
    198204        catch (Exception e)
    199205        {
    200             Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 
     206            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
    201207                "Could not load", e);
    202208            throw new SAXException(e);
     
    205211    }
    206212
     213    @Override
    207214    public void endElement(String namespaceURI, String sName, String qName)
    208215        throws SAXException
     
    213220            System.err.println(printIndent(indent, " ") + "Ending parse of tag " + sName+ ": " + namespaceURI);
    214221        }
    215        
     222
    216223        if (skipNonSVGTagDepth != 0)
    217224        {
     
    219226            return;
    220227        }
    221        
     228
    222229        sName = sName.toLowerCase();
    223230
     
    230237
    231238        try {
    232             SVGElement svgEle = (SVGElement)buildStack.removeLast();
     239            SVGElement svgEle = buildStack.removeLast();
    233240
    234241            svgEle.loaderEndElement(helper);
     
    237244            if (buildStack.size() != 0)
    238245            {
    239                 parent = (SVGElement)buildStack.getLast();
     246                parent = buildStack.getLast();
    240247            }
    241248            //else loadRoot = (SVGElement)svgEle;
     
    253260        catch (Exception e)
    254261        {
    255             Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING, 
     262            Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
    256263                "Could not parse", e);
    257264            throw new SAXException(e);
     
    259266    }
    260267
     268    @Override
    261269    public void characters(char buf[], int offset, int len)
    262270        throws SAXException
     
    269277        if (buildStack.size() != 0)
    270278        {
    271             SVGElement parent = (SVGElement)buildStack.getLast();
     279            SVGElement parent = buildStack.getLast();
    272280            String s = new String(buf, offset, len);
    273281            parent.loaderAddText(helper, s);
     
    275283    }
    276284
     285    @Override
    277286    public void processingInstruction(String target, String data)
    278287        throws SAXException
     
    280289        //Check for external style sheet
    281290    }
    282    
     291
    283292//    public SVGElement getLoadRoot() { return loadRoot; }
    284293    public SVGDiagram getLoadedDiagram() { return diagram; }
Note: See TracChangeset for help on using the changeset viewer.