Opened 15 years ago
Closed 15 years ago
#5692 closed defect (fixed)
users of imagery plugin don't see bing menu entry, because it uses old cache file from wms plugin
Reported by: | bastiK | Owned by: | team |
---|---|---|---|
Priority: | normal | Milestone: | |
Component: | Core | Version: | latest |
Keywords: | imagery | Cc: |
Description
The file http://josm.openstreetmap.de/maps has been updated to include the slippymap sources so it can be used by imagery plugin as well.
However the file is cached for 7 days, so it can happen that users install the imagery plugin and do not find bing aerial in the menu.
Attachments (0)
Change History (4)
comment:1 by , 15 years ago
comment:2 by , 15 years ago
An easy fix would be something like that:
Index: src/org/openstreetmap/josm/io/MirroredInputStream.java =================================================================== --- src/org/openstreetmap/josm/io/MirroredInputStream.java (revision 3691) +++ src/org/openstreetmap/josm/io/MirroredInputStream.java (working copy) @@ -26,6 +26,7 @@ public class MirroredInputStream extends InputStream { InputStream fs = null; File file = null; + String namespace = null; public MirroredInputStream(String name) throws IOException { this(name, null, -1L); @@ -40,6 +41,14 @@ } public MirroredInputStream(String name, String destDir, long maxTime) throws IOException { + this(name, destDir, maxTime, null); + } + + public MirroredInputStream(String name, String destDir, String namespace) throws IOException { + this(name, destDir, -1L, namespace); + } + + public MirroredInputStream(String name, String destDir, long maxTime, String namespace) throws IOException { URL url; try { url = new URL(name); @@ -49,7 +58,7 @@ file = new File(name.substring("file://".length())); } } else { - file = checkLocal(url, destDir, maxTime); + file = checkLocal(url, destDir, maxTime, namespace); } } catch (java.net.MalformedURLException e) { if(name.startsWith("resource://")) { @@ -65,7 +74,7 @@ throw new IOException(); fs = new FileInputStream(file); } - + /** * Replies an input stream for a file in a ZIP-file. Replies a file in the top * level directory of the ZIP file which has an extension <code>extension</code>. If more @@ -139,8 +148,13 @@ } catch (java.net.MalformedURLException e) {} } - private File checkLocal(URL url, String destDir, long maxTime) throws IOException { - String localPath = Main.pref.get("mirror." + url); + private File checkLocal(URL url, String destDir, long maxTime, String namespace) throws IOException { + String prefKey = "mirror."; + if (namespace != null) { + prefKey += namespace + "."; + } + prefKey += url; + String localPath = Main.pref.get(prefKey); File file = null; if (localPath != null && localPath.length() > 0) { String[] lp = localPath.split(";"); @@ -162,8 +176,7 @@ destDirFile.mkdirs(); } - String a = url.toString().replaceAll("[^A-Za-z0-9_.-]", "_"); - localPath = "mirror_" + a; + localPath = prefKey.replaceAll("[^A-Za-z0-9_.-]", "_"); destDirFile = new File(destDir, localPath + ".tmp"); BufferedOutputStream bos = null; BufferedInputStream bis = null; @@ -195,7 +208,7 @@ } file = new File(destDir, localPath); destDirFile.renameTo(file); - Main.pref.put("mirror." + url, System.currentTimeMillis() + ";" + file); + Main.pref.put(prefKey, System.currentTimeMillis() + ";" + file); } return file;
and
Index: src/org/openstreetmap/josm/plugins/imagery/ImageryLayerInfo.java =================================================================== --- src/org/openstreetmap/josm/plugins/imagery/ImageryLayerInfo.java (revision 24551) +++ src/org/openstreetmap/josm/plugins/imagery/ImageryLayerInfo.java (working copy) @@ -35,7 +35,7 @@ { try { - MirroredInputStream s = new MirroredInputStream(source, ImageryPlugin.instance.getPluginDir(), -1); + MirroredInputStream s = new MirroredInputStream(source, ImageryPlugin.instance.getPluginDir(), -1, "imagery"); InputStreamReader r; try {
that is, add a "salt" to the cache key the clear the cache file.
This is easy and straightforward and should work reliably. Disadvantage is, that it's somewhat ugly to always have this superfluous namespace string in the filename and preference key.
Another solution would be to have a method that is called when an plugin is installed ("install script"), to clear the cache file. This would be a little more complicated, but maybe needed in future anyway. Comments?
comment:3 by , 15 years ago
just noticed: in this case it would be easier to simply include the directory into the preference key. (This would basically clear all plugin cache files once.)
reported here: http://forum.openstreetmap.org/viewtopic.php?id=10188