Changeset 18427 in josm for trunk/src


Ignore:
Timestamp:
2022-04-04T22:26:00+02:00 (3 years ago)
Author:
taylor.smock
Message:

Fix an NPE that occurred when attempting to copy an image URL

This occurred when the user
1) Downloaded images from Wikimedia Commons
2) Attempted to open the image in an external program

This patch also fixes an issue where image paths, when copied with the
Copy image path action and were to remote resources, could have a /
removed from the protocol (https://example.org -> https:/example.org).

Location:
trunk/src/org/openstreetmap/josm
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/street_level/IImageEntry.java

    r18290 r18427  
    66import java.io.File;
    77import java.io.IOException;
     8import java.net.URI;
    89import java.time.Instant;
    910import java.util.List;
     
    158159
    159160    /**
     161     * Get the URI for the image
     162     * @return The image URI
     163     * @since 18427
     164     */
     165    default URI getImageURI() {
     166        return this.getFile().toURI();
     167    }
     168
     169    /**
    160170     * Returns the position value. The position value from the temporary copy
    161171     * is returned if that copy exists.
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

    r18300 r18427  
    484484        public void actionPerformed(ActionEvent e) {
    485485            if (currentEntry != null) {
    486                 ClipboardUtils.copyString(String.valueOf(currentEntry.getFile()));
     486                ClipboardUtils.copyString(String.valueOf(currentEntry.getImageURI()));
    487487            }
    488488        }
     
    511511            if (currentEntry != null) {
    512512                try {
    513                     PlatformManager.getPlatform().openUrl(currentEntry.getFile().toURI().toURL().toExternalForm());
     513                    PlatformManager.getPlatform().openUrl(currentEntry.getImageURI().toURL().toExternalForm());
    514514                } catch (IOException ex) {
    515515                    Logging.error(ex);
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/WikimediaCommonsEntry.java

    r18217 r18427  
    33
    44import java.net.MalformedURLException;
     5import java.net.URI;
     6import java.net.URISyntaxException;
    57import java.net.URL;
    68import java.util.Objects;
    79
    810import org.openstreetmap.josm.data.coor.LatLon;
     11import org.openstreetmap.josm.tools.JosmRuntimeException;
    912import org.openstreetmap.josm.tools.Mediawiki;
    1013
     
    2326    protected URL getImageUrl() throws MalformedURLException {
    2427        return new URL(Mediawiki.getImageUrl("https://upload.wikimedia.org/wikipedia/commons", title));
     28    }
     29
     30    @Override
     31    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        }
    2538    }
    2639
Note: See TracChangeset for help on using the changeset viewer.