Changeset 15423 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/tagging/presets/items/Link.java
r14649 r15423 7 7 import java.util.Arrays; 8 8 import java.util.Collection; 9 import java.util.List;10 9 import java.util.Optional; 11 10 … … 22 21 /** 23 22 * Hyperlink type. 23 * @since 8863 24 24 */ 25 25 public class Link extends TextItem { … … 37 37 public boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) { 38 38 initializeLocaleText(tr("More information about this feature")); 39 Optional.ofNullable(buildUrlLabel()).ifPresent(label -> p.add(label, GBC.eol().insets(0, 10, 0, 0).fill(GBC.HORIZONTAL))); 40 return false; 41 } 42 43 protected UrlLabel buildUrlLabel() { 44 final String url = getUrl(); 39 45 if (wiki != null) { 40 final String url = Config.getUrls().getOSMWiki() + "/wiki/" + wiki; 41 final UrlLabel label = new UrlLabel(url, locale_text, 2) { 46 return new UrlLabel(url, locale_text, 2) { 42 47 @Override 43 48 public void mouseClicked(MouseEvent e) { 44 49 if (SwingUtilities.isLeftMouseButton(e)) { 45 50 // Open localized page if exists 46 final List<String> pages =Arrays.asList(51 HelpAction.displayHelp(Arrays.asList( 47 52 LanguageInfo.getWikiLanguagePrefix(LanguageInfo.LocaleType.OSM_WIKI) + wiki, 48 wiki); 49 HelpAction.displayHelp(pages); 53 wiki)); 50 54 } else { 51 55 super.mouseClicked(e); … … 53 57 } 54 58 }; 55 p.add(label, GBC.eol().insets(0, 10, 0, 0).fill(GBC.HORIZONTAL));56 59 } else if (href != null || locale_href != null) { 57 final String url = Optional.ofNullable(locale_href).orElse(href); 58 final UrlLabel label = new UrlLabel(url, locale_text, 2); 59 p.add(label, GBC.eol().insets(0, 10, 0, 0).fill(GBC.HORIZONTAL)); 60 return new UrlLabel(url, locale_text, 2); 60 61 } 61 return false; 62 return null; 63 } 64 65 /** 66 * Returns the link URL. 67 * @return the link URL 68 * @since 15423 69 */ 70 public String getUrl() { 71 if (wiki != null) { 72 return Config.getUrls().getOSMWiki() + "/wiki/" + wiki; 73 } else if (href != null || locale_href != null) { 74 return Optional.ofNullable(locale_href).orElse(href); 75 } 76 return null; 62 77 } 63 78 -
trunk/src/org/openstreetmap/josm/tools/HttpClient.java
r15389 r15423 821 821 } 822 822 823 private static boolean isRedirect(final int statusCode) { 823 /** 824 * Determines if the given status code is an HTTP redirection. 825 * @param statusCode HTTP status code 826 * @return {@code true} if the given status code is an HTTP redirection 827 * @since 15423 828 */ 829 public static boolean isRedirect(final int statusCode) { 824 830 switch (statusCode) { 825 831 case HttpURLConnection.HTTP_MOVED_PERM: // 301 -
trunk/test/unit/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreferenceTestIT.java
r15101 r15423 8 8 9 9 import java.io.IOException; 10 import java.net.URL; 10 11 import java.util.Collection; 11 12 import java.util.HashSet; … … 28 29 import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset; 29 30 import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetReader; 31 import org.openstreetmap.josm.gui.tagging.presets.items.Link; 30 32 import org.openstreetmap.josm.spi.preferences.Config; 31 33 import org.openstreetmap.josm.testutils.JOSMTestRules; 34 import org.openstreetmap.josm.tools.HttpClient; 35 import org.openstreetmap.josm.tools.HttpClient.Response; 32 36 import org.openstreetmap.josm.tools.ImageProvider; 33 37 import org.openstreetmap.josm.tools.Logging; … … 113 117 assertFalse(presets.isEmpty()); 114 118 // wait for asynchronous icon loading 115 presets. stream().map(TaggingPreset::getIconLoadingTask).filter(Objects::nonNull).forEach(t -> {119 presets.parallelStream().map(TaggingPreset::getIconLoadingTask).filter(Objects::nonNull).forEach(t -> { 116 120 try { 117 121 t.get(30, TimeUnit.SECONDS); 118 122 } catch (InterruptedException | ExecutionException | TimeoutException e) { 123 Logging.error(e); 124 } 125 }); 126 // check that links are correct and not redirections 127 presets.parallelStream().flatMap(x -> x.data.stream().filter(i -> i instanceof Link).map(i -> ((Link) i).getUrl())).forEach(u -> { 128 try { 129 Response cr = HttpClient.create(new URL(u)).setMaxRedirects(-1).connect(); 130 final int code = cr.getResponseCode(); 131 if (HttpClient.isRedirect(code)) { 132 addOrIgnoreError(messages, "Found HTTP redirection for " + u + " -> " + code + " -> " + cr.getHeaderField("Location")); 133 } else if (code >= 400) { 134 addOrIgnoreError(messages, "Found HTTP error for " + u + " -> " + code); 135 } 136 } catch (IOException e) { 119 137 Logging.error(e); 120 138 } … … 125 143 if (message.contains(TaggingPreset.PRESET_ICON_ERROR_MSG_PREFIX)) { 126 144 error = true; 127 if (isIgnoredSubstring(message)) { 128 ignoredErrors.add(message); 129 } else { 130 messages.add(message); 131 } 145 addOrIgnoreError(messages, message); 132 146 } 133 147 } … … 136 150 } 137 151 } 152 153 void addOrIgnoreError(Set<String> messages, String message) { 154 if (isIgnoredSubstring(message)) { 155 ignoredErrors.add(message); 156 } else { 157 messages.add(message); 158 } 159 } 138 160 }
Note:
See TracChangeset
for help on using the changeset viewer.