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


Ignore:
Timestamp:
2011-10-20T14:12:47+02:00 (13 years ago)
Author:
Don-vip
Message:

fix #6982 - broken TMS url leads to exceptions

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java

    r4172 r4531  
    55
    66import java.awt.event.ActionEvent;
     7
     8import javax.swing.JOptionPane;
    79
    810import org.openstreetmap.josm.Main;
     
    2527    public void actionPerformed(ActionEvent e) {
    2628        if (!isEnabled()) return;
    27         Main.main.addLayer(ImageryLayer.create(info));
     29        try {
     30            Main.main.addLayer(ImageryLayer.create(info));
     31        } catch (IllegalArgumentException ex) {
     32            if (ex.getMessage() == null || ex.getMessage().isEmpty()) {
     33                throw ex;
     34            } else {
     35                JOptionPane.showMessageDialog(Main.parent,
     36                        ex.getMessage(), tr("Error"),
     37                        JOptionPane.ERROR_MESSAGE);
     38            }
     39        }
    2840    }
    2941
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java

    r4492 r4531  
    11// License: GPL. See LICENSE file for details.
    22package org.openstreetmap.josm.gui.bbox;
     3
     4import static org.openstreetmap.josm.tools.I18n.tr;
    35
    46import java.awt.Color;
     
    1820import java.util.Vector;
    1921import java.util.concurrent.CopyOnWriteArrayList;
     22
     23import javax.swing.JOptionPane;
    2024
    2125import org.openstreetmap.gui.jmapviewer.Coordinate;
     
    3741import org.openstreetmap.josm.data.preferences.StringProperty;
    3842import org.openstreetmap.josm.gui.layer.TMSLayer;
    39 import org.openstreetmap.josm.tools.OpenBrowser;
    4043
    4144public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser{
     
    114117                    continue;
    115118                }
    116                 TileSource source = TMSLayer.getTileSource(info);
    117                 if (source != null) {
    118                     sources.add(source);
     119                try {
     120                    TileSource source = TMSLayer.getTileSource(info);
     121                    if (source != null) {
     122                        sources.add(source);
     123                    }
     124                } catch (IllegalArgumentException ex) {
     125                    if (ex.getMessage() != null && !ex.getMessage().isEmpty()) {
     126                        JOptionPane.showMessageDialog(Main.parent,
     127                                ex.getMessage(), tr("Warning"),
     128                                JOptionPane.WARNING_MESSAGE);
     129                    }
    119130                }
    120131            }
  • trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java

    r4529 r4531  
    2424import java.util.List;
    2525import java.util.Map;
     26import java.util.regex.Matcher;
     27import java.util.regex.Pattern;
    2628
    2729import javax.swing.AbstractAction;
     
    222224    }
    223225
    224     public static TileSource getTileSource(ImageryInfo info) {
     226    public static TileSource getTileSource(ImageryInfo info) throws IllegalArgumentException {
    225227        if (info.getImageryType() == ImageryType.TMS) {
     228            checkUrl(info.getUrl());
    226229            TMSTileSource t = new TemplatedTMSTileSource(info.getName(), info.getUrl(), info.getMinZoom(), info.getMaxZoom());
    227230            info.setAttribution(t);
     
    232235            return new ScanexTileSource(info.getUrl());
    233236        return null;
     237    }
     238   
     239    public static void checkUrl(String url) throws IllegalArgumentException {
     240        if (url == null) {
     241            throw new IllegalArgumentException();
     242        } else {
     243            Matcher m = Pattern.compile("\\{[^}]*\\}").matcher(url);
     244            while (m.find()) {
     245                boolean isSupportedPattern = false;
     246                for (String pattern : TemplatedTMSTileSource.ALL_PATTERNS) {
     247                    if (m.group().matches(pattern)) {
     248                        isSupportedPattern = true;
     249                        break;
     250                    }
     251                }
     252                if (!isSupportedPattern) {
     253                    throw new IllegalArgumentException(tr("{0} is not a valid TMS argument. Please check this server URL:\n{1}", m.group(), url));
     254                }
     255            }
     256        }
    234257    }
    235258
  • trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java

    r4524 r4531  
    7070import org.openstreetmap.josm.data.imagery.ImageryInfo;
    7171import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
     72import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
    7273import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
    7374import org.openstreetmap.josm.data.imagery.OffsetBookmark;
     
    626627                        JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    627628                if (answer == JOptionPane.OK_OPTION) {
    628                     model.addRow(new ImageryInfo(p.getUrlName(), p.getUrl()));
     629                    try {
     630                        ImageryInfo info = new ImageryInfo(p.getUrlName(), p.getUrl());
     631                        if (ImageryType.TMS.equals(info.getImageryType())) {
     632                            TMSLayer.checkUrl(info.getUrl());
     633                        }
     634                        model.addRow(info);
     635                    } catch (IllegalArgumentException ex) {
     636                        if (ex.getMessage() == null || ex.getMessage().isEmpty()) {
     637                            throw ex;
     638                        } else {
     639                            JOptionPane.showMessageDialog(Main.parent,
     640                                    ex.getMessage(), tr("Error"),
     641                                    JOptionPane.ERROR_MESSAGE);
     642                        }
     643                    }
    629644                }
    630645            }
Note: See TracChangeset for help on using the changeset viewer.