Ignore:
Timestamp:
2011-02-26T00:35:10+01:00 (13 years ago)
Author:
framm
Message:

Changed the way in which JOSM handles imagery layer blacklisting. Instead
of a hard-coded list of Google URLs, we now parse the server's
/api/capabilities response which is expected to look like this:

<osm version="0.6" generator="OpenStreetMap server">

<api>

<version minimum="0.6" maximum="0.6"/>
<area maximum="0.25"/>
<tracepoints per_page="5000"/>
<waynodes maximum="2000"/>
<changesets maximum_elements="50000"/>
<timeout seconds="300"/>

</api>
<policy>

<imagery>

<blacklist regex=".*\.google\.com/.*"/>
<blacklist regex=".*209\.85\.2\d\d.*"/>
<blacklist regex=".*209\.85\.1[3-9]\d.*"/>
<blacklist regex=".*209\.85\.12[89].*"/>

</imagery>

</policy>

</osm>

JOSM will now try to establish an API connection when started, so that
it knows about blacklisted layers. It will also re-read the list when
the URL is changed in the preferences, and if any prohibited layers are
active they will be removed.

For an interim period, JOSM still uses the four regular expressions
listed above whenever the server API URL is *.openstreetmap.org and
the API does not send any blacklist entries. It is expected that the
API will soon return proper blacklist entries.

Things that could be improved:

  1. Establish a general listener system where components can register

their interest in a change of the configured OSM server. Currently
we have to plug through to the gui layer (Main.main.mapView) from
the base comms layer (OsmApi) which is ugly.

  1. Establish a new class of blacklist which works by IP number and not

just regular expression, so that you can say "any host name that resolves
to this IP is blacklisted".

  1. Track all layers that were used in editing a data set, and refuse

uploading if the upload URL bans any of these layers.

File:
1 edited

Legend:

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

    r3878 r3934  
    44import java.util.ArrayList;
    55import java.util.Collection;
     6
     7import org.openstreetmap.josm.io.OsmApi;
    68
    79/**
     
    2729        }
    2830    }
    29 
    30     private final static String[] BLACKLIST_REGEXES = {
    31         // These entries are for Google tile servers (names and IPV4 numbers)
    32         ".*\\.google\\.com/.*",
    33         ".*209\\.85\\.2\\d\\d.*",
    34         ".*209\\.85\\.1[3-9]\\d.*",
    35         ".*209\\.85\\.12[89].*"
    36     };
    3731
    3832    String name;
     
    4337    double pixelPerDegree = 0.0;
    4438    int maxZoom = 0;
    45     private boolean blacklisted = false;
    4639
    4740    public ImageryInfo(String name) {
     
    173166    public void setUrl(String url) {
    174167
    175         // determine if URL is on blacklist and flag accordingly.
    176         blacklisted = false;
    177         for (String blacklistRegex : BLACKLIST_REGEXES) {
    178             if (url.matches(blacklistRegex)) {
    179                 blacklisted = true;
    180                 System.err.println("layer '" + name + "' uses blacklisted URL");
    181                 break;
    182             }
    183         }
    184 
    185168        for (ImageryType type : ImageryType.values()) {
    186169            if (url.startsWith(type.getUrlString() + ":")) {
     
    252235    }
    253236
     237    /**
     238     * Returns true if this layer's URL is matched by one of the regular
     239     * expressions kept by the current OsmApi instance.
     240     */
    254241    public boolean isBlacklisted() {
    255         return blacklisted;
     242        return OsmApi.getOsmApi().getCapabilities().isOnImageryBlacklist(this.url);
    256243    }
    257244}
Note: See TracChangeset for help on using the changeset viewer.