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

Last change on this file since 6248 was 6248, checked in by Don-vip, 11 years ago

Rework console output:

  • new log level "error"
  • Replace nearly all calls to system.out and system.err to Main.(error|warn|info|debug)
  • Remove some unnecessary debug output
  • Some messages are modified (removal of "Info", "Warning", "Error" from the message itself -> notable i18n impact but limited to console error messages not seen by the majority of users, so that's ok)
  • Property svn:eol-style set to native
File size: 2.2 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.ByteArrayInputStream;
6import java.io.ByteArrayOutputStream;
7import java.io.IOException;
8import java.net.URL;
9import java.text.MessageFormat;
10import java.util.ArrayList;
11import java.util.StringTokenizer;
12
13import javax.imageio.ImageIO;
14
15import org.openstreetmap.josm.Main;
16import org.openstreetmap.josm.data.preferences.StringProperty;
17import org.openstreetmap.josm.gui.MapView;
18import org.openstreetmap.josm.gui.layer.WMSLayer;
19import org.openstreetmap.josm.tools.Utils;
20
21public class HTMLGrabber extends WMSGrabber {
22 public static final StringProperty PROP_BROWSER = new StringProperty("imagery.wms.browser", "webkit-image {0}");
23
24 public HTMLGrabber(MapView mv, WMSLayer layer, boolean localOnly) {
25 super(mv, layer, localOnly);
26 }
27
28 @Override
29 protected BufferedImage grab(WMSRequest request, URL url, int attempt) throws IOException {
30 String urlstring = url.toExternalForm();
31
32 Main.info("Grabbing HTML " + (attempt > 1? "(attempt " + attempt + ") ":"") + url);
33
34 ArrayList<String> cmdParams = new ArrayList<String>();
35 StringTokenizer st = new StringTokenizer(MessageFormat.format(PROP_BROWSER.get(), urlstring));
36 while (st.hasMoreTokens()) {
37 cmdParams.add(st.nextToken());
38 }
39
40 ProcessBuilder builder = new ProcessBuilder( cmdParams);
41
42 Process browser;
43 try {
44 browser = builder.start();
45 } catch (IOException ioe) {
46 throw new IOException( "Could not start browser. Please check that the executable path is correct.\n" + ioe.getMessage() );
47 }
48
49 ByteArrayOutputStream baos = new ByteArrayOutputStream();
50 Utils.copyStream(browser.getInputStream(), baos);
51 ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
52 BufferedImage img = layer.normalizeImage(ImageIO.read(bais));
53 bais.reset();
54 layer.cache.saveToCache(layer.isOverlapEnabled()?img:null, bais, Main.getProjection(), request.getPixelPerDegree(), b.minEast, b.minNorth);
55
56 return img;
57 }
58}
Note: See TracBrowser for help on using the repository browser.