Changeset 16555 in osm for applications/editors


Ignore:
Timestamp:
2009-07-17T14:19:35+02:00 (15 years ago)
Author:
avar
Message:

Get the id= bit from the walking-papers.org URL automatically so the
user doesn't have to manually copy/paste bits of the URL.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/walkingpapers/src/org/openstreetmap/josm/plugins/walkingpapers/WalkingPapersAddLayerAction.java

    r16549 r16555  
    2727    public void actionPerformed(ActionEvent e) {
    2828        String wpid = JOptionPane.showInputDialog(Main.parent,
    29                 tr("Image id from walking-papers.org (the bit after the ?id= in the URL)"),
     29                tr("Enter a walking-papers.org URL or ID (the bit after the ?id= in the URL)"),
    3030                        Main.pref.get("walkingpapers.last-used-id"));
    3131
    32         if (wpid == null || wpid.equals("")) return;
     32        // Grab id= from the URL if we need to, otherwise get an ID
     33        String mungedWpId = this.getWalkingPapersId(wpid);
     34
     35        if (mungedWpId == null || mungedWpId.equals("")) return;
    3336
    3437        // screen-scrape details about this id from walking-papers.org
    35         String wpUrl = "http://walking-papers.org/scan.php?id=" + wpid;
     38        String wpUrl = "http://walking-papers.org/scan.php?id=" + mungedWpId;
    3639
    3740        Pattern spanPattern = Pattern.compile("<span class=\"(\\S+)\">(\\S+)</span>");
     
    6770        }
    6871
    69         Main.pref.put("walkingpapers.last-used-id", wpid);
     72        Main.pref.put("walkingpapers.last-used-id", mungedWpId);
    7073
    7174        Bounds b = new Bounds(new LatLon(south, west), new LatLon(north, east));
    7275       
    73         WalkingPapersLayer wpl = new WalkingPapersLayer(wpid, tile, b, minz, maxz);
     76        WalkingPapersLayer wpl = new WalkingPapersLayer(mungedWpId, tile, b, minz, maxz);
    7477        Main.main.addLayer(wpl);
    7578
    7679    }
    7780
     81    public static String getWalkingPapersId(String wpid) {
     82        if (!wpid.contains("id=")) {
     83            return wpid;
     84        } else {
     85            // To match e.g. http://walking-papers.org/scan.php?id=53h78bbx
     86            final Pattern pattern = Pattern.compile("\\?id=(\\S+)");
     87            final Matcher matcher = pattern.matcher(wpid);
     88            final boolean found   = matcher.find();
     89
     90            if (found) {
     91                return matcher.group(1);
     92            }
     93        }
     94        return null;
     95    }
    7896}
Note: See TracChangeset for help on using the changeset viewer.