Modify ↓
#17544 closed enhancement (fixed)
support optional `browse/` in osm url at open location [half patch]
Reported by: | Klumbumbus | Owned by: | team |
---|---|---|---|
Priority: | normal | Milestone: | 19.03 |
Component: | Core | Version: | |
Keywords: | Cc: |
Description
Keepright uses this url schema in the popup:
https://www.openstreetmap.org/browse/way/119890471
I tried this:
-
DownloadOsmIdTask.java
23 23 */ 24 24 public class DownloadOsmIdTask extends DownloadOsmTask { 25 25 26 private static final String URL_ID_PATTERN = "https?://(?:www\\.)?(osm|openstreetmap)\\.org/( node|way|relation)/(\\p{Digit}+).*";26 private static final String URL_ID_PATTERN = "https?://(?:www\\.)?(osm|openstreetmap)\\.org/(browse/)?(node|way|relation)/(\\p{Digit}+).*"; 27 27 28 28 @Override 29 29 public String[] getPatterns() {
however when I compile this it does not work. Could someone please review? Thanks.
Attachments (0)
Change History (6)
comment:1 by , 6 years ago
comment:2 by , 6 years ago
Milestone: | → 19.03 |
---|
comment:3 by , 6 years ago
Ok, so this would work too, right?
-
DownloadOsmIdTask.java
23 23 */ 24 24 public class DownloadOsmIdTask extends DownloadOsmTask { 25 25 26 private static final String URL_ID_PATTERN = "https?://(?:www\\.)?(osm|openstreetmap)\\.org/( node|way|relation)/(\\p{Digit}+).*";26 private static final String URL_ID_PATTERN = "https?://(?:www\\.)?(osm|openstreetmap)\\.org/(browse/)?(node|way|relation)/(\\p{Digit}+).*"; 27 27 28 28 @Override 29 29 public String[] getPatterns() { … … 34 34 public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) { 35 35 final Matcher matcher = Pattern.compile(URL_ID_PATTERN).matcher(url); 36 36 if (matcher.matches()) { 37 final OsmPrimitiveType type = OsmPrimitiveType.from(matcher.group( 2));38 final long id = Long.parseLong(matcher.group( 3));37 final OsmPrimitiveType type = OsmPrimitiveType.from(matcher.group(3)); 38 final long id = Long.parseLong(matcher.group(4)); 39 39 final PrimitiveId primitiveId = new SimplePrimitiveId(id, type); 40 40 final DownloadPrimitivesWithReferrersTask downloadTask = new DownloadPrimitivesWithReferrersTask( 41 41 settings.isNewLayer(), Collections.singletonList(primitiveId), true, true, null, null);
comment:4 by , 6 years ago
At first sight yes (did not check). But it's cleaner to create non-capturing groups when you don't need the value.
Note:
See TracTickets
for help on using tickets.
you have to make the new group as non-capturing by adding
?:
beforebrowse/
:private static final String URL_ID_PATTERN = "https?://(?:www\\.)?(osm|openstreetmap)\\.org/(?:browse/)?(node|way|relation)/(\\p{Digit}+).*";
Otherwise the group indexes are modified. See javadoc to understand how "groups and capturing" work.