Changeset 14480 in josm for trunk/src/org


Ignore:
Timestamp:
2018-12-01T21:27:53+01:00 (5 years ago)
Author:
Don-vip
Message:

fix #16937 - Support user logins ending by " !"

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/AboutAction.java

    r14153 r14480  
    163163     */
    164164    private void setTextFromResourceFile(JTextArea ta, String filePath) {
    165         InputStream is = getClass().getResourceAsStream(filePath);
     165        InputStream is = Utils.getResourceAsStream(getClass(), filePath);
    166166        if (is == null) {
    167167            displayErrorMessage(ta, tr("Failed to locate resource ''{0}''.", filePath));
  • trunk/src/org/openstreetmap/josm/data/Version.java

    r14406 r14480  
    66import java.io.IOException;
    77import java.io.InputStream;
    8 import java.net.URL;
    9 import java.nio.file.InvalidPathException;
    108import java.util.Map.Entry;
    119import java.util.Optional;
     
    107105     */
    108106    public void init() {
    109         try (InputStream stream = openRevisionStream("/REVISION")) {
     107        try (InputStream stream = Utils.getResourceAsStream(getClass(), "/REVISION")) {
    110108            if (stream == null) {
    111109                Logging.warn(tr("The revision file ''/REVISION'' is missing."));
     
    120118    }
    121119
    122     private static InputStream openRevisionStream(String path) throws IOException {
    123         try {
    124             return Version.class.getResourceAsStream(path);
    125         } catch (InvalidPathException e) {
    126             Logging.error("Cannot open {0}: {1}", path, e.getMessage());
    127             URL betterUrl = Utils.betterJarUrl(Version.class.getResource(path));
    128             if (betterUrl != null) {
    129                 return betterUrl.openStream();
    130             }
    131             return null;
    132         }
    133     }
    134 
    135120    /**
    136121     * Replies the version string. Either the SVN revision "1234" (as string) or the
  • trunk/src/org/openstreetmap/josm/gui/GettingStarted.java

    r14273 r14480  
    176176            URL u = GettingStarted.class.getResource(im);
    177177            if (u != null) {
    178                 m.appendReplacement(sb, Matcher.quoteReplacement("src=\"" + u + '\"'));
     178                try {
     179                    m.appendReplacement(sb, Matcher.quoteReplacement("src=\"" + Utils.betterJarUrl(u, u) + '\"'));
     180                } catch (IOException e) {
     181                    Logging.error(e);
     182                }
    179183            }
    180184        }
  • trunk/src/org/openstreetmap/josm/gui/MainInitialization.java

    r14140 r14480  
    3333import org.openstreetmap.josm.spi.preferences.Config;
    3434import org.openstreetmap.josm.tools.I18n;
     35import org.openstreetmap.josm.tools.ImageProvider;
    3536import org.openstreetmap.josm.tools.Logging;
    3637import org.openstreetmap.josm.tools.OpenBrowser;
     
    140141                // hooks for the jmapviewer component
    141142                FeatureAdapter.registerBrowserAdapter(OpenBrowser::displayUrl);
     143                FeatureAdapter.registerImageAdapter(ImageProvider::read);
    142144                FeatureAdapter.registerTranslationAdapter(I18n::tr);
    143145                FeatureAdapter.registerLoggingAdapter(name -> Logging.getLogger());
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r14406 r14480  
    227227            if (name != null && name.startsWith("resource://")) {
    228228                String resourceName = name.substring("resource:/".length());
    229                 InputStream is = null;
    230                 try {
    231                     is = getClass().getResourceAsStream(resourceName);
    232                 } catch (InvalidPathException e) {
    233                     Logging.error("Cannot open {0}: {1}", resourceName, e.getMessage());
    234                     Logging.trace(e);
    235                 }
     229                InputStream is = Utils.getResourceAsStream(getClass(), resourceName);
    236230                if (is == null) {
    237                     URL resource = getClass().getResource(resourceName);
    238                     if (resource != null) {
    239                         // More robust way to open stream
    240                         is = Utils.openStream(resource);
    241                     }
    242                     if (is == null) {
    243                         throw new IOException(tr("Failed to open input stream for resource ''{0}''", name));
    244                     }
     231                    throw new IOException(tr("Failed to open input stream for resource ''{0}''", name));
    245232                }
    246233                return is;
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r14384 r14480  
    422422        String name = pluginName;
    423423        name = name.replaceAll("[-. ]", "");
    424         try (InputStream manifestStream = PluginInformation.class.getResourceAsStream("/org/openstreetmap/josm/plugins/"+name+"/MANIFEST.MF")) {
     424        try (InputStream manifestStream = Utils.getResourceAsStream(
     425                PluginInformation.class, "/org/openstreetmap/josm/plugins/"+name+"/MANIFEST.MF")) {
    425426            if (manifestStream != null) {
    426427                return new PluginInformation(manifestStream, pluginName, null);
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r14404 r14480  
    18711871     */
    18721872    public static URL betterJarUrl(URL jarUrl) throws IOException {
     1873        return betterJarUrl(jarUrl, null);
     1874    }
     1875
     1876    /**
     1877     * Tries to build a better JAR URL if we find it concerned by a JDK bug.
     1878     * @param jarUrl jar URL to test
     1879     * @param defaultUrl default URL to return
     1880     * @return potentially a better URL that won't provoke a JDK bug, or {@code defaultUrl}
     1881     * @throws IOException if an I/O error occurs
     1882     * @since 14480
     1883     */
     1884    public static URL betterJarUrl(URL jarUrl, URL defaultUrl) throws IOException {
    18731885        // Workaround to https://bugs.openjdk.java.net/browse/JDK-4523159
    18741886        String urlPath = jarUrl.getPath().replace("%20", " ");
     
    18881900            return new URL(jarUrl.getProtocol() + ':' + jarCopy.toUri().toURL().toExternalForm() + urlPath.substring(index));
    18891901        }
    1890         return null;
     1902        return defaultUrl;
     1903    }
     1904
     1905    /**
     1906     * Finds a resource with a given name, with robustness to known JDK bugs.
     1907     * @param klass class on which {@link Class#getResourceAsStream} will be called
     1908     * @param path name of the desired resource
     1909     * @return  A {@link java.io.InputStream} object or {@code null} if no resource with this name is found
     1910     * @since 14480
     1911     */
     1912    public static InputStream getResourceAsStream(Class<?> klass, String path) {
     1913        try {
     1914            return klass.getResourceAsStream(path);
     1915        } catch (InvalidPathException e) {
     1916            Logging.error("Cannot open {0}: {1}", path, e.getMessage());
     1917            try {
     1918                URL betterUrl = betterJarUrl(klass.getResource(path));
     1919                if (betterUrl != null) {
     1920                    return betterUrl.openStream();
     1921                }
     1922            } catch (IOException ex) {
     1923                Logging.error(ex);
     1924            }
     1925            return null;
     1926        }
    18911927    }
    18921928}
Note: See TracChangeset for help on using the changeset viewer.