diff --git a/src/org/openstreetmap/josm/gui/GettingStarted.java b/src/org/openstreetmap/josm/gui/GettingStarted.java
index 6fbdaca..be1310a 100644
|
a
|
b
|
import java.awt.BorderLayout;
|
| 8 | 8 | import java.awt.EventQueue; |
| 9 | 9 | import java.awt.event.InputEvent; |
| 10 | 10 | import java.awt.event.KeyEvent; |
| | 11 | import java.io.IOException; |
| 11 | 12 | import java.io.UnsupportedEncodingException; |
| 12 | 13 | import java.net.URL; |
| 13 | 14 | import java.util.regex.Matcher; |
| … |
… |
public class GettingStarted extends JPanel {
|
| 56 | 57 | /** |
| 57 | 58 | * Grabs current MOTD from cache or webpage and parses it. |
| 58 | 59 | */ |
| 59 | | private static class MotdContent extends CacheCustomContent<RuntimeException> { |
| | 60 | private static class MotdContent extends CacheCustomContent<IOException> { |
| 60 | 61 | public MotdContent() { |
| 61 | 62 | super("motd.html", CacheCustomContent.INTERVAL_DAILY); |
| 62 | 63 | } |
| … |
… |
public class GettingStarted extends JPanel {
|
| 69 | 70 | * @see org.openstreetmap.josm.io.CacheCustomContent#updateData() |
| 70 | 71 | */ |
| 71 | 72 | @Override |
| 72 | | protected byte[] updateData() { |
| | 73 | protected byte[] updateData() throws IOException { |
| 73 | 74 | 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 | | } |
| 78 | 75 | // Save this to prefs in case JOSM is updated so MOTD can be refreshed |
| 79 | 76 | Main.pref.putInteger("cache.motd.html.version", myVersion); |
| 80 | 77 | Main.pref.put("cache.motd.html.lang", myLang); |
| … |
… |
public class GettingStarted extends JPanel {
|
| 117 | 114 | |
| 118 | 115 | // Asynchronously get MOTD to speed-up JOSM startup |
| 119 | 116 | Thread t = new Thread(new Runnable() { |
| | 117 | @Override |
| 120 | 118 | 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 | } |
| 123 | 127 | } |
| 124 | 128 | |
| 125 | 129 | EventQueue.invokeLater(new Runnable() { |
| | 130 | @Override |
| 126 | 131 | public void run() { |
| 127 | 132 | lg.setText(fixImageLinks(content)); |
| 128 | 133 | // lg.moveCaretPosition(0); |
diff --git a/src/org/openstreetmap/josm/tools/WikiReader.java b/src/org/openstreetmap/josm/tools/WikiReader.java
index 5bf80b8..f83d694 100644
|
a
|
b
|
|
| 1 | 1 | // License: GPL. Copyright 2007 by Immanuel Scholz and others |
| 2 | 2 | package org.openstreetmap.josm.tools; |
| 3 | 3 | |
| 4 | | import static org.openstreetmap.josm.tools.I18n.tr; |
| 5 | | |
| 6 | 4 | import java.io.BufferedReader; |
| 7 | 5 | import java.io.IOException; |
| 8 | 6 | import java.io.InputStream; |
| … |
… |
public class WikiReader {
|
| 44 | 42 | return readNormal(in); |
| 45 | 43 | } |
| 46 | 44 | |
| 47 | | public String readLang(String text) { |
| | 45 | public String readLang(String text) throws IOException { |
| 48 | 46 | 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)); |
| 69 | 50 | } |
| 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; |
| 98 | 55 | } |
| 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"))); |
| 100 | 61 | } |
| 101 | 62 | |
| 102 | 63 | private String readNormal(BufferedReader in) throws IOException { |