Changeset 3934 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2011-02-26T00:35:10+01:00 (14 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r3924 r3934 71 71 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference; 72 72 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 73 import org.openstreetmap.josm.io.OsmApi; 73 74 import org.openstreetmap.josm.plugins.PluginHandler; 74 75 import org.openstreetmap.josm.tools.I18n; … … 211 212 isOpenjdk = System.getProperty("java.vm.name").toUpperCase().indexOf("OPENJDK") != -1; 212 213 platform.startupHook(); 214 215 // We try to establish an API connection early, so that any API 216 // capabilities are already known to the editor instance. However 217 // if it goes wrong that's not critical at this stage. 218 try { 219 OsmApi.getOsmApi().initialize(null); 220 } catch (Exception x) { 221 // ignore any exception here. 222 } 223 213 224 contentPanePrivate.add(panel, BorderLayout.CENTER); 214 225 panel.add(gettingStarted, BorderLayout.CENTER); … … 234 245 toolbar.control.updateUI(); 235 246 contentPanePrivate.updateUI(); 247 236 248 } 237 249 -
trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java
r3878 r3934 4 4 import java.util.ArrayList; 5 5 import java.util.Collection; 6 7 import org.openstreetmap.josm.io.OsmApi; 6 8 7 9 /** … … 27 29 } 28 30 } 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 };37 31 38 32 String name; … … 43 37 double pixelPerDegree = 0.0; 44 38 int maxZoom = 0; 45 private boolean blacklisted = false;46 39 47 40 public ImageryInfo(String name) { … … 173 166 public void setUrl(String url) { 174 167 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 185 168 for (ImageryType type : ImageryType.values()) { 186 169 if (url.startsWith(type.getUrlString() + ":")) { … … 252 235 } 253 236 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 */ 254 241 public boolean isBlacklisted() { 255 return blacklisted;242 return OsmApi.getOsmApi().getCapabilities().isOnImageryBlacklist(this.url); 256 243 } 257 244 } -
trunk/src/org/openstreetmap/josm/gui/preferences/server/OsmApiUrlInputPanel.java
r3083 r3934 32 32 import org.openstreetmap.josm.gui.widgets.AbstractTextComponentValidator; 33 33 import org.openstreetmap.josm.gui.widgets.SelectAllOnFocusGainedDecorator; 34 import org.openstreetmap.josm.io.OsmApi; 34 35 import org.openstreetmap.josm.tools.ImageProvider; 35 36 … … 136 137 */ 137 138 public void saveToPreferences() { 139 String old_url = Main.pref.get("osm-server.url", null); 138 140 if (cbUseDefaultServerUrl.isSelected()) { 139 141 Main.pref.put("osm-server.url", null); … … 143 145 Main.pref.put("osm-server.url", tfOsmServerUrl.getText().trim()); 144 146 } 145 147 String new_url = Main.pref.get("osm-server.url", null); 148 149 // When API URL changes, re-initialize API connection so we may adjust 150 // server-dependent settings. 151 if ((old_url == null && new_url != null) || (old_url != null && !old_url.equals(new_url))) { 152 try { 153 OsmApi.getOsmApi().initialize(null); 154 } catch (Exception x) { 155 // ignore; 156 } 157 } 146 158 } 147 159 -
trunk/src/org/openstreetmap/josm/io/Capabilities.java
r3083 r3934 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.ArrayList; 7 import java.util.Collections; 6 8 import java.util.HashMap; 9 import java.util.List; 7 10 8 11 /** 9 12 * Represents the server capabilities 10 13 * 14 * Example capabilites document: 15 * 16 * <osm version="0.6" generator="OpenStreetMap server"> 17 * <api> 18 * <version minimum="0.6" maximum="0.6"/> 19 * <area maximum="0.25"/> 20 * <tracepoints per_page="5000"/> 21 * <waynodes maximum="2000"/> 22 * <changesets maximum_elements="50000"/> 23 * <timeout seconds="300"/> 24 * </api> 25 * <policy> 26 * <imagery> 27 * <blacklist regex=".*\.google\.com/.*"/> 28 * <blacklist regex=".*209\.85\.2\d\d.*"/> 29 * <blacklist regex=".*209\.85\.1[3-9]\d.*"/> 30 * <blacklist regex=".*209\.85\.12[89].*"/> 31 * </imagery> 32 * </policy> 33 * </osm> 34 * 35 * This class is used in conjunction with a very primitive parser 36 * and simply stuffs the each tag and its attributes into a hash 37 * of hashes, with the exception of the "blacklist" tag which gets 38 * a list of its own. The DOM hierarchy is disregarded. 11 39 */ 12 40 public class Capabilities { 13 private HashMap<String, HashMap<String,String>> capabilities; 41 42 private HashMap<String, HashMap<String,String>> capabilities; 43 private ArrayList<String> imageryBlacklist; 14 44 15 45 public Capabilities() { 16 c apabilities = new HashMap<String, HashMap<String,String>>();46 clear(); 17 47 } 18 48 … … 32 62 33 63 /** 34 * re plies the value of configuration item in the capabilities as64 * returns the value of configuration item in the capabilities as 35 65 * double value 36 66 * … … 53 83 54 84 public void put(String element, String attribute, String value) { 55 if (capabilities == null) { 56 capabilities = new HashMap<String, HashMap<String,String>>(); 85 if (element.equals("blacklist")) { 86 if (attribute.equals("regex")) { 87 imageryBlacklist.add(value); 88 } 89 } else { 90 if (! capabilities.containsKey(element)) { 91 HashMap<String,String> h = new HashMap<String, String>(); 92 capabilities.put(element, h); 93 } 94 HashMap<String, String> e = capabilities.get(element); 95 e.put(attribute, value); 57 96 } 58 if (! capabilities.containsKey(element)) {59 HashMap<String,String> h = new HashMap<String, String>();60 capabilities.put(element, h);61 }62 HashMap<String, String> e = capabilities.get(element);63 e.put(attribute, value);64 97 } 65 98 66 99 public void clear() { 67 100 capabilities = new HashMap<String, HashMap<String,String>>(); 101 imageryBlacklist = new ArrayList<String>(); 68 102 } 69 103 … … 74 108 75 109 /** 76 * Re plies the max number of objects in a changeset. -1 if either the capabilities110 * Returns the max number of objects in a changeset. -1 if either the capabilities 77 111 * don't include this parameter or if the parameter value is illegal (not a number, 78 112 * a negative number) … … 95 129 } 96 130 } 131 132 /** 133 * checks if the given URL is blacklisted by one of the of the 134 * regular expressions. 135 */ 136 137 public boolean isOnImageryBlacklist(String url) 138 { 139 for (String blacklistRegex : imageryBlacklist) { 140 if (url.matches(blacklistRegex)) { 141 return true; 142 } 143 } 144 return false; 145 } 146 147 /** 148 * returns the full list of blacklist regular expressions. 149 */ 150 public List<String> getImageryBlacklist() 151 { 152 return Collections.unmodifiableList(imageryBlacklist); 153 } 97 154 } -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r3566 r3934 32 32 import org.openstreetmap.josm.data.osm.OsmPrimitive; 33 33 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 34 import org.openstreetmap.josm.gui.layer.Layer; 35 import org.openstreetmap.josm.gui.layer.ImageryLayer; 34 36 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 35 37 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 157 159 cancel = false; 158 160 try { 159 String s = sendRequest("GET", "capabilities", null, monitor, false);161 String s = sendRequest("GET", "capabilities", null, monitor, false); 160 162 InputSource inputSource = new InputSource(new StringReader(s)); 161 163 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new CapabilitiesParser()); … … 173 175 osmWriter.setVersion(version); 174 176 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 175 204 } catch(IOException e) { 176 205 initialized = false;
Note:
See TracChangeset
for help on using the changeset viewer.