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

Last change on this file since 3715 was 3715, checked in by Upliner, 13 years ago

Added imagery plugin to josm core. Imagery plugin is union of wmsplugin and slippymap plugins. It includes code by Tim Waters, Petr Dlouhý, Frederik Ramm and others. Also enables the remotecontol which was integrated in [3707].

File size: 1.6 KB
Line 
1package org.openstreetmap.josm.io.imagery;
2
3import java.awt.image.BufferedImage;
4import java.io.IOException;
5import java.net.URL;
6import java.text.MessageFormat;
7import java.util.ArrayList;
8import java.util.StringTokenizer;
9
10import javax.imageio.ImageIO;
11
12import org.openstreetmap.josm.data.preferences.StringProperty;
13import org.openstreetmap.josm.gui.MapView;
14import org.openstreetmap.josm.gui.layer.WMSLayer;
15import org.openstreetmap.josm.io.CacheFiles;
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, CacheFiles cache) {
21 super(mv, layer, cache);
22 }
23
24 @Override
25 protected BufferedImage grab(URL url) throws IOException {
26 String urlstring = url.toExternalForm();
27
28 System.out.println("Grabbing HTML " + 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.