Ignore:
Timestamp:
2014-10-30T16:49:19+01:00 (10 years ago)
Author:
stoecker
Message:

fix #9059 - no more assumptions about URL for element browsing - use OSM website as default and hidden option for changes

Location:
trunk/src/org/openstreetmap/josm/actions
Files:
3 edited

Legend:

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

    r7005 r7678  
    3232    public AbstractInfoAction(String name, String iconName, String tooltip, Shortcut shortcut, boolean register, String toolbarId, boolean installAdapters) {
    3333        super(name, iconName, tooltip, shortcut, register, toolbarId, installAdapters);
    34     }
    35 
    36     /**
    37      * Replies the base URL for browsing information about about a primitive.
    38      *
    39      * @return the base URL, i.e. https://www.openstreetmap.org
    40      */
    41     public static String getBaseBrowseUrl() {
    42         String baseUrl = Main.pref.get("osm-server.url", OsmApi.DEFAULT_API_URL);
    43         Pattern pattern = Pattern.compile("/api/?$");
    44         String ret = pattern.matcher(baseUrl).replaceAll("");
    45         if (ret.equals(baseUrl)) {
    46             Main.warn(tr("Unexpected format of API base URL. Redirection to info or history page for OSM object will probably fail. API base URL is: ''{0}''",baseUrl));
    47         }
    48         for (String prefix : new String[]{"http://api.openstreetmap.org/", "https://api.openstreetmap.org/"}) {
    49             if (ret.startsWith(prefix)) {
    50                 ret = Main.getOSMWebsite() + "/" + ret.substring(prefix.length());
    51                 break;
    52             }
    53         }
    54         return ret;
    55     }
    56 
    57     /**
    58      * Replies the base URL for browsing information about a user.
    59      *
    60      * @return the base URL, i.e. https://www.openstreetmap.org/user
    61      */
    62     public static String getBaseUserUrl() {
    63         String baseUrl = Main.pref.get("osm-server.url", OsmApi.DEFAULT_API_URL);
    64         Pattern pattern = Pattern.compile("/api/?$");
    65         String ret =  pattern.matcher(baseUrl).replaceAll("/user");
    66         if (ret.equals(baseUrl)) {
    67             Main.warn(tr("Unexpected format of API base URL. Redirection to user page for OSM user will probably fail. API base URL is: ''{0}''",baseUrl));
    68         }
    69         for (String prefix : new String[]{"http://api.openstreetmap.org/", "https://api.openstreetmap.org/"}) {
    70             if (ret.startsWith(prefix)) {
    71                 ret = Main.getOSMWebsite() + "/" + ret.substring(prefix.length());
    72                 break;
    73             }
    74         }
    75         return ret;
    7634    }
    7735
  • trunk/src/org/openstreetmap/josm/actions/HistoryInfoWebAction.java

    r6380 r7678  
    77import java.awt.event.KeyEvent;
    88
     9import org.openstreetmap.josm.Main;
    910import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1011import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    2526    protected  String createInfoUrl(Object infoObject) {
    2627        OsmPrimitive primitive = (OsmPrimitive) infoObject;
    27         return getBaseBrowseUrl() + "/" + OsmPrimitiveType.from(primitive).getAPIName() + "/" + primitive.getId() + "/history";
     28        return Main.getBaseBrowseUrl() + "/" + OsmPrimitiveType.from(primitive).getAPIName() + "/" + primitive.getId() + "/history";
    2829    }
    2930}
  • trunk/src/org/openstreetmap/josm/actions/InfoWebAction.java

    r6380 r7678  
    77import java.awt.event.KeyEvent;
    88
     9import org.openstreetmap.josm.Main;
    910import org.openstreetmap.josm.data.osm.OsmPrimitive;
    1011import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
     
    2526    protected  String createInfoUrl(Object infoObject) {
    2627        OsmPrimitive primitive = (OsmPrimitive)infoObject;
    27         return getBaseBrowseUrl() + "/" + OsmPrimitiveType.from(primitive).getAPIName() + "/" + primitive.getId();
     28        return Main.getBaseBrowseUrl() + "/" + OsmPrimitiveType.from(primitive).getAPIName() + "/" + primitive.getId();
    2829    }
    2930}
Note: See TracChangeset for help on using the changeset viewer.