- Timestamp:
- 2017-08-27T23:42:54+02:00 (8 years ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r12671 r12679 6 6 import java.io.IOException; 7 7 import java.net.URL; 8 import java.util.Arrays; 8 9 import java.util.Optional; 9 10 import java.util.concurrent.Future; … … 31 32 import org.openstreetmap.josm.io.BoundingBoxDownloader; 32 33 import org.openstreetmap.josm.io.OsmServerLocationReader; 34 import org.openstreetmap.josm.io.OsmServerLocationReader.GpxUrlPattern; 33 35 import org.openstreetmap.josm.io.OsmServerReader; 34 36 import org.openstreetmap.josm.io.OsmTransferException; … … 44 46 private GpxLayer gpxLayer; 45 47 46 private static final String PATTERN_TRACE_ID = "https?://.*(osm|openstreetmap).org/trace/\\p{Digit}+/data";47 private static final String PATTERN_USER_TRACE_ID = "https?://.*(osm|openstreetmap).org/user/[^/]+/traces/(\\p{Digit}+)";48 private static final String PATTERN_EDIT_TRACE_ID = "https?://.*(osm|openstreetmap).org/edit/?\\?gpx=(\\p{Digit}+)(#.*)?";49 50 private static final String PATTERN_TRACKPOINTS_BBOX = "https?://.*/api/0.6/trackpoints\\?bbox=.*,.*,.*,.*";51 52 private static final String PATTERN_EXTERNAL_GPX_SCRIPT = "https?://.*exportgpx.*";53 private static final String PATTERN_EXTERNAL_GPX_FILE = "https?://.*/(.*\\.gpx)";54 55 48 protected String newLayerName; 56 49 57 50 @Override 58 51 public String[] getPatterns() { 59 return new String[] { 60 PATTERN_EXTERNAL_GPX_FILE, PATTERN_EXTERNAL_GPX_SCRIPT, 61 PATTERN_TRACE_ID, PATTERN_USER_TRACE_ID, PATTERN_EDIT_TRACE_ID, 62 PATTERN_TRACKPOINTS_BBOX, 63 }; 52 return Arrays.stream(GpxUrlPattern.values()).map(GpxUrlPattern::pattern).toArray(String[]::new); 64 53 } 65 54 … … 81 70 public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) { 82 71 CheckParameterUtil.ensureParameterNotNull(url, "url"); 83 final Optional<String> mappedUrl = Stream.of( PATTERN_USER_TRACE_ID,PATTERN_EDIT_TRACE_ID)84 .map(p -> Pattern.compile(p).matcher(url)) 72 final Optional<String> mappedUrl = Stream.of(GpxUrlPattern.USER_TRACE_ID, GpxUrlPattern.EDIT_TRACE_ID) 73 .map(p -> Pattern.compile(p.pattern()).matcher(url)) 85 74 .filter(Matcher::matches) 86 75 .map(m -> "https://www.openstreetmap.org/trace/" + m.group(2) + "/data") … … 89 78 return loadUrl(newLayer, mappedUrl.get(), progressMonitor); 90 79 } 91 if (url.matches(PATTERN_TRACE_ID) 92 || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT) 93 || url.matches(PATTERN_EXTERNAL_GPX_FILE)) { 80 if (Stream.of(GpxUrlPattern.TRACE_ID, GpxUrlPattern.EXTERNAL_GPX_SCRIPT, GpxUrlPattern.EXTERNAL_GPX_FILE) 81 .anyMatch(p -> url.matches(p.pattern()))) { 94 82 downloadTask = new DownloadTask(newLayer, 95 83 new OsmServerLocationReader(url), progressMonitor); 96 84 // Extract .gpx filename from URL to set the new layer name 97 Matcher matcher = Pattern.compile( PATTERN_EXTERNAL_GPX_FILE).matcher(url);85 Matcher matcher = Pattern.compile(GpxUrlPattern.EXTERNAL_GPX_FILE.pattern()).matcher(url); 98 86 newLayerName = matcher.matches() ? matcher.group(1) : null; 99 87 // We need submit instead of execute so we can wait for it to finish and get the error … … 101 89 return MainApplication.worker.submit(downloadTask); 102 90 103 } else if (url.matches( PATTERN_TRACKPOINTS_BBOX)) {91 } else if (url.matches(GpxUrlPattern.TRACKPOINTS_BBOX.pattern())) { 104 92 String[] table = url.split("\\?|=|&"); 105 93 for (int i = 0; i < table.length; i++) { … … 224 212 return true; 225 213 } 226 227 /**228 * Determines if the given URL denotes an OSM gpx-related API call.229 * @param url The url to check230 * @return true if the url matches "Trace ID" API call or "Trackpoints bbox" API call, false otherwise231 * @see GpxData#fromServer232 * @since 5745233 */234 public static final boolean isFromServer(String url) {235 return url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_TRACKPOINTS_BBOX));236 }237 214 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTask.java
r12636 r12679 7 7 import java.io.IOException; 8 8 import java.net.URL; 9 import java.util.Arrays; 9 10 import java.util.List; 10 11 import java.util.concurrent.Future; … … 28 29 import org.openstreetmap.josm.io.OsmApi; 29 30 import org.openstreetmap.josm.io.OsmServerLocationReader; 31 import org.openstreetmap.josm.io.OsmServerLocationReader.NoteUrlPattern; 30 32 import org.openstreetmap.josm.io.OsmServerReader; 31 33 import org.openstreetmap.josm.io.OsmTransferException; … … 41 43 public class DownloadNotesTask extends AbstractDownloadTask<NoteData> { 42 44 43 private static final String PATTERN_API_URL = "https?://.*/api/0.6/notes.*";44 private static final String PATTERN_DUMP_FILE = "https?://.*/(.*\\.osn(.bz2)?)";45 45 /** Property defining the number of notes to be downloaded */ 46 46 public static final IntegerProperty DOWNLOAD_LIMIT = new IntegerProperty("osm.notes.downloadLimit", 1000); … … 98 98 @Override 99 99 public String[] getPatterns() { 100 return newString[]{PATTERN_API_URL, PATTERN_DUMP_FILE};100 return Arrays.stream(NoteUrlPattern.values()).map(NoteUrlPattern::pattern).toArray(String[]::new); 101 101 } 102 102 -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r12636 r12679 7 7 import java.net.URL; 8 8 import java.util.ArrayList; 9 import java.util.Arrays; 9 10 import java.util.Collection; 10 11 import java.util.Collections; … … 35 36 import org.openstreetmap.josm.io.BoundingBoxDownloader; 36 37 import org.openstreetmap.josm.io.OsmServerLocationReader; 38 import org.openstreetmap.josm.io.OsmServerLocationReader.OsmUrlPattern; 37 39 import org.openstreetmap.josm.io.OsmServerReader; 38 40 import org.openstreetmap.josm.io.OsmTransferCanceledException; … … 48 50 public class DownloadOsmTask extends AbstractDownloadTask<DataSet> { 49 51 50 // CHECKSTYLE.OFF: SingleSpaceSeparator51 protected static final String PATTERN_OSM_API_URL = "https?://.*/api/0.6/(map|nodes?|ways?|relations?|\\*).*";52 protected static final String PATTERN_OVERPASS_API_URL = "https?://.*/interpreter\\?data=.*";53 protected static final String PATTERN_OVERPASS_API_XAPI_URL = "https?://.*/xapi(\\?.*\\[@meta\\]|_meta\\?).*";54 protected static final String PATTERN_EXTERNAL_OSM_FILE = "https?://.*/.*\\.osm";55 // CHECKSTYLE.ON: SingleSpaceSeparator56 57 52 protected Bounds currentBounds; 58 53 protected DownloadTask downloadTask; … … 66 61 public String[] getPatterns() { 67 62 if (this.getClass() == DownloadOsmTask.class) { 68 return new String[]{PATTERN_OSM_API_URL, PATTERN_OVERPASS_API_URL, 69 PATTERN_OVERPASS_API_XAPI_URL, PATTERN_EXTERNAL_OSM_FILE}; 63 return Arrays.stream(OsmUrlPattern.values()).map(OsmUrlPattern::pattern).toArray(String[]::new); 70 64 } else { 71 65 return super.getPatterns(); … … 408 402 if (url != null) { 409 403 String urlString = url.toExternalForm(); 410 if (urlString.matches( PATTERN_OSM_API_URL)) {404 if (urlString.matches(OsmUrlPattern.OSM_API_URL.pattern())) { 411 405 // TODO: proper i18n after stabilization 412 406 Collection<String> items = new ArrayList<>(); -
trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
r10315 r12679 9 9 import java.util.List; 10 10 11 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;12 11 import org.openstreetmap.josm.data.gpx.GpxData; 13 12 import org.openstreetmap.josm.data.notes.Note; … … 22 21 */ 23 22 public class OsmServerLocationReader extends OsmServerReader { 23 24 // CHECKSTYLE.OFF: MethodParamPad 25 // CHECKSTYLE.OFF: SingleSpaceSeparator 26 27 /** 28 * Patterns for OSM data download URLs. 29 * @since 12679 30 */ 31 public enum OsmUrlPattern { 32 OSM_API_URL ("https?://.*/api/0.6/(map|nodes?|ways?|relations?|\\*).*"), 33 OVERPASS_API_URL ("https?://.*/interpreter\\?data=.*"), 34 OVERPASS_API_XAPI_URL ("https?://.*/xapi(\\?.*\\[@meta\\]|_meta\\?).*"), 35 EXTERNAL_OSM_FILE ("https?://.*/.*\\.osm"); 36 37 private final String urlPattern; 38 39 OsmUrlPattern(String urlPattern) { 40 this.urlPattern = urlPattern; 41 } 42 43 /** 44 * Returns the URL pattern. 45 * @return the URL pattern 46 */ 47 public String pattern() { 48 return urlPattern; 49 } 50 } 51 52 /** 53 * Patterns for GPX download URLs. 54 * @since 12679 55 */ 56 public enum GpxUrlPattern { 57 TRACE_ID ("https?://.*(osm|openstreetmap).org/trace/\\p{Digit}+/data"), 58 USER_TRACE_ID("https?://.*(osm|openstreetmap).org/user/[^/]+/traces/(\\p{Digit}+)"), 59 EDIT_TRACE_ID("https?://.*(osm|openstreetmap).org/edit/?\\?gpx=(\\p{Digit}+)(#.*)?"), 60 61 TRACKPOINTS_BBOX("https?://.*/api/0.6/trackpoints\\?bbox=.*,.*,.*,.*"), 62 63 EXTERNAL_GPX_SCRIPT("https?://.*exportgpx.*"), 64 EXTERNAL_GPX_FILE ("https?://.*/(.*\\.gpx)"); 65 66 private final String urlPattern; 67 68 GpxUrlPattern(String urlPattern) { 69 this.urlPattern = urlPattern; 70 } 71 72 /** 73 * Returns the URL pattern. 74 * @return the URL pattern 75 */ 76 public String pattern() { 77 return urlPattern; 78 } 79 } 80 81 /** 82 * Patterns for Note download URLs. 83 * @since 12679 84 */ 85 public enum NoteUrlPattern { 86 API_URL ("https?://.*/api/0.6/notes.*"), 87 DUMP_FILE("https?://.*/(.*\\.osn(.bz2)?)"); 88 89 private final String urlPattern; 90 91 NoteUrlPattern(String urlPattern) { 92 this.urlPattern = urlPattern; 93 } 94 95 /** 96 * Returns the URL pattern. 97 * @return the URL pattern 98 */ 99 public String pattern() { 100 return urlPattern; 101 } 102 } 103 104 // CHECKSTYLE.ON: SingleSpaceSeparator 105 // CHECKSTYLE.ON: MethodParamPad 24 106 25 107 protected final String url; … … 163 245 gpxParsedProperly = reader.parse(false); 164 246 GpxData result = reader.getGpxData(); 165 result.fromServer = DownloadGpsTask.isFromServer(url);247 result.fromServer = isGpxFromServer(url); 166 248 return result; 167 249 } … … 185 267 } 186 268 } 269 270 /** 271 * Determines if the given URL denotes an OSM gpx-related API call. 272 * @param url The url to check 273 * @return true if the url matches "Trace ID" API call or "Trackpoints bbox" API call, false otherwise 274 * @see GpxData#fromServer 275 * @since 12679 276 */ 277 public static final boolean isGpxFromServer(String url) { 278 return url != null && (url.matches(GpxUrlPattern.TRACE_ID.pattern()) || url.matches(GpxUrlPattern.TRACKPOINTS_BBOX.pattern())); 279 } 187 280 } -
trunk/test/unit/org/openstreetmap/josm/gui/util/WindowGeometryTest.java
r12678 r12679 17 17 import org.junit.Test; 18 18 import org.openstreetmap.josm.Main; 19 import org.openstreetmap.josm.gui.util.WindowGeometry;20 19 import org.openstreetmap.josm.gui.util.WindowGeometry.WindowGeometryException; 21 20 import org.openstreetmap.josm.testutils.JOSMTestRules;
Note:
See TracChangeset
for help on using the changeset viewer.