Changeset 15784 in josm
- Timestamp:
- 2020-01-27T02:35:43+01:00 (5 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 2 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java
r14397 r15784 25 25 import java.util.regex.Matcher; 26 26 import java.util.regex.Pattern; 27 import java.util.regex.PatternSyntaxException;28 27 29 28 import javax.swing.JOptionPane; … … 39 38 import org.openstreetmap.josm.gui.io.importexport.AllFormatsImporter; 40 39 import org.openstreetmap.josm.gui.io.importexport.FileImporter; 40 import org.openstreetmap.josm.gui.util.GuiHelper; 41 41 import org.openstreetmap.josm.gui.widgets.AbstractFileChooser; 42 42 import org.openstreetmap.josm.io.OsmTransferException; … … 331 331 } 332 332 } 333 } catch (IOException | PatternSyntaxException | IllegalStateException | IndexOutOfBoundsExceptione) {333 } catch (IOException | RuntimeException | LinkageError e) { 334 334 Logging.error(e); 335 GuiHelper.runInEDT( 336 () -> new Notification(Utils.getRootCause(e).getMessage()).setIcon(JOptionPane.ERROR_MESSAGE).show()); 335 337 } 336 338 } -
trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java
r15441 r15784 28 28 import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesUrlBoundsTask; 29 29 import org.openstreetmap.josm.actions.downloadtasks.DownloadNotesUrlIdTask; 30 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmChangeCompressedTask;31 30 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmChangeTask; 32 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmCompressedTask;33 31 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmIdTask; 34 32 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; … … 97 95 addDownloadTaskClass(DownloadOsmUrlTask.class); 98 96 addDownloadTaskClass(DownloadOsmIdTask.class); 99 addDownloadTaskClass(DownloadOsmCompressedTask.class);100 addDownloadTaskClass(DownloadOsmChangeCompressedTask.class);101 97 addDownloadTaskClass(DownloadSessionTask.class); 102 98 addDownloadTaskClass(DownloadNotesUrlBoundsTask.class); -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/AbstractDownloadTask.java
r13261 r15784 3 3 4 4 import java.util.ArrayList; 5 import java.util.Arrays; 5 6 import java.util.List; 6 7 7 8 import org.openstreetmap.josm.data.ProjectionBounds; 9 import org.openstreetmap.josm.io.UrlPattern; 8 10 import org.openstreetmap.josm.io.XmlWriter; 9 11 … … 57 59 public void setFailed(boolean failed) { 58 60 this.failed = failed; 61 } 62 63 protected static <T extends Enum<T> & UrlPattern> String[] patterns(Class<T> urlPatternEnum) { 64 // Do not use a method reference until we switch to Java 11, as we face JDK-8141508 with Java 8 65 return Arrays.stream(urlPatternEnum.getEnumConstants()).map(/* JDK-8141508 */ t -> t.pattern()).toArray(String[]::new); 59 66 } 60 67 … … 116 123 */ 117 124 public boolean acceptsUrl(String url) { 118 if (url == null) 119 return false; 120 for (String p: getPatterns()) { 121 if (url.matches(p)) { 122 return true; 123 } 124 } 125 return false; 125 return url != null && Arrays.stream(getPatterns()).anyMatch(url::matches); 126 126 } 127 127 -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGeoJsonTask.java
r15622 r15784 12 12 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 13 13 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 14 import org.openstreetmap.josm.io.Compression; 14 15 import org.openstreetmap.josm.io.GeoJSONServerReader; 16 import org.openstreetmap.josm.io.UrlPatterns.GeoJsonUrlPattern; 15 17 import org.openstreetmap.josm.tools.Utils; 16 18 … … 22 24 public class DownloadGeoJsonTask extends DownloadOsmTask { 23 25 24 private static final String PATTERN_COMPRESS = "https?://.*/(.*\\.(json|geojson)(\\.(gz|xz|bz2?|zip))?)";25 private static final String PATTERN_FORMAT_GEOJSON = "https?://.*format=geojson.*";26 27 26 @Override 28 27 public String[] getPatterns() { 29 return new String[]{PATTERN_COMPRESS, PATTERN_FORMAT_GEOJSON};28 return patterns(GeoJsonUrlPattern.class); 30 29 } 31 30 … … 51 50 52 51 InternalDownloadTask(DownloadParams settings, String url, ProgressMonitor progressMonitor) { 53 super(settings, new GeoJSONServerReader(url), progressMonitor );52 super(settings, new GeoJSONServerReader(url), progressMonitor, true, Compression.byExtension(url)); 54 53 this.url = url; 55 54 } -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r15652 r15784 6 6 import java.io.IOException; 7 7 import java.net.URL; 8 import java.util. Arrays;8 import java.util.Objects; 9 9 import java.util.Optional; 10 10 import java.util.concurrent.Future; 11 11 import java.util.regex.Matcher; 12 import java.util.regex.Pattern;13 12 import java.util.stream.Stream; 14 13 … … 30 29 import org.openstreetmap.josm.io.BoundingBoxDownloader; 31 30 import org.openstreetmap.josm.io.OsmServerLocationReader; 32 import org.openstreetmap.josm.io.OsmServerLocationReader.GpxUrlPattern;33 31 import org.openstreetmap.josm.io.OsmServerReader; 34 32 import org.openstreetmap.josm.io.OsmTransferException; 33 import org.openstreetmap.josm.io.UrlPatterns.GpxUrlPattern; 35 34 import org.openstreetmap.josm.spi.preferences.Config; 36 import org.openstreetmap.josm.tools.CheckParameterUtil;37 35 import org.openstreetmap.josm.tools.Utils; 38 36 import org.xml.sax.SAXException; … … 50 48 @Override 51 49 public String[] getPatterns() { 52 return Arrays.stream(GpxUrlPattern.values()).map(GpxUrlPattern::pattern).toArray(String[]::new);50 return patterns(GpxUrlPattern.class); 53 51 } 54 52 … … 69 67 @Override 70 68 public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) { 71 CheckParameterUtil.ensureParameterNotNull(url, "url"); 72 this.url = url; 69 this.url = Objects.requireNonNull(url); 73 70 final Optional<String> mappedUrl = Stream.of(GpxUrlPattern.USER_TRACE_ID, GpxUrlPattern.EDIT_TRACE_ID) 74 .map(p -> Pattern.compile(p.pattern()).matcher(url))71 .map(p -> p.matcher(url)) 75 72 .filter(Matcher::matches) 76 73 .map(m -> "https://www.openstreetmap.org/trace/" + m.group(2) + "/data") … … 81 78 if (Stream.of(GpxUrlPattern.TRACE_ID, GpxUrlPattern.EXTERNAL_GPX_SCRIPT, 82 79 GpxUrlPattern.EXTERNAL_GPX_FILE, GpxUrlPattern.TASKING_MANAGER) 83 .anyMatch(p -> url.matches(p.pattern()))) {80 .anyMatch(p -> p.matches(url))) { 84 81 downloadTask = new DownloadTask(settings, 85 82 new OsmServerLocationReader(url), progressMonitor); … … 88 85 return MainApplication.worker.submit(downloadTask); 89 86 90 } else if ( url.matches(GpxUrlPattern.TRACKPOINTS_BBOX.pattern())) {87 } else if (GpxUrlPattern.TRACKPOINTS_BBOX.matches(url)) { 91 88 String[] table = url.split("\\?|=|&"); 92 89 for (int i = 0; i < table.length; i++) { … … 153 150 private String getLayerName() { 154 151 // Extract .gpx filename from URL to set the new layer name 155 final Matcher matcher = url != null ? Pattern.compile(GpxUrlPattern.EXTERNAL_GPX_FILE.pattern()).matcher(url) : null;152 final Matcher matcher = url != null ? GpxUrlPattern.EXTERNAL_GPX_FILE.matcher(url) : null; 156 153 final String newLayerName = matcher != null && matcher.matches() ? matcher.group(1) : null; 157 154 final String metadataName = rawData != null ? rawData.getString(GpxConstants.META_NAME) : null; -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadNotesTask.java
r15358 r15784 7 7 import java.io.IOException; 8 8 import java.net.URL; 9 import java.util.Arrays;10 9 import java.util.List; 11 10 import java.util.concurrent.Future; … … 29 28 import org.openstreetmap.josm.io.OsmApi; 30 29 import org.openstreetmap.josm.io.OsmServerLocationReader; 31 import org.openstreetmap.josm.io.OsmServerLocationReader.NoteUrlPattern;32 30 import org.openstreetmap.josm.io.OsmServerReader; 33 31 import org.openstreetmap.josm.io.OsmTransferException; 32 import org.openstreetmap.josm.io.UrlPatterns.NoteUrlPattern; 34 33 import org.openstreetmap.josm.tools.Logging; 35 34 import org.xml.sax.SAXException; … … 107 106 @Override 108 107 public String[] getPatterns() { 109 return Arrays.stream(NoteUrlPattern.values()).map(NoteUrlPattern::pattern).toArray(String[]::new);108 return patterns(NoteUrlPattern.class); 110 109 } 111 110 -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmChangeTask.java
r14763 r15784 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.Arrays; 6 7 import java.util.Date; 7 8 import java.util.HashMap; … … 12 13 import java.util.concurrent.RejectedExecutionException; 13 14 import java.util.regex.Matcher; 14 import java.util.regex.Pattern;15 15 16 16 import org.openstreetmap.josm.data.Bounds; … … 34 34 import org.openstreetmap.josm.gui.history.HistoryLoadTask; 35 35 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 36 import org.openstreetmap.josm.io.Compression; 36 37 import org.openstreetmap.josm.io.OsmApi; 37 38 import org.openstreetmap.josm.io.OsmServerLocationReader; 38 39 import org.openstreetmap.josm.io.OsmServerReader; 39 40 import org.openstreetmap.josm.io.OsmTransferException; 41 import org.openstreetmap.josm.io.UrlPatterns.OsmChangeUrlPattern; 40 42 import org.openstreetmap.josm.tools.Logging; 41 43 … … 46 48 public class DownloadOsmChangeTask extends DownloadOsmTask { 47 49 48 private static final String OSM_WEBSITE_PATTERN = "https?://www\\.(osm|openstreetmap)\\.org/changeset/(\\p{Digit}+).*";49 50 50 @Override 51 51 public String[] getPatterns() { 52 return new String[]{"https?://.*/api/0.6/changeset/\\p{Digit}+/download", // OSM API 0.6 changesets 53 OSM_WEBSITE_PATTERN, // OSM changesets 54 "https?://.*/.*\\.osc" // Remote .osc files 55 }; 52 return patterns(OsmChangeUrlPattern.class); 56 53 } 57 54 … … 67 64 68 65 @Override 69 public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) { 70 final Matcher matcher = Pattern.compile(OSM_WEBSITE_PATTERN).matcher(url); 66 public Future<?> loadUrl(DownloadParams settings, final String url, ProgressMonitor progressMonitor) { 67 OsmChangeUrlPattern urlPattern = Arrays.stream(OsmChangeUrlPattern.values()).filter(p -> p.matches(url)).findFirst() 68 .orElseThrow(() -> new IllegalArgumentException("URL does not match any OSM URL pattern: " + url)); 69 String newUrl = url; 70 final Matcher matcher = OsmChangeUrlPattern.OSM_WEBSITE.matcher(url); 71 71 if (matcher.matches()) { 72 url = OsmApi.getOsmApi().getBaseUrl() + "changeset/" + Long.parseLong(matcher.group(2)) + "/download"; 73 } 74 downloadTask = new DownloadTask(settings, new OsmServerLocationReader(url), progressMonitor); 72 newUrl = OsmApi.getOsmApi().getBaseUrl() + "changeset/" + Long.parseLong(matcher.group(2)) + "/download"; 73 } 74 downloadTask = new DownloadTask(settings, new OsmServerLocationReader(newUrl), progressMonitor, true, 75 Compression.byExtension(newUrl)); 75 76 // Extract .osc filename from URL to set the new layer name 76 extractOsmFilename(settings, "https?://.*/(.*\\.osc)", url);77 extractOsmFilename(settings, urlPattern.pattern(), newUrl); 77 78 return MainApplication.worker.submit(downloadTask); 78 79 } … … 88 89 * @param reader OSM data reader 89 90 * @param progressMonitor progress monitor 91 * @param zoomAfterDownload If true, the map view will zoom to download area after download 92 * @param compression compression to use 90 93 */ 91 public DownloadTask(DownloadParams settings, OsmServerReader reader, ProgressMonitor progressMonitor) { 92 super(settings, reader, progressMonitor); 94 public DownloadTask(DownloadParams settings, OsmServerReader reader, ProgressMonitor progressMonitor, 95 boolean zoomAfterDownload, Compression compression) { 96 super(settings, reader, progressMonitor, zoomAfterDownload, compression); 93 97 } 94 98 95 99 @Override 96 100 protected DataSet parseDataSet() throws OsmTransferException { 97 return reader.parseOsmChange(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 101 return reader.parseOsmChange(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false), 102 compression); 98 103 } 99 104 -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r15447 r15784 38 38 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 39 39 import org.openstreetmap.josm.io.BoundingBoxDownloader; 40 import org.openstreetmap.josm.io.Compression; 40 41 import org.openstreetmap.josm.io.OsmServerLocationReader; 41 import org.openstreetmap.josm.io.OsmServerLocationReader.OsmUrlPattern;42 42 import org.openstreetmap.josm.io.OsmServerReader; 43 43 import org.openstreetmap.josm.io.OsmTransferCanceledException; 44 44 import org.openstreetmap.josm.io.OsmTransferException; 45 45 import org.openstreetmap.josm.io.OverpassDownloadReader; 46 import org.openstreetmap.josm.io.UrlPatterns.OsmUrlPattern; 46 47 import org.openstreetmap.josm.tools.Logging; 47 48 import org.openstreetmap.josm.tools.Utils; … … 72 73 public String[] getPatterns() { 73 74 if (this.getClass() == DownloadOsmTask.class) { 74 return Arrays.stream(OsmUrlPattern.values()).map(OsmUrlPattern::pattern).toArray(String[]::new);75 return patterns(OsmUrlPattern.class); 75 76 } else { 76 77 return super.getPatterns(); … … 158 159 public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) { 159 160 String newUrl = modifyUrlBeforeLoad(url); 160 downloadTask = new DownloadTask(settings, getOsmServerReader(newUrl), progressMonitor); 161 OsmUrlPattern urlPattern = Arrays.stream(OsmUrlPattern.values()).filter(p -> p.matches(newUrl)).findFirst() 162 .orElseThrow(() -> new IllegalArgumentException("URL does not match any OSM URL pattern: " + newUrl)); 163 downloadTask = new DownloadTask(settings, getOsmServerReader(newUrl), progressMonitor, true, Compression.byExtension(newUrl)); 161 164 currentBounds = null; 162 165 // Extract .osm filename from URL to set the new layer name 163 extractOsmFilename(settings, "https?://.*/(.*\\.osm)", newUrl);166 extractOsmFilename(settings, urlPattern.pattern(), newUrl); 164 167 return MainApplication.worker.submit(downloadTask); 165 168 } … … 413 416 protected class DownloadTask extends AbstractInternalTask { 414 417 protected final OsmServerReader reader; 418 protected final Compression compression; 415 419 416 420 /** … … 434 438 */ 435 439 public DownloadTask(DownloadParams settings, OsmServerReader reader, ProgressMonitor progressMonitor, boolean zoomAfterDownload) { 440 this(settings, reader, progressMonitor, zoomAfterDownload, Compression.NONE); 441 } 442 443 /** 444 * Constructs a new {@code DownloadTask}. 445 * @param settings download settings 446 * @param reader OSM data reader 447 * @param progressMonitor progress monitor 448 * @param zoomAfterDownload If true, the map view will zoom to download area after download 449 * @param compression compression to use 450 * @since 15784 451 */ 452 public DownloadTask(DownloadParams settings, OsmServerReader reader, ProgressMonitor progressMonitor, boolean zoomAfterDownload, 453 Compression compression) { 436 454 super(settings, tr("Downloading data"), progressMonitor, false, zoomAfterDownload); 437 this.reader = reader; 455 this.reader = Objects.requireNonNull(reader); 456 this.compression = compression; 438 457 } 439 458 440 459 protected DataSet parseDataSet() throws OsmTransferException { 441 return reader.parseOsm(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 460 ProgressMonitor subTaskMonitor = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false); 461 // Don't call parseOsm signature with compression if not needed, too many implementations to update before to avoid side effects 462 return compression != null && compression != Compression.NONE ? 463 reader.parseOsm(subTaskMonitor, compression) : reader.parseOsm(subTaskMonitor); 442 464 } 443 465 … … 500 522 @Override 501 523 public String getConfirmationMessage(URL url) { 502 if (url != null) { 503 String urlString = url.toExternalForm(); 504 if (urlString.matches(OsmUrlPattern.OSM_API_URL.pattern())) { 505 // TODO: proper i18n after stabilization 506 Collection<String> items = new ArrayList<>(); 507 items.add(tr("OSM Server URL:") + ' ' + url.getHost()); 508 items.add(tr("Command")+": "+url.getPath()); 509 if (url.getQuery() != null) { 510 items.add(tr("Request details: {0}", url.getQuery().replaceAll(",\\s*", ", "))); 511 } 512 return Utils.joinAsHtmlUnorderedList(items); 513 } 514 // TODO: other APIs 524 if (OsmUrlPattern.OSM_API_URL.matches(url)) { 525 Collection<String> items = new ArrayList<>(); 526 items.add(tr("OSM Server URL:") + ' ' + url.getHost()); 527 items.add(tr("Command")+": "+url.getPath()); 528 if (url.getQuery() != null) { 529 items.add(tr("Request details: {0}", url.getQuery().replaceAll(",\\s*", ", "))); 530 } 531 return Utils.joinAsHtmlUnorderedList(items); 515 532 } 516 533 return null; -
trunk/src/org/openstreetmap/josm/io/GeoJSONServerReader.java
r15452 r15784 5 5 6 6 import java.io.IOException; 7 import java. util.Objects;7 import java.io.InputStream; 8 8 9 9 import org.openstreetmap.josm.data.osm.DataSet; 10 import org.openstreetmap.josm.gui.io.importexport.GeoJSONImporter;11 10 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 11 import org.xml.sax.SAXException; 12 12 13 13 /** … … 16 16 * @since 15424 17 17 */ 18 public class GeoJSONServerReader extends OsmServerReader { 19 20 private final String url; 18 public class GeoJSONServerReader extends OsmServerLocationReader { 21 19 22 20 /** … … 25 23 */ 26 24 public GeoJSONServerReader(String url) { 27 this.url = Objects.requireNonNull(url); 25 super(url); 26 } 27 28 protected class GeoJsonParser extends Parser<DataSet> { 29 protected GeoJsonParser(ProgressMonitor progressMonitor, Compression compression) { 30 super(progressMonitor, compression); 31 } 32 33 @Override 34 public DataSet parse() throws OsmTransferException, IllegalDataException, IOException, SAXException { 35 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 36 if (in == null) 37 return null; 38 progressMonitor.subTask(tr("Downloading OSM data...")); 39 InputStream uncompressedInputStream = compression.getUncompressedInputStream(in); // NOPMD 40 ProgressMonitor subTaskMonitor = progressMonitor.createSubTaskMonitor(1, false); 41 return GeoJSONReader.parseDataSet(uncompressedInputStream, subTaskMonitor); 42 } 28 43 } 29 44 30 45 @Override 31 46 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 32 try { 33 progressMonitor.beginTask(tr("Contacting Server..."), 10); 34 return new GeoJSONImporter().parseDataSet(url); 35 } catch (IOException | IllegalDataException e) { 36 throw new OsmTransferException(e); 37 } finally { 38 progressMonitor.finishTask(); 39 } 47 return parseOsm(progressMonitor, Compression.NONE); 48 } 49 50 @Override 51 public DataSet parseOsm(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException { 52 return doParse(new GeoJsonParser(progressMonitor, compression), progressMonitor); 40 53 } 41 54 } -
trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
r15631 r15784 13 13 import org.openstreetmap.josm.data.osm.DataSet; 14 14 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 15 import org.openstreetmap.josm.io.UrlPatterns.GpxUrlPattern; 15 16 import org.openstreetmap.josm.tools.Utils; 16 17 import org.xml.sax.SAXException; … … 21 22 */ 22 23 public class OsmServerLocationReader extends OsmServerReader { 23 24 // CHECKSTYLE.OFF: MethodParamPad25 // CHECKSTYLE.OFF: SingleSpaceSeparator26 27 /**28 * Patterns for OSM data download URLs.29 * @since 1267930 */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 pattern46 */47 public String pattern() {48 return urlPattern;49 }50 }51 52 /**53 * Patterns for GPX download URLs.54 * @since 1267955 */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 TASKING_MANAGER("https?://.*/api/v\\p{Digit}+/projects?/\\p{Digit}+/(tasks_as_gpx?.*|tasks/queries/gpx/\\?tasks=.*)"),63 64 /** External GPX script */65 EXTERNAL_GPX_SCRIPT("https?://.*exportgpx.*"),66 /** External GPX file */67 EXTERNAL_GPX_FILE ("https?://.*/(.*\\.gpx)");68 69 private final String urlPattern;70 71 GpxUrlPattern(String urlPattern) {72 this.urlPattern = urlPattern;73 }74 75 /**76 * Returns the URL pattern.77 * @return the URL pattern78 */79 public String pattern() {80 return urlPattern;81 }82 }83 84 /**85 * Patterns for Note download URLs.86 * @since 1267987 */88 public enum NoteUrlPattern {89 /** URL of OSM API Notes endpoint */90 API_URL ("https?://.*/api/0.6/notes.*"),91 /** URL of OSM API Notes compressed dump file */92 DUMP_FILE("https?://.*/(.*\\.osn(\\.(gz|xz|bz2?|zip))?)");93 94 private final String urlPattern;95 96 NoteUrlPattern(String urlPattern) {97 this.urlPattern = urlPattern;98 }99 100 /**101 * Returns the URL pattern.102 * @return the URL pattern103 */104 public String pattern() {105 return urlPattern;106 }107 }108 109 // CHECKSTYLE.ON: SingleSpaceSeparator110 // CHECKSTYLE.ON: MethodParamPad111 24 112 25 protected final String url; … … 250 163 gpxParsedProperly = reader.parse(false); 251 164 GpxData result = reader.getGpxData(); 252 result.fromServer = isGpxFromServer(url);165 result.fromServer = GpxUrlPattern.isGpxFromServer(url); 253 166 return result; 254 167 } … … 272 185 } 273 186 } 274 275 /**276 * Determines if the given URL denotes an OSM gpx-related API call.277 * @param url The url to check278 * @return true if the url matches "Trace ID" API call or "Trackpoints bbox" API call, false otherwise279 * @see GpxData#fromServer280 * @since 12679281 */282 public static final boolean isGpxFromServer(String url) {283 return url != null && (url.matches(GpxUrlPattern.TRACE_ID.pattern()) || url.matches(GpxUrlPattern.TRACKPOINTS_BBOX.pattern()));284 }285 187 } -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r14216 r15784 261 261 */ 262 262 public DataSet parseOsm(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException { 263 return null;263 throw new UnsupportedOperationException(); 264 264 } 265 265 … … 283 283 */ 284 284 public DataSet parseOsmChange(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException { 285 return null;285 throw new UnsupportedOperationException(); 286 286 } 287 287 … … 305 305 */ 306 306 public GpxData parseRawGps(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException { 307 return null;307 throw new UnsupportedOperationException(); 308 308 } 309 309 … … 372 372 */ 373 373 public List<Note> parseRawNotes(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException { 374 return null;374 throw new UnsupportedOperationException(); 375 375 } 376 376
Note:
See TracChangeset
for help on using the changeset viewer.