Changeset 1586 in josm for trunk/src/org/openstreetmap


Ignore:
Timestamp:
2009-05-11T17:33:36+02:00 (15 years ago)
Author:
stoecker
Message:

fix hardcoded URL - patch by Gubaer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/HistoryInfoAction.java

    r1523 r1586  
    88import java.util.Collection;
    99import java.util.LinkedList;
     10import java.util.regex.Pattern;
    1011
    1112import javax.swing.JOptionPane;
     
    2930    }
    3031
     32    /**
     33     * replies the base URL for browsing the the history of an OSM primitive
     34     *
     35     * @return the base URL, i.e. http://api.openstreetmap.org/browse
     36     */
     37    protected String getBaseURL() {
     38        String baseUrl = Main.pref.get("osm-server.url", "http://api.openstreetmap.org/api");
     39        Pattern pattern = Pattern.compile("/api/?$");
     40        String ret =  pattern.matcher(baseUrl).replaceAll("/browse");
     41        if (ret.equals(baseUrl)) {
     42            System.out.println("WARNING: unexpected format of API base URL. Redirection to history page for OSM primitive will probably fail. API base URL is: " + baseUrl);
     43        }
     44        return ret;
     45    }   
     46   
    3147    public void actionPerformed(ActionEvent e) {
    32         final Collection<Object> sel = new LinkedList<Object>();
     48        final Collection<Object> sel = new LinkedList<Object>();       
     49        final String baseUrl  = getBaseURL();
    3350        new AbstractVisitor() {
    3451            public void visit(Node n) {
    3552                if(n.id <= 0) return;
    36                 OpenBrowser.displayUrl("http://www.openstreetmap.org/browse/node/" + n.id + "/history");
     53                OpenBrowser.displayUrl(baseUrl + "/node/" + n.id + "/history");
    3754                sel.add(n);
    3855            }
     
    4057            public void visit(Way w) {
    4158                if(w.id <= 0) return;
    42                 OpenBrowser.displayUrl("http://www.openstreetmap.org/browse/way/" + w.id + "/history");
     59                OpenBrowser.displayUrl(baseUrl + "/way/" + w.id + "/history");
    4360                sel.add(w);
    4461            }
     
    4663            public void visit(Relation e) {
    4764                if(e.id <= 0) return;
    48                 OpenBrowser.displayUrl("http://www.openstreetmap.org/browse/relation/" + e.id + "/history");
     65                OpenBrowser.displayUrl(baseUrl + "/relation/" + e.id + "/history");
    4966                sel.add(e);
    5067            }
Note: See TracChangeset for help on using the changeset viewer.