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


Ignore:
Timestamp:
2012-03-08T22:03:42+01:00 (12 years ago)
Author:
simon04
Message:

see #7395 - don't cache erroneously downloaded MOTD

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r4865 r5061  
    99import java.awt.event.InputEvent;
    1010import java.awt.event.KeyEvent;
     11import java.io.IOException;
    1112import java.io.UnsupportedEncodingException;
    1213import java.net.URL;
     
    5758     * Grabs current MOTD from cache or webpage and parses it.
    5859     */
    59     private static class MotdContent extends CacheCustomContent<RuntimeException> {
     60    private static class MotdContent extends CacheCustomContent<IOException> {
    6061        public MotdContent() {
    6162            super("motd.html", CacheCustomContent.INTERVAL_DAILY);
     
    7071         */
    7172        @Override
    72         protected byte[] updateData() {
     73        protected byte[] updateData() throws IOException {
    7374            String motd = new WikiReader().readLang("StartupPage");
    74             if (motd.length() == 0) {
    75                 motd = "<html>" + STYLE + "<h1>" + "JOSM - " + tr("Java OpenStreetMap Editor")
    76                 + "</h1>\n<h2 align=\"center\">(" + tr("Message of the day not available") + ")</h2></html>";
    77             }
    7875            // Save this to prefs in case JOSM is updated so MOTD can be refreshed
    7976            Main.pref.putInteger("cache.motd.html.version", myVersion);
     
    118115        // Asynchronously get MOTD to speed-up JOSM startup
    119116        Thread t = new Thread(new Runnable() {
     117            @Override
    120118            public void run() {
    121                 if (content.length() == 0 && Main.pref.getBoolean("help.displaymotd", true)) {
    122                     content = new MotdContent().updateIfRequiredString();
     119                if (content.isEmpty() && Main.pref.getBoolean("help.displaymotd", true)) {
     120                    try {
     121                        content = new MotdContent().updateIfRequiredString();
     122                    } catch (IOException ex) {
     123                        System.out.println(tr("Warning: failed to read MOTD. Exception was: {1}", ex.toString()));
     124                        content = "<html>" + STYLE + "<h1>" + "JOSM - " + tr("Java OpenStreetMap Editor")
     125                                + "</h1>\n<h2 align=\"center\">(" + tr("Message of the day not available") + ")</h2></html>";
     126                    }
    123127                }
    124128
    125129                EventQueue.invokeLater(new Runnable() {
     130                    @Override
    126131                    public void run() {
    127132                        lg.setText(fixImageLinks(content));
  • trunk/src/org/openstreetmap/josm/tools/WikiReader.java

    r4915 r5061  
    11// License: GPL. Copyright 2007 by Immanuel Scholz and others
    22package org.openstreetmap.josm.tools;
    3 
    4 import static org.openstreetmap.josm.tools.I18n.tr;
    53
    64import java.io.BufferedReader;
     
    4543    }
    4644
    47     public String readLang(String text) {
     45    public String readLang(String text) throws IOException {
    4846        String languageCode = LanguageInfo.getWikiLanguagePrefix();
    49         String url = baseurl + "/wiki/" + languageCode + text;
    50         String res = "";
    51         InputStream in = null;
    52         try {
    53             in = new URL(url).openStream();
    54             res = readFromTrac(new BufferedReader(new InputStreamReader(in, "utf-8")));
    55         } catch (IOException ioe) {
    56             System.out.println(tr("Warning: failed to read MOTD from ''{0}''. Exception was: {1}", url, ioe
    57                     .toString()));
    58         } catch(SecurityException e) {
    59             System.out.println(tr(
    60                     "Warning: failed to read MOTD from ''{0}'' for security reasons. Exception was: {1}", url, e
    61                     .toString()));
    62         } finally {
    63             if (in != null) {
    64                 try {
    65                     in.close();
    66                 } catch (IOException e) {
    67                 }
    68             }
     47        String res = readLang(new URL(baseurl + "/wiki/" + languageCode + text));
     48        if (res.isEmpty() && !languageCode.isEmpty()) {
     49            res = readLang(new URL(baseurl + "/wiki/" + text));
    6950        }
    70         if (res.length() == 0 && languageCode.length() != 0) {
    71             url = baseurl + "/wiki/" + text;
    72             try {
    73                 in = new URL(url).openStream();
    74             } catch (IOException e) {
    75                 System.out.println(tr("Warning: failed to read MOTD from ''{0}''. Exception was: {1}", url, e
    76                         .toString()));
    77                 return res;
    78             } catch (SecurityException e) {
    79                 System.out.println(tr(
    80                         "Warning: failed to read MOTD from ''{0}'' for security reasons. Exception was: {1}", url, e
    81                         .toString()));
    82                 return res;
    83             }
    84             try {
    85                 res = readFromTrac(new BufferedReader(new InputStreamReader(in, "utf-8")));
    86             } catch (IOException ioe) {
    87                 System.out.println(tr("Warning: failed to read MOTD from ''{0}''. Exception was: {1}", url, ioe
    88                         .toString()));
    89                 return res;
    90             } finally {
    91                 if (in != null) {
    92                     try {
    93                         in.close();
    94                     } catch (IOException e) {
    95                     }
    96                 }
    97             }
     51        if (res.isEmpty()) {
     52            throw new IOException(text + " does not exist");
     53        } else {
     54            return res;
    9855        }
    99         return res;
     56    }
     57
     58    private String readLang(URL url) throws IOException {
     59        InputStream in = url.openStream();
     60        return readFromTrac(new BufferedReader(new InputStreamReader(in, "utf-8")));
    10061    }
    10162
Note: See TracChangeset for help on using the changeset viewer.