Changeset 9965 in josm for trunk/src/org/openstreetmap/josm


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
Files:
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r9911 r9965  
    14341434     */
    14351435    private void removeObsolete(int loadedVersion) {
    1436         // drop this block march 2016
    1437         // update old style JOSM server links to use zip now, see #10581, #12189
    1438         // actually also cache and mirror entries should be cleared
    1439         if (loadedVersion < 9216) {
    1440             for (String key: new String[]{"mappaint.style.entries", "taggingpreset.entries"}) {
    1441                 Collection<Map<String, String>> data = getListOfStructs(key, (Collection<Map<String, String>>) null);
    1442                 if (data != null) {
    1443                     List<Map<String, String>> newlist = new ArrayList<>();
    1444                     boolean modified = false;
    1445                     for (Map<String, String> map : data) {
    1446                          Map<String, String> newmap = new LinkedHashMap<>();
    1447                          for (Entry<String, String> entry : map.entrySet()) {
    1448                              String val = entry.getValue();
    1449                              String mkey = entry.getKey();
    1450                              if ("url".equals(mkey) && val.contains("josm.openstreetmap.de/josmfile") && !val.contains("zip=1")) {
    1451                                  val += "&zip=1";
    1452                                  modified = true;
    1453                              }
    1454                              if ("url".equals(mkey) && val.contains("http://josm.openstreetmap.de/josmfile")) {
    1455                                  val = val.replace("http://", "https://");
    1456                                  modified = true;
    1457                              }
    1458                              newmap.put(mkey, val);
    1459                          }
    1460                          newlist.add(newmap);
    1461                     }
    1462                     if (modified) {
    1463                         putListOfStructs(key, newlist);
    1464                     }
    1465                 }
    1466             }
    1467         }
    14681436        /* drop in October 2016 */
    14691437        if (loadedVersion < 9715) {
     
    14911459            }
    14921460        }
     1461        // drop in November 2016
     1462        if (loadedVersion < 9965) {
     1463            Setting<?> setting = settingsMap.get("mappaint.style.entries");
     1464            if (setting != null && setting instanceof MapListSetting) {
     1465                List<Map<String, String>> l = new LinkedList<>();
     1466                boolean modified = false;
     1467                for (Map<String, String> map: ((MapListSetting) setting).getValue()) {
     1468                    String url = map.get("url");
     1469                    if (url != null && url.contains("josm.openstreetmap.de/josmfile?page=Styles/LegacyStandard")) {
     1470                        modified = true;
     1471                    } else {
     1472                        l.add(map);
     1473                    }
     1474                }
     1475                if (modified) {
     1476                    putListOfStructs("mappaint.style.entries", l);
     1477                }
     1478            }
     1479        }
    14931480
    14941481        for (String key : OBSOLETE_PREF_KEYS) {
  • trunk/src/org/openstreetmap/josm/gui/dialogs/InspectPrimitiveDialog.java

    r9284 r9965  
    3939import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    4040import org.openstreetmap.josm.gui.mappaint.Cascade;
    41 import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement;
    4241import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    4342import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
     
    4746import org.openstreetmap.josm.gui.mappaint.StyleSource;
    4847import org.openstreetmap.josm.gui.mappaint.mapcss.MapCSSStyleSource;
    49 import org.openstreetmap.josm.gui.mappaint.xml.XmlStyleSource;
     48import org.openstreetmap.josm.gui.mappaint.styleelement.StyleElement;
    5049import org.openstreetmap.josm.gui.util.GuiHelper;
    5150import org.openstreetmap.josm.gui.widgets.JosmTextArea;
     
    423422
    424423    private static String getSort(StyleSource s) {
    425         if (s instanceof XmlStyleSource) {
    426             return tr("xml");
    427         } else if (s instanceof MapCSSStyleSource) {
     424        if (s instanceof MapCSSStyleSource) {
    428425            return tr("mapcss");
    429426        } else {
  • 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;
  • trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java

    r9570 r9965  
    13901390                }
    13911391                readFile();
     1392                for (Iterator<ExtendedSourceEntry> it = sources.iterator(); it.hasNext();) {
     1393                    if ("xml".equals(it.next().styleType)) {
     1394                        Main.debug("Removing XML source entry");
     1395                        it.remove();
     1396                    }
     1397                }
    13921398            } catch (IOException e) {
    13931399                if (canceled)
Note: See TracChangeset for help on using the changeset viewer.