source: josm/trunk/src/org/openstreetmap/josm/data/imagery/CachedAttributionBingAerialTileSource.java@ 8637

Last change on this file since 8637 was 8624, checked in by bastiK, 9 years ago

add missing svn:eol-style=native

  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.data.imagery;
3
4import java.io.IOException;
5import java.io.StringReader;
6import java.net.URL;
7import java.util.List;
8import java.util.Scanner;
9import java.util.concurrent.Callable;
10
11import org.openstreetmap.gui.jmapviewer.tilesources.BingAerialTileSource;
12import org.openstreetmap.josm.Main;
13import org.openstreetmap.josm.io.CacheCustomContent;
14import org.openstreetmap.josm.io.UTFInputStreamReader;
15import org.openstreetmap.josm.tools.Utils;
16import org.xml.sax.InputSource;
17
18/**
19 * Bing TileSource with cached attribution
20 *
21 * @author Wiktor Niesiobędzki
22 * @since 8526
23 */
24public class CachedAttributionBingAerialTileSource extends BingAerialTileSource {
25 /**
26 * Creates tile source
27 * @param info ImageryInfo description of this tile source
28 */
29 public CachedAttributionBingAerialTileSource(ImageryInfo info) {
30 super(info);
31 }
32
33 class BingAttributionData extends CacheCustomContent<IOException> {
34
35 public BingAttributionData() {
36 super("bing.attribution.xml", CacheCustomContent.INTERVAL_HOURLY);
37 }
38
39 @Override
40 protected byte[] updateData() throws IOException {
41 URL u = getAttributionUrl();
42 try (Scanner scanner = new Scanner(UTFInputStreamReader.create(Utils.openURL(u)))) {
43 String r = scanner.useDelimiter("\\A").next();
44 Main.info("Successfully loaded Bing attribution data.");
45 return r.getBytes("UTF-8");
46 }
47 }
48 }
49
50 @Override
51 protected Callable<List<Attribution>> getAttributionLoaderCallable() {
52 return new Callable<List<Attribution>>() {
53
54 @Override
55 public List<Attribution> call() throws Exception {
56 BingAttributionData attributionLoader = new BingAttributionData();
57 int waitTimeSec = 1;
58 while (true) {
59 try {
60 String xml = attributionLoader.updateIfRequiredString();
61 return parseAttributionText(new InputSource(new StringReader((xml))));
62 } catch (IOException ex) {
63 Main.warn("Could not connect to Bing API. Will retry in " + waitTimeSec + " seconds.");
64 Thread.sleep(waitTimeSec * 1000L);
65 waitTimeSec *= 2;
66 }
67 }
68 }
69 };
70 }
71}
Note: See TracBrowser for help on using the repository browser.