### Eclipse Workspace Patch 1.0
#P josm
diff --git src/org/openstreetmap/josm/gui/layer/geoimage/WikimediaCommonsEntry.java src/org/openstreetmap/josm/gui/layer/geoimage/WikimediaCommonsEntry.java
index 8df45ae..8aa4e61 100644
|
|
|
|
| 3 | 3 | |
| 4 | 4 | import java.net.MalformedURLException; |
| 5 | 5 | import java.net.URI; |
| 6 | | import java.net.URISyntaxException; |
| 7 | 6 | import java.net.URL; |
| 8 | 7 | import java.util.Objects; |
| 9 | 8 | |
| 10 | 9 | import org.openstreetmap.josm.data.coor.LatLon; |
| 11 | | import org.openstreetmap.josm.tools.JosmRuntimeException; |
| 12 | 10 | import org.openstreetmap.josm.tools.Mediawiki; |
| 13 | 11 | |
| 14 | 12 | /** |
| 15 | 13 | * A geocoded image from <a href="https://commons.wikimedia.org/">Wikimedia Commons</a> |
| 16 | 14 | */ |
| 17 | 15 | class WikimediaCommonsEntry extends ImageEntry { |
| | 16 | private static final String COMMONS_BASE_URL = "https://upload.wikimedia.org/wikipedia/commons"; |
| 18 | 17 | private final String title; |
| 19 | 18 | |
| 20 | 19 | WikimediaCommonsEntry(String title, LatLon latLon) { |
| 21 | | this.title = title.replaceFirst("^File:", "").replace(" ", "_"); |
| 22 | | setPos(latLon); |
| | 20 | Objects.requireNonNull(title, "Title must not be null"); |
| | 21 | this.title = title.trim() |
| | 22 | .replaceFirst("^(?i)File:", "") |
| | 23 | .replace("\\s+", "_"); |
| | 24 | |
| | 25 | if (latLon != null) { |
| | 26 | setPos(latLon); |
| | 27 | } |
| 23 | 28 | } |
| 24 | 29 | |
| 25 | 30 | @Override |
| 26 | 31 | protected URL getImageUrl() throws MalformedURLException { |
| 27 | | return new URL(Mediawiki.getImageUrl("https://upload.wikimedia.org/wikipedia/commons", title)); |
| | 32 | try { |
| | 33 | return getImageURI().toURL(); |
| | 34 | } catch (IllegalArgumentException | MalformedURLException e) { |
| | 35 | throw new MalformedURLException("Invalid Commons URL for '" + title + "': " + e.getMessage()); |
| | 36 | } |
| 28 | 37 | } |
| 29 | 38 | |
| 30 | 39 | @Override |
| 31 | 40 | public URI getImageURI() { |
| 32 | | try { |
| 33 | | return new URI(Mediawiki.getImageUrl("https://upload.wikimedia.org/wikipedia/commons", this.title)); |
| 34 | | } catch (URISyntaxException e) { |
| 35 | | // This should never happen. |
| 36 | | throw new JosmRuntimeException(this.toString(), e); |
| 37 | | } |
| | 41 | return URI.create(Mediawiki.getImageUrl(COMMONS_BASE_URL, title)); |
| 38 | 42 | } |
| 39 | 43 | |
| 40 | 44 | @Override |
| … |
… |
|
| 44 | 48 | |
| 45 | 49 | @Override |
| 46 | 50 | public String toString() { |
| 47 | | return "File:" + title; |
| | 51 | return getDisplayName(); |
| 48 | 52 | } |
| 49 | 53 | |
| 50 | 54 | @Override |
| 51 | 55 | public int hashCode() { |
| 52 | | return 31 * super.hashCode() + Objects.hash(title); |
| | 56 | return 31 * super.hashCode() + Objects.hash(title); |
| 53 | 57 | } |
| 54 | 58 | |
| 55 | 59 | @Override |
| 56 | 60 | public boolean equals(Object obj) { |
| 57 | | if (this == obj) |
| 58 | | return true; |
| 59 | | if (!super.equals(obj) || getClass() != obj.getClass()) |
| | 61 | if (this == obj) { |
| | 62 | return true; |
| | 63 | } |
| | 64 | |
| | 65 | if (obj == null || getClass() != obj.getClass()) { |
| 60 | 66 | return false; |
| 61 | | WikimediaCommonsEntry other = (WikimediaCommonsEntry) obj; |
| | 67 | } |
| | 68 | |
| | 69 | if (!super.equals(obj)) { |
| | 70 | return false; |
| | 71 | } |
| | 72 | |
| | 73 | final WikimediaCommonsEntry other = (WikimediaCommonsEntry) obj; |
| 62 | 74 | return Objects.equals(title, other.title); |
| 63 | 75 | } |
| 64 | 76 | } |