Ignore:
Timestamp:
2011-02-26T00:35:10+01:00 (15 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/io/OsmApi.java

    r3566 r3934  
    3232import org.openstreetmap.josm.data.osm.OsmPrimitive;
    3333import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     34import org.openstreetmap.josm.gui.layer.Layer;
     35import org.openstreetmap.josm.gui.layer.ImageryLayer;
    3436import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    3537import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    157159        cancel = false;
    158160        try {
    159             String s = sendRequest("GET", "capabilities", null,monitor, false);
     161            String s = sendRequest("GET", "capabilities", null, monitor, false);
    160162            InputSource inputSource = new InputSource(new StringReader(s));
    161163            SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new CapabilitiesParser());
     
    173175            osmWriter.setVersion(version);
    174176            initialized = true;
     177
     178            /* This is an interim solution for openstreetmap.org not currently
     179             * transmitting their imagery blacklist in the capabilities call.
     180             * remove this as soon as openstreetmap.org adds blacklists. */
     181            if (this.serverUrl.matches(".*openstreetmap.org/api.*") && capabilities.getImageryBlacklist().isEmpty())
     182            {
     183                capabilities.put("blacklist", "regex", ".*\\.google\\.com/.*");
     184                capabilities.put("blacklist", "regex", ".*209\\.85\\.2\\d\\d.*");
     185                capabilities.put("blacklist", "regex", ".*209\\.85\\.1[3-9]\\d.*");
     186                capabilities.put("blacklist", "regex", ".*209\\.85\\.12[89].*");
     187            }
     188
     189            /* This checks if there are any layers currently displayed that
     190             * are now on the blacklist, and removes them. This is a rare
     191             * situaton - probably only occurs if the user changes the API URL
     192             * in the preferences menu. Otherwise they would not have been able
     193             * to load the layers in the first place becuase they would have
     194             * been disabled! */
     195            if (Main.main.isDisplayingMapView()) {
     196                for (Layer l : Main.map.mapView.getLayersOfType(ImageryLayer.class)) {
     197                    if (((ImageryLayer) l).getInfo().isBlacklisted()) {
     198                        System.out.println(tr("Removed layer {0} because it is not allowed by the configured API.", l.getName()));
     199                        Main.main.removeLayer(l);
     200                    }
     201                }
     202            }
     203
    175204        } catch(IOException e) {
    176205            initialized = false;
Note: See TracChangeset for help on using the changeset viewer.