Commit 0b374eb4 authored by Florian Schäfer's avatar Florian Schäfer

Add notification when download fails (e.g. when download area is too big)

parent 9dfab27e
......@@ -26,8 +26,11 @@ import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.openstreetmap.josm.data.coor.LatLon;
import org.openstreetmap.josm.data.osm.OsmPrimitive;
import org.openstreetmap.josm.gui.Notification;
import org.openstreetmap.josm.gui.datatransfer.ClipboardUtils;
import org.openstreetmap.josm.tools.HttpClient;
import org.openstreetmap.josm.tools.I18n;
import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.Logging;
import org.openstreetmap.josm.tools.Pair;
import org.openstreetmap.josm.tools.Utils;
......@@ -104,6 +107,13 @@ public final class WikipediaApp {
// parse XML document
try (InputStream in = connect(url).getContent()) {
final Document doc = newDocumentBuilder().parse(in);
final String errorInfo = X_PATH.evaluateString("//error/@info", doc);
if (errorInfo != null && errorInfo.length() >= 1) {
// I18n: {0} is the error message returned by the API
new Notification(I18n.tr("Downloading entries with geo coordinates failed: {0}", errorInfo))
.setIcon(WikipediaPlugin.W_IMAGE.setMaxSize(ImageProvider.ImageSizes.DEFAULT).get())
.show();
}
final List<WikipediaEntry> entries = X_PATH.evaluateNodes("//gs", doc).stream()
.map(node -> {
final String name = X_PATH.evaluateString("@title", node);
......@@ -117,7 +127,7 @@ public final class WikipediaApp {
}
}).collect(Collectors.toList());
if ("wikidata".equals(wikipediaLang)) {
return getLabelForWikidata(entries, Locale.getDefault()).stream().collect(Collectors.toList());
return new ArrayList<>(getLabelForWikidata(entries, Locale.getDefault()));
} else {
return entries;
}
......@@ -362,7 +372,7 @@ public final class WikipediaApp {
}
}
static List<WikidataEntry> getLabelForWikidata(List<? extends WikipediaEntry> entries, Locale locale, String... preferredLanguage) {
static List<WikidataEntry> getLabelForWikidata(final List<? extends WikipediaEntry> entries, final Locale locale, final String... preferredLanguage) {
final Collection<String> languages = new ArrayList<>();
if (locale != null) {
languages.add(getMediawikiLocale(locale));
......
......@@ -26,6 +26,7 @@ import org.wikipedia.validator.WikipediaAgainstWikidata;
public final class WikipediaPlugin extends Plugin {
public static final ImageIcon LOGO = ImageProvider.get("dialogs/wikipedia");
public static final ImageProvider W_IMAGE = new ImageProvider("w");
private static String name;
private static String versionInfo;
......
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="200" viewBox="-1.22 -1.27 30 20">
<path d="M10.76 3.62l-.5-1C9.44.98 9.46.9 8.62.78 8.37.74 8.25.71 8.25.6V.07l.07-.05h4.91l.13.04v.52c0 .12-.08.18-.26.18l-.35.06c-.9.07-.76.43-.16 1.62l5.68 11.62.2.05L23.5 2.15c.18-.48.15-.82-.07-1.02-.23-.2-.39-.32-.97-.34l-.48-.02a.27.27 0 0 1-.16-.06.17.17 0 0 1-.08-.15v-.5l.07-.05h5.7l.05.05v.5c0 .14-.07.2-.23.2-.74.04-1.3.2-1.65.49-.36.29-.64.69-.84 1.21 0 0-4.64 10.6-6.22 14.14-.61 1.15-1.2 1.05-1.73-.04-1.11-2.28-4.24-9.21-4.24-9.21z"/>
<path d="M19.85.01h-4.63l-.07.05v.5c0 .06.03.1.08.14.05.04.1.06.17.06l.23.03c.58.02.85.17.93.27.14.17.2.35-.13 1.09l-5.98 11.93-.16-.04S6.01 5 4.77 1.97a2.04 2.04 0 0 1-.19-.69c0-.3.28-.47.83-.5l.65-.02c.17 0 .25-.07.25-.2v-.5L6.26.02H.06L.02.07V.6c0 .1.12.15.36.18.65.04 1.08.14 1.28.31.2.18.42.62.71 1.3C3.92 6.14 7.23 12.8 8.84 16.6c.46 1.04 1.04 1.2 1.75-.03 1.23-2.27 4.55-9.22 4.55-9.22l2.62-4.9c.3-.51.6-.97.75-1.19.27-.39.42-.46 1.17-.5.15 0 .23-.07.23-.2v-.5z"/>
</svg>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment