Ignore:
Timestamp:
2012-11-17T14:08:43+01:00 (11 years ago)
Author:
Don-vip
Message:

fix #8201 - Error handling or redacted items

File:
1 edited

Legend:

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

    r5275 r5584  
    1010import java.net.SocketException;
    1111import java.net.UnknownHostException;
     12import java.util.regex.Matcher;
     13import java.util.regex.Pattern;
    1214
    1315import javax.swing.JOptionPane;
     
    242244    }
    243245
     246    private static boolean isOAuth() {
     247        return Main.pref.get("osm-server.auth-method", "basic").equals("oauth");
     248    }
     249   
    244250    /**
    245251     * Explains a {@link OsmApiException} which was thrown because the authentication at
     
    249255     */
    250256    public static void explainAuthenticationFailed(OsmApiException e) {
    251         String authMethod = Main.pref.get("osm-server.auth-method", "basic");
    252257        String msg;
    253         if (authMethod.equals("oauth")) {
     258        if (isOAuth()) {
    254259            msg = ExceptionUtil.explainFailedOAuthAuthentication(e);
    255260        } else {
     
    268273    /**
    269274     * Explains a {@link OsmApiException} which was thrown because accessing a protected
    270      * resource was forbidden.
     275     * resource was forbidden (HTTP 403).
    271276     *
    272277     * @param e the exception
    273278     */
    274279    public static void explainAuthorizationFailed(OsmApiException e) {
    275         // Fixme: add special handling that calls ExceptionUtil.explainFailedOAuthAuthorisation(e)
    276         HelpAwareOptionPane.showOptionDialog(
    277                 Main.parent,
    278                 ExceptionUtil.explainFailedAuthorisation(e),
     280       
     281        Matcher m;
     282        String msg;
     283        String url = e.getAccessedUrl();
     284        Pattern p = Pattern.compile("http://.*/api/0.6/(node|way|relation)/(\\d+)/(\\d+)");
     285       
     286        // Special case for individual access to redacted versions
     287        // See http://wiki.openstreetmap.org/wiki/Open_Database_License/Changes_in_the_API
     288        if (url != null && (m = p.matcher(url)).matches()) {
     289            String type = m.group(1);
     290            String id = m.group(2);
     291            String version = m.group(3);
     292            // {1} is the translation of "node", "way" or "relation"
     293            msg = tr("Access to redacted version ''{0}'' of {1} {2} is forbidden.",
     294                    version, tr(type), id);
     295        } else if (isOAuth()) {
     296            msg = ExceptionUtil.explainFailedOAuthAuthorisation(e);
     297        } else {
     298            msg = ExceptionUtil.explainFailedAuthorisation(e);
     299        }
     300       
     301        HelpAwareOptionPane.showOptionDialog(
     302                Main.parent,
     303                msg,
    279304                tr("Authorisation Failed"),
    280305                JOptionPane.ERROR_MESSAGE,
    281                 ht("/ErrorMessages#AuthenticationFailed")
     306                ht("/ErrorMessages#AuthorizationFailed")
    282307        );
    283308    }
Note: See TracChangeset for help on using the changeset viewer.