Changeset 13536 in josm for trunk/src/org/openstreetmap/josm/io/CachedFile.java
- Timestamp:
- 2018-03-17T17:01:12+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/CachedFile.java
r13204 r13536 75 75 protected File cacheFile; 76 76 protected boolean initialized; 77 protected String parameter; 77 78 78 79 public static final long DEFAULT_MAXTIME = -1L; … … 173 174 } 174 175 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 175 185 public String getName() { 186 if(parameter != null) 187 return name.replaceAll("%<(.*)>", ""); 176 188 return name; 177 189 } … … 284 296 } 285 297 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()); 287 299 return cacheFile; 288 300 } … … 298 310 * @param extension the extension of the file we're looking for 299 311 * @param namepart the name part 300 * @return The zip entry path of the matching file. Nullif this cached file312 * @return The zip entry path of the matching file. <code>null</code> if this cached file 301 313 * doesn't represent a zip file or if there was no matching 302 314 * file in the ZIP file. … … 312 324 * @param extension the extension of the file we're looking for 313 325 * @param namepart the name part 314 * @return InputStream to the matching file. Nullif this cached file326 * @return InputStream to the matching file. <code>null</code> if this cached file 315 327 * doesn't represent a zip file or if there was no matching 316 328 * file in the ZIP file. … … 380 392 url = new URL(name); 381 393 if (!"file".equals(url.getProtocol())) { 382 String prefKey = getPrefKey(url, destDir );394 String prefKey = getPrefKey(url, destDir, null); 383 395 List<String> localPath = new ArrayList<>(Config.getPref().getList(prefKey)); 384 396 if (localPath.size() == 2) { … … 403 415 * @return Preference key 404 416 */ 405 private static String getPrefKey(URL url, String destDir ) {417 private static String getPrefKey(URL url, String destDir, String parameter) { 406 418 StringBuilder prefKey = new StringBuilder("mirror."); 407 419 if (destDir != null) { 408 420 prefKey.append(destDir).append('.'); 409 421 } 410 prefKey.append(url.toString()); 422 if (parameter != null) { 423 prefKey.append(url.toString().replaceAll("%<(.*)>", "")); 424 } else { 425 prefKey.append(url.toString()); 426 } 411 427 return prefKey.toString().replaceAll("=", "_"); 412 428 } 413 429 414 430 private File checkLocal(URL url) throws IOException { 415 String prefKey = getPrefKey(url, destDir );431 String prefKey = getPrefKey(url, destDir, parameter); 416 432 String urlStr = url.toExternalForm(); 433 if (parameter != null) 434 urlStr = urlStr.replaceAll("%<(.*)>", ""); 417 435 long age = 0L; 418 436 long maxAgeMillis = maxAge; … … 460 478 } 461 479 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 462 492 String a = urlStr.replaceAll("[^A-Za-z0-9_.-]", "_"); 463 493 String localPath = "mirror_" + a;
Note:
See TracChangeset
for help on using the changeset viewer.