source: josm/trunk/src/org/openstreetmap/josm/io/imagery/HTMLGrabber.java@ 3747

Last change on this file since 3747 was 3747, checked in by jttt, 13 years ago

Make sure wms layer will not try to download the same area twice

  • Property svn:eol-style set to native
File size: 1.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.imagery;
3
4import java.awt.image.BufferedImage;
5import java.io.IOException;
6import java.net.URL;
7import java.text.MessageFormat;
8import java.util.ArrayList;
9import java.util.StringTokenizer;
10
11import javax.imageio.ImageIO;
12
13import org.openstreetmap.josm.data.preferences.StringProperty;
14import org.openstreetmap.josm.gui.MapView;
15import org.openstreetmap.josm.gui.layer.WMSLayer;
16
17public class HTMLGrabber extends WMSGrabber {
18 public static final StringProperty PROP_BROWSER = new StringProperty("imagery.wms.browser", "webkit-image {0}");
19
20 public HTMLGrabber(MapView mv, WMSLayer layer) {
21 super(mv, layer);
22 }
23
24 @Override
25 protected BufferedImage grab(URL url, int attempt) throws IOException {
26 String urlstring = url.toExternalForm();
27
28 System.out.println("Grabbing HTML " + (attempt > 1? "(attempt " + attempt + ") ":"") + url);
29
30 ArrayList<String> cmdParams = new ArrayList<String>();
31 StringTokenizer st = new StringTokenizer(MessageFormat.format(PROP_BROWSER.get(), urlstring));
32 while( st.hasMoreTokens() ) {
33 cmdParams.add(st.nextToken());
34 }
35
36 ProcessBuilder builder = new ProcessBuilder( cmdParams);
37
38 Process browser;
39 try {
40 browser = builder.start();
41 } catch(IOException ioe) {
42 throw new IOException( "Could not start browser. Please check that the executable path is correct.\n" + ioe.getMessage() );
43 }
44
45 BufferedImage img = ImageIO.read(browser.getInputStream());
46 cache.saveImg(urlstring, img);
47 return img;
48 }
49}
Note: See TracBrowser for help on using the repository browser.