Ticket #21826: josm_21826_wip.patch
File josm_21826_wip.patch, 6.9 KB (added by , 3 years ago) |
---|
-
test/data/__files/api/0.6/capabilities
6 6 <note_area maximum="25"/> 7 7 <tracepoints per_page="5000"/> 8 8 <waynodes maximum="2000"/> 9 <relationmembers maximum="32000"/> 9 10 <changesets maximum_elements="10000"/> 10 11 <timeout seconds="300"/> 11 12 <status database="online" api="online" gpx="online"/> … … 15 16 <blacklist regex=".*\.google(apis)?\..*/(vt|kh)[\?/].*([xyz]=.*){3}.*"/> 16 17 </imagery> 17 18 </policy> 18 </osm> 19 </osm> 20 No newline at end of file -
src/org/openstreetmap/josm/io/Capabilities.java
24 24 * 25 25 * Example capabilities document: 26 26 * <pre> 27 * <osm version="0.6" generator="OpenStreetMap server"> 27 * <?xml version="1.0" encoding="UTF-8"?> 28 * <osm version="0.6" generator="OpenStreetMap server" copyright="OpenStreetMap and contributors" attribution="http://www.openstreetmap.org/copyright" license="http://opendatacommons.org/licenses/odbl/1-0/"> 28 29 * <api> 29 30 * <version minimum="0.6" maximum="0.6"/> 30 31 * <area maximum="0.25"/> 32 * <note_area maximum="25"/> 31 33 * <tracepoints per_page="5000"/> 32 34 * <waynodes maximum="2000"/> 35 * <relationmembers maximum="32000"/> 33 36 * <changesets maximum_elements="10000"/> 34 37 * <timeout seconds="300"/> 35 38 * <status database="online" api="online" gpx="online"/> … … 36 39 * </api> 37 40 * <policy> 38 41 * <imagery> 39 * <blacklist regex=".*\.google\.com/.*"/> 40 * <blacklist regex=".*209\.85\.2\d\d.*"/> 41 * <blacklist regex=".*209\.85\.1[3-9]\d.*"/> 42 * <blacklist regex=".*209\.85\.12[89].*"/> 42 * <blacklist regex=".*\.google(apis)?\..*(vt|kh)[\?/].*([xyz]=.*){3}.*"/> 43 * <blacklist regex="http://xdworld\.vworld\.kr:8080/.*"/> 44 * <blacklist regex=".*\.here\.com[/:].*"/> 43 45 * </imagery> 44 46 * </policy> 45 47 * </osm> 46 48 * </pre> 47 49 * This class is used in conjunction with a very primitive parser 48 * and simply stuffs theeach tag and its attributes into a hash50 * and simply stuffs each tag and its attributes into a hash 49 51 * of hashes, with the exception of the "blacklist" tag which gets 50 52 * a list of its own. The DOM hierarchy is disregarded. 51 53 */ … … 188 190 } 189 191 190 192 /** 193 * Returns the max number of members in a relation. -1 if either the capabilities 194 * don't include this parameter or if the parameter value is illegal (not a number, 195 * a negative number) 196 * 197 * @return the max number of members in a relation 198 * @since xxx 199 */ 200 public long getMaxRelationMembers() { 201 String v = get("relationmembers", "maximum"); 202 if (v != null) { 203 try { 204 long n = Long.parseLong(v); 205 if (n <= 0) { 206 warnIllegalValue("relationmembers", "maximum", n); 207 } else { 208 return n; 209 } 210 } catch (NumberFormatException e) { 211 warnIllegalValue("relationmembers", "maximum", v); 212 } 213 } 214 return -1; 215 } 216 217 /** 191 218 * Returns the max number of nodes in a way. -1 if either the capabilities 192 219 * don't include this parameter or if the parameter value is illegal (not a number, 193 220 * a negative number) -
src/org/openstreetmap/josm/actions/upload/ApiPreconditionCheckerHook.java
11 11 12 12 import org.openstreetmap.josm.data.APIDataSet; 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 import org.openstreetmap.josm.data.osm.Relation; 14 15 import org.openstreetmap.josm.data.osm.Tagged; 15 16 import org.openstreetmap.josm.data.osm.Way; 16 17 import org.openstreetmap.josm.gui.ExceptionDialogUtil; … … 36 37 if (NetworkManager.isOffline(OnlineResource.OSM_API)) { 37 38 return false; 38 39 } 40 39 41 // FIXME: this should run asynchronously and a progress monitor 40 // should be displayed.42 // should be displayed. 41 43 api.initialize(NullProgressMonitor.INSTANCE); 44 42 45 long maxNodes = api.getCapabilities().getMaxWayNodes(); 43 46 if (maxNodes > 0) { 44 47 if (!checkMaxNodes(apiData.getPrimitivesToAdd(), maxNodes)) … … 48 51 if (!checkMaxNodes(apiData.getPrimitivesToDelete(), maxNodes)) 49 52 return false; 50 53 } 54 55 long maxMembers = api.getCapabilities().getMaxRelationMembers(); 56 if (maxMembers > 0) { 57 if (!checkMaxMembers(apiData.getPrimitivesToAdd(), maxNodes)) 58 return false; 59 if (!checkMaxMembers(apiData.getPrimitivesToUpdate(), maxNodes)) 60 return false; 61 if (!checkMaxMembers(apiData.getPrimitivesToDelete(), maxNodes)) 62 return false; 63 } 51 64 } catch (OsmTransferCanceledException e) { 52 65 Logging.trace(e); 53 66 return false; … … 58 71 return true; 59 72 } 60 73 74 private static boolean checkMaxMembers(Collection<OsmPrimitive> primitives, long maxMembers) { 75 for (OsmPrimitive osmPrimitive : primitives) { 76 if (osmPrimitive instanceof Relation && ((Relation) osmPrimitive).getMembersCount() > maxMembers) { 77 JOptionPane.showMessageDialog( 78 MainApplication.getMainFrame(), 79 tr("{0} members in relation {1} exceed the max. allowed number of members {2}", 80 ((Relation) osmPrimitive).getMembersCount(), 81 Long.toString(osmPrimitive.getId()), 82 maxMembers 83 ), 84 tr("API Capabilities Violation"), 85 JOptionPane.ERROR_MESSAGE 86 ); 87 MainApplication.getLayerManager().getEditDataSet().setSelected(Collections.singleton(osmPrimitive)); 88 return false; 89 } 90 } 91 return true; 92 } 93 61 94 private static boolean checkMaxNodes(Collection<OsmPrimitive> primitives, long maxNodes) { 62 95 for (OsmPrimitive osmPrimitive : primitives) { 63 96 for (Map.Entry<String, String> entry: osmPrimitive.getKeys().entrySet()) {