Ignore:
Timestamp:
2010-01-12T20:02:54+01:00 (14 years ago)
Author:
Gubaer
Message:

fixed NPE with new location for elemstyles.xml, see r2827

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java

    r2827 r2832  
    11package org.openstreetmap.josm.gui.mappaint;
    22
     3import static org.openstreetmap.josm.tools.I18n.tr;
     4
     5import java.io.IOException;
    36import java.util.Collection;
    47import java.util.Collections;
     
    1215import org.openstreetmap.josm.tools.ImageProvider;
    1316import org.xml.sax.InputSource;
     17import org.xml.sax.SAXException;
    1418import org.xml.sax.XMLReader;
    1519import org.xml.sax.helpers.XMLReaderFactory;
     
    3135        {
    3236            String[] a;
    33             if(fileset.indexOf("=") >= 0)
     37            if(fileset.indexOf("=") >= 0) {
    3438                a = fileset.split("=", 2);
    35             else
     39            } else {
    3640                a = new String[] {"", fileset};
     41            }
    3742
    3843            /* non-prefixed path is generic path, always take it */
    39             if(a[0].length() == 0 || styleName.equals(a[0]))
     44            if(a[0].length() == 0 || styleName.equals(a[0])) {
    4045                dirs.add(a[1]);
     46            }
    4147        }
    4248        ImageIcon i = ImageProvider.getIfAvailable(dirs, "mappaint."+styleName, null, name);
     
    6167
    6268        Collection<String> files = Main.pref.getCollection("mappaint.style.sources", Collections.<String>emptySet());
    63         if(Main.pref.getBoolean("mappaint.style.enable-defaults", true))
    64         {
     69        if (Main.pref.getBoolean("mappaint.style.enable-defaults", true)) {
    6570            LinkedList<String> f = new LinkedList<String>();
    6671            f.add("resource://data/elemstyles.xml");
     
    6974        }
    7075
    71         for(String fileset : files)
    72         {
     76        for (String file : files) {
    7377            String[] a = null;
    74             try
    75             {
    76                 if(fileset.indexOf("=") >= 0)
    77                     a = fileset.split("=", 2);
    78                 else
    79                     a = new String[] {null, fileset};
     78            try {
     79                if (file.indexOf("=") >= 0) {
     80                    a = file.split("=", 2);
     81                } else {
     82                    a = new String[] { null, file };
     83                }
    8084                XMLReader xmlReader = XMLReaderFactory.createXMLReader();
    8185                ElemStyleHandler handler = new ElemStyleHandler(a[0]);
    8286                xmlReader.setContentHandler(handler);
    8387                xmlReader.setErrorHandler(handler);
    84                 xmlReader.parse(new InputSource(new MirroredInputStream(a[1])));
    85             }
    86             catch (Exception e)
    87             {
    88                 System.out.println("Mappaint-Style \"" + a[0] + "\" file \"" + a[1] + "\"");
    89                 System.out.println("Mappaint-Style problems: " + e);
     88                MirroredInputStream in = new MirroredInputStream(a[1]);
     89                xmlReader.parse(new InputSource(in));
     90            } catch(IOException e) {
     91                System.err.println(tr("Warning: failed to load Mappaint-Styles from ''{0}''. Exception was: {1}", a[1], e.toString()));
     92                e.printStackTrace();
     93            } catch(SAXException e) {
     94                System.err.println(tr("Warning: failed to parse Mappaint-Styles from ''{0}''. Exception was: {1}", a[1], e.toString()));
    9095                e.printStackTrace();
    9196            }
     
    9398        iconDirs = null;
    9499    }
    95 
    96100}
Note: See TracChangeset for help on using the changeset viewer.