Modify

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#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

     
    2323 */
    2424public class DownloadOsmIdTask extends DownloadOsmTask {
    2525
    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}+).*";
    2727
    2828    @Override
    2929    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 Don-vip, 5 years ago

you have to make the new group as non-capturing by adding ?: before browse/:
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.

comment:2 by Don-vip, 5 years ago

Milestone: 19.03

comment:3 by Klumbumbus, 5 years ago

Ok, so this would work too, right?

  • DownloadOsmIdTask.java

     
    2323 */
    2424public class DownloadOsmIdTask extends DownloadOsmTask {
    2525
    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}+).*";
    2727
    2828    @Override
    2929    public String[] getPatterns() {
     
    3434    public Future<?> loadUrl(DownloadParams settings, String url, ProgressMonitor progressMonitor) {
    3535        final Matcher matcher = Pattern.compile(URL_ID_PATTERN).matcher(url);
    3636        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));
    3939            final PrimitiveId primitiveId = new SimplePrimitiveId(id, type);
    4040            final DownloadPrimitivesWithReferrersTask downloadTask = new DownloadPrimitivesWithReferrersTask(
    4141                    settings.isNewLayer(), Collections.singletonList(primitiveId), true, true, null, null);

comment:4 by Don-vip, 5 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.

comment:5 by Klumbumbus, 5 years ago

Resolution: fixed
Status: newclosed

In 14944/josm:

fix #17544 - support optional browse/ in osm url at open location

comment:6 by Klumbumbus, 5 years ago

OK, thanks for the help.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain team.
as The resolution will be set.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.