### Eclipse Workspace Patch 1.0
#P josm
diff --git src/org/openstreetmap/josm/gui/help/HelpContentReader.java src/org/openstreetmap/josm/gui/help/HelpContentReader.java
index ce605ca..cebd6e4 100644
|
|
|
|
| 4 | 4 | import java.io.BufferedReader; |
| 5 | 5 | import java.io.IOException; |
| 6 | 6 | import java.net.MalformedURLException; |
| | 7 | import java.net.URI; |
| | 8 | import java.net.URISyntaxException; |
| 7 | 9 | import java.net.URL; |
| 8 | 10 | |
| 9 | 11 | import org.openstreetmap.josm.tools.HttpClient; |
| … |
… |
|
| 37 | 39 | * @param dotest if {@code true}, checks if help content is empty |
| 38 | 40 | * @return the content, filtered and transformed for being displayed in the internal help browser |
| 39 | 41 | * @throws HelpContentReaderException if problem occurs |
| 40 | | * @throws MissingHelpContentException if this helpTopicUrl doesn't point to an existing Wiki help page |
| 41 | 42 | */ |
| 42 | 43 | public String fetchHelpTopicContent(String helpTopicUrl, boolean dotest) throws HelpContentReaderException { |
| 43 | | if (helpTopicUrl == null) |
| 44 | | throw new MissingHelpContentException("helpTopicUrl is null"); |
| | 44 | if (helpTopicUrl == null || helpTopicUrl.isBlank()) { |
| | 45 | throw new HelpContentReaderException(new IllegalArgumentException("helpTopicUrl is null or blank"), 0); |
| | 46 | } |
| 45 | 47 | HttpClient.Response con = null; |
| 46 | 48 | try { |
| 47 | | URL u = new URL(helpTopicUrl); |
| | 49 | final URL u = new URI(helpTopicUrl).toURL(); |
| 48 | 50 | con = HttpClient.create(u).connect(); |
| | 51 | |
| 49 | 52 | try (BufferedReader in = con.getContentReader()) { |
| 50 | 53 | return prepareHelpContent(in, dotest, u); |
| 51 | 54 | } |
| 52 | | } catch (MalformedURLException e) { |
| | 55 | } catch (MalformedURLException | URISyntaxException e) { |
| 53 | 56 | throw new HelpContentReaderException(e, 0); |
| 54 | 57 | } catch (IOException e) { |
| 55 | | throw new HelpContentReaderException(e, con != null ? con.getResponseCode() : 0); |
| | 58 | int responseCode = 0; |
| | 59 | if (con != null) { |
| | 60 | try { |
| | 61 | responseCode = con.getResponseCode(); |
| | 62 | } catch (Exception ignored) { |
| | 63 | // do nothing |
| | 64 | } |
| | 65 | } |
| | 66 | throw new HelpContentReaderException(e, responseCode); |
| | 67 | } finally { |
| | 68 | if (con instanceof AutoCloseable) { |
| | 69 | try { |
| | 70 | ((AutoCloseable) con).close(); |
| | 71 | } catch (Exception ignored) { |
| | 72 | // do nothing |
| | 73 | } |
| | 74 | } |
| 56 | 75 | } |
| 57 | 76 | } |
| 58 | 77 | |
| … |
… |
|
| 78 | 97 | } catch (IOException e) { |
| 79 | 98 | throw new HelpContentReaderException(e, 0); |
| 80 | 99 | } |
| 81 | | if (dotest && s.isEmpty()) |
| 82 | | throw new MissingHelpContentException(s); |
| | 100 | if (dotest && s.isEmpty()) { |
| | 101 | throw new MissingHelpContentException(s); |
| | 102 | } |
| 83 | 103 | return s; |
| 84 | 104 | } |
| 85 | 105 | } |
diff --git test/unit/org/openstreetmap/josm/gui/help/HelpContentReaderTest.java test/unit/org/openstreetmap/josm/gui/help/HelpContentReaderTest.java
index f8f3299..2fc268b 100644
|
|
|
|
| 26 | 26 | */ |
| 27 | 27 | @Test |
| 28 | 28 | void testFetchHelpTopicContentNominal() throws HelpContentReaderException { |
| 29 | | String res = new HelpContentReader(HelpUtil.getWikiBaseUrl()).fetchHelpTopicContent(HelpBrowserTest.URL_1, false); |
| | 29 | final String res = new HelpContentReader(HelpUtil.getWikiBaseUrl()).fetchHelpTopicContent(HelpBrowserTest.URL_1, false); |
| 30 | 30 | assertFalse(res.isBlank()); |
| 31 | 31 | } |
| 32 | 32 | } |