Changeset 7678 in josm for trunk/src/org


Ignore:
Timestamp:
2014-10-30T16:49:19+01:00 (5 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
Files:
9 edited

Legend:

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

    r7634 r7678  
    15621562
    15631563    /**
     1564     * Replies the base URL for browsing information about a primitive.
     1565     * @return the base URL, i.e. https://www.openstreetmap.org
     1566     * @since 7678
     1567     */
     1568    public static String getBaseBrowseUrl() {
     1569        if (Main.pref != null)
     1570            return Main.pref.get("osm-browse.url", getOSMWebsite());
     1571        return getOSMWebsite();
     1572    }
     1573
     1574    /**
     1575     * Replies the base URL for browsing information about a user.
     1576     * @return the base URL, i.e. https://www.openstreetmap.org/user
     1577     * @since 7678
     1578     */
     1579    public static String getBaseUserUrl() {
     1580        if (Main.pref != null)
     1581            return Main.pref.get("osm-user.url", getOSMWebsite() + "/user");
     1582        return getOSMWebsite() + "/user";
     1583    }
     1584
     1585    /**
    15641586     * Determines if we are currently running on OSX.
    15651587     * @return {@code true} if we are currently running on OSX
  • 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}
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ChangesetDialog.java

    r7434 r7678  
    434434            if (sel.size() > 10 && ! AbstractInfoAction.confirmLaunchMultiple(sel.size()))
    435435                return;
    436             String baseUrl = AbstractInfoAction.getBaseBrowseUrl();
     436            String baseUrl = Main.getBaseBrowseUrl();
    437437            for (Changeset cs: sel) {
    438438                String url = baseUrl + "/changeset/" + cs.getId();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/UserListDialog.java

    r7005 r7678  
    222222            User user = (User)infoObject;
    223223            try {
    224                 return getBaseUserUrl() + "/" + URLEncoder.encode(user.getName(), "UTF-8").replaceAll("\\+", "%20");
     224                return Main.getBaseUserUrl() + "/" + URLEncoder.encode(user.getName(), "UTF-8").replaceAll("\\+", "%20");
    225225            } catch(UnsupportedEncodingException e) {
    226226                Main.error(e);
  • trunk/src/org/openstreetmap/josm/gui/history/VersionInfoPanel.java

    r7299 r7678  
    2020
    2121import org.openstreetmap.josm.Main;
    22 import org.openstreetmap.josm.actions.AbstractInfoAction;
    2322import org.openstreetmap.josm.data.osm.Changeset;
    2423import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    169168
    170169    protected static String getUserUrl(String username) throws UnsupportedEncodingException {
    171         return AbstractInfoAction.getBaseUserUrl() + "/" +  URLEncoder.encode(username, "UTF-8").replaceAll("\\+", "%20");
     170        return Main.getBaseUserUrl() + "/" +  URLEncoder.encode(username, "UTF-8").replaceAll("\\+", "%20");
    172171    }
    173172
     
    181180        if (!model.isLatest(primitive)) {
    182181            User user = primitive.getUser();
    183             String url = AbstractInfoAction.getBaseBrowseUrl() + "/changeset/" + primitive.getChangesetId();
     182            String url = Main.getBaseBrowseUrl() + "/changeset/" + primitive.getChangesetId();
    184183            lblChangeset.setUrl(url);
    185184            lblChangeset.setDescription(Long.toString(primitive.getChangesetId()));
  • trunk/src/org/openstreetmap/josm/gui/history/VersionTable.java

    r6915 r7678  
    156156        protected String createInfoUrl(Object infoObject) {
    157157            HistoryOsmPrimitive primitive = (HistoryOsmPrimitive) infoObject;
    158             return getBaseBrowseUrl() + "/changeset/" + primitive.getChangesetId();
     158            return Main.getBaseBrowseUrl() + "/changeset/" + primitive.getChangesetId();
    159159        }
    160160
     
    186186        protected String createInfoUrl(Object infoObject) {
    187187            HistoryOsmPrimitive hp = (HistoryOsmPrimitive) infoObject;
    188             return hp.getUser() == null ? null : getBaseUserUrl() + "/" + hp.getUser().getName();
     188            return hp.getUser() == null ? null : Main.getBaseUserUrl() + "/" + hp.getUser().getName();
    189189        }
    190190
  • trunk/src/org/openstreetmap/josm/io/MessageNotifier.java

    r7434 r7678  
    6767                            JPanel panel = new JPanel(new GridBagLayout());
    6868                            panel.add(new JLabel(trn("You have {0} unread message.", "You have {0} unread messages.", unread, unread)), GBC.eol());
    69                             panel.add(new UrlLabel(Main.getOSMWebsite() + "/user/"+userInfo.getDisplayName()+"/inbox", tr("Click here to see your inbox.")), GBC.eol());
     69                            panel.add(new UrlLabel(Main.getBaseUserUrl() + "/"+userInfo.getDisplayName()+"/inbox", tr("Click here to see your inbox.")), GBC.eol());
    7070                            panel.setOpaque(false);
    7171                            new Notification().setContent(panel)
Note: See TracChangeset for help on using the changeset viewer.