Changeset 6867 in josm for trunk/src/org
- Timestamp:
- 2014-02-18T00:35:15+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/mappaint/MapPaintStyles.java
r6830 r6867 10 10 import java.util.Arrays; 11 11 import java.util.Collection; 12 import java.util.HashSet; 12 13 import java.util.LinkedList; 13 14 import java.util.List; 15 import java.util.Set; 14 16 import java.util.concurrent.CopyOnWriteArrayList; 15 17 … … 217 219 MirroredInputStream in = null; 218 220 try { 219 in = new MirroredInputStream(entry.url); 221 Set<String> mimes = new HashSet<String>(); 222 mimes.addAll(Arrays.asList(XmlStyleSource.XML_STYLE_MIME_TYPES.split(", "))); 223 mimes.addAll(Arrays.asList(MapCSSStyleSource.MAPCSS_STYLE_MIME_TYPES.split(", "))); 224 in = new MirroredInputStream(entry.url, null, Utils.join(", ", mimes)); 220 225 String zipEntryPath = in.findZipEntryPath("mapcss", "style"); 221 226 if (zipEntryPath != null) { -
trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/MapCSSStyleSource.java
r6736 r6867 34 34 35 35 public class MapCSSStyleSource extends StyleSource { 36 37 /** 38 * The accepted MIME types sent in the HTTP Accept header. 39 * @since 6867 40 */ 41 public static final String MAPCSS_STYLE_MIME_TYPES = "text/mapcss, text/css; q=0.9, text/plain; q=0.8, application/zip, application/octet-stream; q=0.5"; 42 36 43 public final List<MapCSSRule> rules; 37 44 private Color backgroundColorOverride; … … 97 104 return new ByteArrayInputStream(css.getBytes(Utils.UTF_8)); 98 105 } 99 MirroredInputStream in = new MirroredInputStream(url );106 MirroredInputStream in = new MirroredInputStream(url, null, MAPCSS_STYLE_MIME_TYPES); 100 107 if (isZip) { 101 108 File file = in.getFile(); -
trunk/src/org/openstreetmap/josm/gui/mappaint/xml/XmlStyleSource.java
r6643 r6867 35 35 public class XmlStyleSource extends StyleSource implements StyleKeys { 36 36 37 /** 38 * The accepted MIME types sent in the HTTP Accept header. 39 * @since 6867 40 */ 41 public static final String XML_STYLE_MIME_TYPES = "application/xml, text/xml, text/plain; q=0.8, application/zip, application/octet-stream; q=0.5"; 42 37 43 protected final Map<String, IconPrototype> icons = new HashMap<String, IconPrototype>(); 38 44 protected final Map<String, LinePrototype> lines = new HashMap<String, LinePrototype>(); … … 98 104 @Override 99 105 public InputStream getSourceInputStream() throws IOException { 100 MirroredInputStream in = new MirroredInputStream(url );106 MirroredInputStream in = new MirroredInputStream(url, null, XML_STYLE_MIME_TYPES); 101 107 InputStream zip = in.findZipEntryInputStream("xml", "style"); 102 108 if (zip != null) { -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetReader.java
r6856 r6867 35 35 public final class TaggingPresetReader { 36 36 37 /** 38 * The accepted MIME types sent in the HTTP Accept header. 39 * @since 6867 40 */ 41 public static final String PRESET_MIME_TYPES = "application/xml, text/xml, text/plain; q=0.8, application/zip, application/octet-stream; q=0.5"; 42 37 43 private TaggingPresetReader() { 38 44 // Hide default constructor for utils classes … … 219 225 public static Collection<TaggingPreset> readAll(String source, boolean validate) throws SAXException, IOException { 220 226 Collection<TaggingPreset> tp; 221 MirroredInputStream s = new MirroredInputStream(source );227 MirroredInputStream s = new MirroredInputStream(source, null, PRESET_MIME_TYPES); 222 228 try { 223 229 InputStream zip = s.findZipEntryInputStream("xml","preset"); -
trunk/src/org/openstreetmap/josm/io/MirroredInputStream.java
r6642 r6867 36 36 public final static long DEFAULT_MAXTIME = -1L; 37 37 38 /** 39 * Constructs an input stream from a given filename, URL or internal resource. 40 * 41 * @param name can be:<ul> 42 * <li>relative or absolute file name</li> 43 * <li>{@code file:///SOME/FILE} the same as above</li> 44 * <li>{@code resource://SOME/FILE} file from the classpath (usually in the current *.jar)</li> 45 * <li>{@code http://...} a URL. It will be cached on disk.</li></ul> 46 * @throws IOException when the resource with the given name could not be retrieved 47 */ 38 48 public MirroredInputStream(String name) throws IOException { 39 this(name, null, DEFAULT_MAXTIME); 40 } 41 49 this(name, null, DEFAULT_MAXTIME, null); 50 } 51 52 /** 53 * Constructs an input stream from a given filename, URL or internal resource. 54 * 55 * @param name can be:<ul> 56 * <li>relative or absolute file name</li> 57 * <li>{@code file:///SOME/FILE} the same as above</li> 58 * <li>{@code resource://SOME/FILE} file from the classpath (usually in the current *.jar)</li> 59 * <li>{@code http://...} a URL. It will be cached on disk.</li></ul> 60 * @param maxTime the maximum age of the cache file (in seconds) 61 * @throws IOException when the resource with the given name could not be retrieved 62 */ 42 63 public MirroredInputStream(String name, long maxTime) throws IOException { 43 this(name, null, maxTime); 44 } 45 64 this(name, null, maxTime, null); 65 } 66 67 /** 68 * Constructs an input stream from a given filename, URL or internal resource. 69 * 70 * @param name can be:<ul> 71 * <li>relative or absolute file name</li> 72 * <li>{@code file:///SOME/FILE} the same as above</li> 73 * <li>{@code resource://SOME/FILE} file from the classpath (usually in the current *.jar)</li> 74 * <li>{@code http://...} a URL. It will be cached on disk.</li></ul> 75 * @param destDir the destination directory for the cache file. Only applies for URLs. 76 * @throws IOException when the resource with the given name could not be retrieved 77 */ 46 78 public MirroredInputStream(String name, String destDir) throws IOException { 47 this(name, destDir, DEFAULT_MAXTIME); 48 } 49 50 /** 51 * Get an inputstream from a given filename, url or internal resource. 52 * @param name can be 53 * - relative or absolute file name 54 * - file:///SOME/FILE the same as above 55 * - resource://SOME/FILE file from the classpath (usually in the current *.jar) 56 * - http://... a url. It will be cached on disk. 57 * @param destDir the destination directory for the cache file. only applies for urls. 79 this(name, destDir, DEFAULT_MAXTIME, null); 80 } 81 82 /** 83 * Constructs an input stream from a given filename, URL or internal resource. 84 * 85 * @param name can be:<ul> 86 * <li>relative or absolute file name</li> 87 * <li>{@code file:///SOME/FILE} the same as above</li> 88 * <li>{@code resource://SOME/FILE} file from the classpath (usually in the current *.jar)</li> 89 * <li>{@code http://...} a URL. It will be cached on disk.</li></ul> 90 * @param destDir the destination directory for the cache file. Only applies for URLs. 58 91 * @param maxTime the maximum age of the cache file (in seconds) 59 92 * @throws IOException when the resource with the given name could not be retrieved 60 93 */ 61 94 public MirroredInputStream(String name, String destDir, long maxTime) throws IOException { 95 this(name, destDir, maxTime, null); 96 } 97 98 /** 99 * Constructs an input stream from a given filename, URL or internal resource. 100 * 101 * @param name can be:<ul> 102 * <li>relative or absolute file name</li> 103 * <li>{@code file:///SOME/FILE} the same as above</li> 104 * <li>{@code resource://SOME/FILE} file from the classpath (usually in the current *.jar)</li> 105 * <li>{@code http://...} a URL. It will be cached on disk.</li></ul> 106 * @param destDir the destination directory for the cache file. Only applies for URLs. 107 * @param httpAccept The accepted MIME types sent in the HTTP Accept header. Only applies for URLs. 108 * @throws IOException when the resource with the given name could not be retrieved 109 * @since 6867 110 */ 111 public MirroredInputStream(String name, String destDir, String httpAccept) throws IOException { 112 this(name, destDir, DEFAULT_MAXTIME, httpAccept); 113 } 114 115 /** 116 * Constructs an input stream from a given filename, URL or internal resource. 117 * 118 * @param name can be:<ul> 119 * <li>relative or absolute file name</li> 120 * <li>{@code file:///SOME/FILE} the same as above</li> 121 * <li>{@code resource://SOME/FILE} file from the classpath (usually in the current *.jar)</li> 122 * <li>{@code http://...} a URL. It will be cached on disk.</li></ul> 123 * @param destDir the destination directory for the cache file. Only applies for URLs. 124 * @param maxTime the maximum age of the cache file (in seconds) 125 * @param httpAccept The accepted MIME types sent in the HTTP Accept header. Only applies for URLs. 126 * @throws IOException when the resource with the given name could not be retrieved 127 * @since 6867 128 */ 129 public MirroredInputStream(String name, String destDir, long maxTime, String httpAccept) throws IOException { 62 130 URL url; 63 131 try { … … 73 141 file = new File(url.getFile()); 74 142 } else { 75 file = checkLocal(url, destDir, maxTime );143 file = checkLocal(url, destDir, maxTime, httpAccept); 76 144 } 77 145 } … … 201 269 } 202 270 203 private File checkLocal(URL url, String destDir, long maxTime ) throws IOException {271 private File checkLocal(URL url, String destDir, long maxTime, String httpAccept) throws IOException { 204 272 String prefKey = getPrefKey(url, destDir); 205 273 long age = 0L; … … 237 305 BufferedInputStream bis = null; 238 306 try { 239 HttpURLConnection con = connectFollowingRedirect(url );307 HttpURLConnection con = connectFollowingRedirect(url, httpAccept); 240 308 bis = new BufferedInputStream(con.getInputStream()); 241 309 FileOutputStream fos = new FileOutputStream(destDirFile); … … 284 352 * 285 353 * @param downloadUrl The resource URL to download 354 * @param httpAccept The accepted MIME types sent in the HTTP Accept header. Can be {@code null} 286 355 * @return The HTTP connection effectively linked to the resource, after all potential redirections 287 356 * @throws MalformedURLException If a redirected URL is wrong 288 357 * @throws IOException If any I/O operation goes wrong 289 * @since 6 073290 */ 291 public static HttpURLConnection connectFollowingRedirect(URL downloadUrl ) throws MalformedURLException, IOException {358 * @since 6867 359 */ 360 public static HttpURLConnection connectFollowingRedirect(URL downloadUrl, String httpAccept) throws MalformedURLException, IOException { 292 361 HttpURLConnection con = null; 293 362 int numRedirects = 0; … … 297 366 con.setConnectTimeout(Main.pref.getInteger("socket.timeout.connect",15)*1000); 298 367 con.setReadTimeout(Main.pref.getInteger("socket.timeout.read",30)*1000); 368 Main.debug("GET "+downloadUrl); 369 if (httpAccept != null) { 370 Main.debug("Accept: "+httpAccept); 371 con.setRequestProperty("Accept", httpAccept); 372 } 299 373 try { 300 374 con.connect(); -
trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java
r6643 r6867 36 36 */ 37 37 public class PluginDownloadTask extends PleaseWaitRunnable{ 38 39 /** 40 * The accepted MIME types sent in the HTTP Accept header. 41 * @since 6867 42 */ 43 public static final String PLUGIN_MIME_TYPES = "application/java-archive, application/zip; q=0.9, application/octet-stream; q=0.5"; 44 38 45 private final Collection<PluginInformation> toUpdate = new LinkedList<PluginInformation>(); 39 46 private final Collection<PluginInformation> failed = new LinkedList<PluginInformation>(); … … 120 127 URL url = new URL(pi.downloadlink); 121 128 synchronized(this) { 122 downloadConnection = MirroredInputStream.connectFollowingRedirect(url );129 downloadConnection = MirroredInputStream.connectFollowingRedirect(url, PLUGIN_MIME_TYPES); 123 130 } 124 131 in = downloadConnection.getInputStream();
Note:
See TracChangeset
for help on using the changeset viewer.