Index: trunk/src/org/openstreetmap/josm/Main.java
===================================================================
--- trunk/src/org/openstreetmap/josm/Main.java	(revision 3930)
+++ trunk/src/org/openstreetmap/josm/Main.java	(revision 3934)
@@ -71,4 +71,5 @@
 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference;
 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences;
+import org.openstreetmap.josm.io.OsmApi;
 import org.openstreetmap.josm.plugins.PluginHandler;
 import org.openstreetmap.josm.tools.I18n;
@@ -211,4 +212,14 @@
         isOpenjdk = System.getProperty("java.vm.name").toUpperCase().indexOf("OPENJDK") != -1;
         platform.startupHook();
+
+        // We try to establish an API connection early, so that any API 
+        // capabilities are already known to the editor instance. However
+        // if it goes wrong that's not critical at this stage.
+        try {
+            OsmApi.getOsmApi().initialize(null);
+        } catch (Exception x) {
+            // ignore any exception here.
+        }
+
         contentPanePrivate.add(panel, BorderLayout.CENTER);
         panel.add(gettingStarted, BorderLayout.CENTER);
@@ -234,4 +245,5 @@
         toolbar.control.updateUI();
         contentPanePrivate.updateUI();
+
     }
 
Index: trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java	(revision 3930)
+++ trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java	(revision 3934)
@@ -4,4 +4,6 @@
 import java.util.ArrayList;
 import java.util.Collection;
+
+import org.openstreetmap.josm.io.OsmApi;
 
 /**
@@ -27,12 +29,4 @@
         }
     }
-
-    private final static String[] BLACKLIST_REGEXES = {
-        // These entries are for Google tile servers (names and IPV4 numbers)
-        ".*\\.google\\.com/.*",
-        ".*209\\.85\\.2\\d\\d.*",
-        ".*209\\.85\\.1[3-9]\\d.*",
-        ".*209\\.85\\.12[89].*"
-    };
 
     String name;
@@ -43,5 +37,4 @@
     double pixelPerDegree = 0.0;
     int maxZoom = 0;
-    private boolean blacklisted = false;
 
     public ImageryInfo(String name) {
@@ -173,14 +166,4 @@
     public void setUrl(String url) {
 
-        // determine if URL is on blacklist and flag accordingly.
-        blacklisted = false;
-        for (String blacklistRegex : BLACKLIST_REGEXES) {
-            if (url.matches(blacklistRegex)) {
-                blacklisted = true;
-                System.err.println("layer '" + name + "' uses blacklisted URL");
-                break;
-            }
-        }
-
         for (ImageryType type : ImageryType.values()) {
             if (url.startsWith(type.getUrlString() + ":")) {
@@ -252,6 +235,10 @@
     }
 
+    /**
+     * Returns true if this layer's URL is matched by one of the regular
+     * expressions kept by the current OsmApi instance.
+     */
     public boolean isBlacklisted() {
-        return blacklisted;
+        return OsmApi.getOsmApi().getCapabilities().isOnImageryBlacklist(this.url);
     }
 }
Index: trunk/src/org/openstreetmap/josm/gui/preferences/server/OsmApiUrlInputPanel.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/preferences/server/OsmApiUrlInputPanel.java	(revision 3930)
+++ trunk/src/org/openstreetmap/josm/gui/preferences/server/OsmApiUrlInputPanel.java	(revision 3934)
@@ -32,4 +32,5 @@
 import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator;
 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator;
+import org.openstreetmap.josm.io.OsmApi;
 import org.openstreetmap.josm.tools.ImageProvider;
 
@@ -136,4 +137,5 @@
      */
     public void saveToPreferences() {
+        String old_url = Main.pref.get("osm-server.url", null);
         if (cbUseDefaultServerUrl.isSelected()) {
             Main.pref.put("osm-server.url", null);
@@ -143,5 +145,15 @@
             Main.pref.put("osm-server.url", tfOsmServerUrl.getText().trim());
         }
-
+        String new_url = Main.pref.get("osm-server.url", null);
+
+        // When API URL changes, re-initialize API connection so we may adjust
+        // server-dependent settings.
+        if ((old_url == null && new_url != null) || (old_url != null && !old_url.equals(new_url))) {
+            try {
+                OsmApi.getOsmApi().initialize(null);
+            } catch (Exception x) {
+                // ignore;
+            }
+        }
     }
 
Index: trunk/src/org/openstreetmap/josm/io/Capabilities.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/Capabilities.java	(revision 3930)
+++ trunk/src/org/openstreetmap/josm/io/Capabilities.java	(revision 3934)
@@ -4,15 +4,45 @@
 import static org.openstreetmap.josm.tools.I18n.tr;
 
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 
 /**
  * Represents the server capabilities
  *
+ * Example capabilites document:
+ * 
+ * <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>
+ * 
+ * This class is used in conjunction with a very primitive parser
+ * and simply stuffs the each tag and its attributes into a hash
+ * of hashes, with the exception of the "blacklist" tag which gets
+ * a list of its own. The DOM hierarchy is disregarded.
  */
 public class Capabilities {
-    private  HashMap<String, HashMap<String,String>> capabilities;
+
+    private HashMap<String, HashMap<String,String>> capabilities;
+    private ArrayList<String> imageryBlacklist;
 
     public Capabilities() {
-        capabilities = new HashMap<String, HashMap<String,String>>();
+        clear();
     }
 
@@ -32,5 +62,5 @@
 
     /**
-     * replies the value of configuration item in the capabilities as
+     * returns the value of configuration item in the capabilities as
      * double value
      *
@@ -53,17 +83,21 @@
 
     public void put(String element, String attribute, String value) {
-        if (capabilities == null) {
-            capabilities = new HashMap<String, HashMap<String,String>>();
+        if (element.equals("blacklist")) {
+            if (attribute.equals("regex")) {
+                imageryBlacklist.add(value);
+            }
+        } else {
+            if (! capabilities.containsKey(element))  {
+                HashMap<String,String> h = new HashMap<String, String>();
+                capabilities.put(element, h);
+            }
+            HashMap<String, String> e = capabilities.get(element);
+            e.put(attribute, value);
         }
-        if (! capabilities.containsKey(element))  {
-            HashMap<String,String> h = new HashMap<String, String>();
-            capabilities.put(element, h);
-        }
-        HashMap<String, String> e = capabilities.get(element);
-        e.put(attribute, value);
     }
 
     public void clear() {
         capabilities = new HashMap<String, HashMap<String,String>>();
+        imageryBlacklist = new ArrayList<String>();
     }
 
@@ -74,5 +108,5 @@
 
     /**
-     * Replies the max number of objects in a changeset. -1 if either the capabilities
+     * Returns the max number of objects in a changeset. -1 if either the capabilities
      * don't include this parameter or if the parameter value is illegal (not a number,
      * a negative number)
@@ -95,3 +129,26 @@
         }
     }
+
+    /**
+     * checks if the given URL is blacklisted by one of the of the 
+     * regular expressions.
+     */
+
+    public boolean isOnImageryBlacklist(String url)
+    {
+        for (String blacklistRegex : imageryBlacklist) {
+            if (url.matches(blacklistRegex)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /** 
+     * returns the full list of blacklist regular expressions.
+     */
+    public List<String> getImageryBlacklist()
+    {
+        return Collections.unmodifiableList(imageryBlacklist);
+    }
 }
Index: trunk/src/org/openstreetmap/josm/io/OsmApi.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmApi.java	(revision 3930)
+++ trunk/src/org/openstreetmap/josm/io/OsmApi.java	(revision 3934)
@@ -32,4 +32,6 @@
 import org.openstreetmap.josm.data.osm.OsmPrimitive;
 import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
+import org.openstreetmap.josm.gui.layer.Layer;
+import org.openstreetmap.josm.gui.layer.ImageryLayer;
 import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
 import org.openstreetmap.josm.gui.progress.ProgressMonitor;
@@ -157,5 +159,5 @@
         cancel = false;
         try {
-            String s = sendRequest("GET", "capabilities", null,monitor, false);
+            String s = sendRequest("GET", "capabilities", null, monitor, false);
             InputSource inputSource = new InputSource(new StringReader(s));
             SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new CapabilitiesParser());
@@ -173,4 +175,31 @@
             osmWriter.setVersion(version);
             initialized = true;
+
+            /* This is an interim solution for openstreetmap.org not currently 
+             * transmitting their imagery blacklist in the capabilities call.
+             * remove this as soon as openstreetmap.org adds blacklists. */
+            if (this.serverUrl.matches(".*openstreetmap.org/api.*") && capabilities.getImageryBlacklist().isEmpty())
+            {
+                capabilities.put("blacklist", "regex", ".*\\.google\\.com/.*");
+                capabilities.put("blacklist", "regex", ".*209\\.85\\.2\\d\\d.*");
+                capabilities.put("blacklist", "regex", ".*209\\.85\\.1[3-9]\\d.*");
+                capabilities.put("blacklist", "regex", ".*209\\.85\\.12[89].*");
+            }
+
+            /* This checks if there are any layers currently displayed that
+             * are now on the blacklist, and removes them. This is a rare
+             * situaton - probably only occurs if the user changes the API URL
+             * in the preferences menu. Otherwise they would not have been able
+             * to load the layers in the first place becuase they would have
+             * been disabled! */
+            if (Main.main.isDisplayingMapView()) {
+                for (Layer l : Main.map.mapView.getLayersOfType(ImageryLayer.class)) {
+                    if (((ImageryLayer) l).getInfo().isBlacklisted()) {
+                        System.out.println(tr("Removed layer {0} because it is not allowed by the configured API.", l.getName()));
+                        Main.main.removeLayer(l);
+                    }
+                }
+            }
+
         } catch(IOException e) {
             initialized = false;
