Ignore:
Timestamp:
2018-03-17T17:01:12+01:00 (6 years ago)
Author:
stoecker
Message:

add possibility to change map ids (see #14655), add overlay flag for imagery

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/CachedFile.java

    r13204 r13536  
    7575    protected File cacheFile;
    7676    protected boolean initialized;
     77    protected String parameter;
    7778
    7879    public static final long DEFAULT_MAXTIME = -1L;
     
    173174    }
    174175
     176    /**
     177     * Sets additional URL parameter (used e.g. for maps)
     178     * @param parameter the URL parameter
     179     * @since 13536
     180     */
     181    public void setParam(String parameter) {
     182        this.parameter = parameter;
     183    }
     184
    175185    public String getName() {
     186        if(parameter != null)
     187            return name.replaceAll("%<(.*)>", "");
    176188        return name;
    177189    }
     
    284296        }
    285297        if (cacheFile == null)
    286             throw new IOException("Unable to get cache file for "+name);
     298            throw new IOException("Unable to get cache file for "+getName());
    287299        return cacheFile;
    288300    }
     
    298310     * @param extension  the extension of the file we're looking for
    299311     * @param namepart the name part
    300      * @return The zip entry path of the matching file. Null if this cached file
     312     * @return The zip entry path of the matching file. <code>null</code> if this cached file
    301313     * doesn't represent a zip file or if there was no matching
    302314     * file in the ZIP file.
     
    312324     * @param extension  the extension of the file we're looking for
    313325     * @param namepart the name part
    314      * @return InputStream to the matching file. Null if this cached file
     326     * @return InputStream to the matching file. <code>null</code> if this cached file
    315327     * doesn't represent a zip file or if there was no matching
    316328     * file in the ZIP file.
     
    380392            url = new URL(name);
    381393            if (!"file".equals(url.getProtocol())) {
    382                 String prefKey = getPrefKey(url, destDir);
     394                String prefKey = getPrefKey(url, destDir, null);
    383395                List<String> localPath = new ArrayList<>(Config.getPref().getList(prefKey));
    384396                if (localPath.size() == 2) {
     
    403415     * @return Preference key
    404416     */
    405     private static String getPrefKey(URL url, String destDir) {
     417    private static String getPrefKey(URL url, String destDir, String parameter) {
    406418        StringBuilder prefKey = new StringBuilder("mirror.");
    407419        if (destDir != null) {
    408420            prefKey.append(destDir).append('.');
    409421        }
    410         prefKey.append(url.toString());
     422        if (parameter != null) {
     423            prefKey.append(url.toString().replaceAll("%<(.*)>", ""));
     424        } else {
     425            prefKey.append(url.toString());
     426        }
    411427        return prefKey.toString().replaceAll("=", "_");
    412428    }
    413429
    414430    private File checkLocal(URL url) throws IOException {
    415         String prefKey = getPrefKey(url, destDir);
     431        String prefKey = getPrefKey(url, destDir, parameter);
    416432        String urlStr = url.toExternalForm();
     433        if (parameter != null)
     434            urlStr = urlStr.replaceAll("%<(.*)>", "");
    417435        long age = 0L;
    418436        long maxAgeMillis = maxAge;
     
    460478        }
    461479
     480        if(parameter != null) {
     481            String u = url.toExternalForm();
     482            String uc;
     483            if("".equals(parameter)) {
     484                uc = u.replaceAll("%<(.*)>", "");
     485            } else {
     486                uc = u.replaceAll("%<(.*)>", "$1"+parameter);
     487            }
     488            if(!uc.equals(u))
     489                url = new URL(uc);
     490        }
     491
    462492        String a = urlStr.replaceAll("[^A-Za-z0-9_.-]", "_");
    463493        String localPath = "mirror_" + a;
Note: See TracChangeset for help on using the changeset viewer.