| 1 | // License: GPL. For details, see LICENSE file.
|
|---|
| 2 | package org.openstreetmap.josm.io.imagery;
|
|---|
| 3 |
|
|---|
| 4 | import java.awt.image.BufferedImage;
|
|---|
| 5 | import java.io.IOException;
|
|---|
| 6 | import java.net.URL;
|
|---|
| 7 | import java.text.MessageFormat;
|
|---|
| 8 | import java.util.ArrayList;
|
|---|
| 9 | import java.util.StringTokenizer;
|
|---|
| 10 |
|
|---|
| 11 | import javax.imageio.ImageIO;
|
|---|
| 12 |
|
|---|
| 13 | import org.openstreetmap.josm.data.preferences.StringProperty;
|
|---|
| 14 | import org.openstreetmap.josm.gui.MapView;
|
|---|
| 15 | import org.openstreetmap.josm.gui.layer.WMSLayer;
|
|---|
| 16 |
|
|---|
| 17 | public 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 | }
|
|---|