Ignore:
Timestamp:
2016-03-12T00:10:24+01:00 (8 years ago)
Author:
Don-vip
Message:

fix #12282 - drop XML mappaint support - keep XML detection in order to warn users and let them upgrade to MapCSS, with link to documentation

Location:
trunk/src/org/openstreetmap/josm/gui/mappaint
Files:
1 deleted
1 edited

Legend:

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

    r9799 r9965  
    1818
    1919import javax.swing.ImageIcon;
     20import javax.swing.JOptionPane;
    2021import javax.swing.SwingUtilities;
    2122
     
    2526import org.openstreetmap.josm.data.osm.Node;
    2627import org.openstreetmap.josm.data.osm.Tag;
     28import org.openstreetmap.josm.gui.HelpAwareOptionPane;
    2729import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     30import org.openstreetmap.josm.gui.help.HelpUtil;
    2831import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    2932import org.openstreetmap.josm.gui.mappaint.styleelement.MapImage;
    3033import org.openstreetmap.josm.gui.mappaint.styleelement.NodeElement;
    3134import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement;
    32 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource;
    3335import org.openstreetmap.josm.gui.preferences.SourceEntry;
    3436import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference.MapPaintPrefHelper;
    3537import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    3638import org.openstreetmap.josm.io.CachedFile;
     39import org.openstreetmap.josm.io.IllegalDataException;
    3740import org.openstreetmap.josm.tools.ImageProvider;
    3841import org.openstreetmap.josm.tools.Utils;
     
    4649 */
    4750public final class MapPaintStyles {
     51
     52    /** To remove in November 2016 */
     53    private static final String XML_STYLE_MIME_TYPES =
     54             "application/xml, text/xml, text/plain; q=0.8, application/zip, application/octet-stream; q=0.5";
    4855
    4956    private static ElemStyles styles = new ElemStyles();
     
    280287
    281288    private static StyleSource fromSourceEntry(SourceEntry entry) {
    282         CachedFile cf = null;
    283         try {
    284             Set<String> mimes = new HashSet<>();
    285             mimes.addAll(Arrays.asList(XmlStyleSource.XML_STYLE_MIME_TYPES.split(", ")));
    286             mimes.addAll(Arrays.asList(MapCSSStyleSource.MAPCSS_STYLE_MIME_TYPES.split(", ")));
    287             cf = new CachedFile(entry.url).setHttpAccept(Utils.join(", ", mimes));
     289        // TODO: Method to clean up in November 2016: remove XML detection completely
     290        Set<String> mimes = new HashSet<>(Arrays.asList(MapCSSStyleSource.MAPCSS_STYLE_MIME_TYPES.split(", ")));
     291        mimes.addAll(Arrays.asList(XML_STYLE_MIME_TYPES.split(", ")));
     292        try (CachedFile cf = new CachedFile(entry.url).setHttpAccept(Utils.join(", ", mimes))) {
    288293            String zipEntryPath = cf.findZipEntryPath("mapcss", "style");
    289294            if (zipEntryPath != null) {
     
    293298            }
    294299            zipEntryPath = cf.findZipEntryPath("xml", "style");
    295             if (zipEntryPath != null)
    296                 return new XmlStyleSource(entry);
     300            if (zipEntryPath != null || Utils.hasExtension(entry.url, "xml"))
     301                throw new IllegalDataException("XML style");
    297302            if (Utils.hasExtension(entry.url, "mapcss"))
    298303                return new MapCSSStyleSource(entry);
    299             if (Utils.hasExtension(entry.url, "xml"))
    300                 return new XmlStyleSource(entry);
    301             else {
    302                 try (InputStreamReader reader = new InputStreamReader(cf.getInputStream(), StandardCharsets.UTF_8)) {
    303                     WHILE: while (true) {
    304                         int c = reader.read();
    305                         switch (c) {
    306                             case -1:
    307                                 break WHILE;
    308                             case ' ':
    309                             case '\t':
    310                             case '\n':
    311                             case '\r':
    312                                 continue;
    313                             case '<':
    314                                 return new XmlStyleSource(entry);
    315                             default:
    316                                 return new MapCSSStyleSource(entry);
    317                         }
     304            try (InputStreamReader reader = new InputStreamReader(cf.getInputStream(), StandardCharsets.UTF_8)) {
     305                WHILE: while (true) {
     306                    int c = reader.read();
     307                    switch (c) {
     308                        case -1:
     309                            break WHILE;
     310                        case ' ':
     311                        case '\t':
     312                        case '\n':
     313                        case '\r':
     314                            continue;
     315                        case '<':
     316                            throw new IllegalDataException("XML style");
     317                        default:
     318                            return new MapCSSStyleSource(entry);
    318319                    }
    319320                }
    320                 Main.warn("Could not detect style type. Using default (xml).");
    321                 return new XmlStyleSource(entry);
    322             }
     321            }
     322            Main.warn("Could not detect style type. Using default (mapcss).");
     323            return new MapCSSStyleSource(entry);
    323324        } catch (IOException e) {
    324325            Main.warn(tr("Failed to load Mappaint styles from ''{0}''. Exception was: {1}", entry.url, e.toString()));
    325326            Main.error(e);
    326         } finally {
    327             if (cf != null) {
    328                 cf.close();
    329             }
     327        } catch (IllegalDataException e) {
     328            String msg = tr("JOSM does no longer support mappaint styles written in the old XML format.\nPlease update ''{0}'' to MapCSS",
     329                    entry.url);
     330            Main.error(msg);
     331            HelpAwareOptionPane.showOptionDialog(Main.parent, msg, tr("Warning"), JOptionPane.WARNING_MESSAGE,
     332                    HelpUtil.ht("/Styles/MapCSSImplementation"));
    330333        }
    331334        return null;
Note: See TracChangeset for help on using the changeset viewer.