1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io.imagery;
|
---|
3 |
|
---|
4 | import java.io.BufferedReader;
|
---|
5 | import java.io.Closeable;
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.util.ArrayList;
|
---|
8 | import java.util.Arrays;
|
---|
9 | import java.util.List;
|
---|
10 | import java.util.Map;
|
---|
11 | import java.util.Objects;
|
---|
12 | import java.util.Stack;
|
---|
13 | import java.util.concurrent.ConcurrentHashMap;
|
---|
14 |
|
---|
15 | import javax.xml.parsers.ParserConfigurationException;
|
---|
16 |
|
---|
17 | import org.openstreetmap.josm.data.imagery.DefaultLayer;
|
---|
18 | import org.openstreetmap.josm.data.imagery.ImageryInfo;
|
---|
19 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
|
---|
20 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryCategory;
|
---|
21 | import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
|
---|
22 | import org.openstreetmap.josm.data.imagery.Shape;
|
---|
23 | import org.openstreetmap.josm.io.CachedFile;
|
---|
24 | import org.openstreetmap.josm.tools.HttpClient;
|
---|
25 | import org.openstreetmap.josm.tools.JosmRuntimeException;
|
---|
26 | import org.openstreetmap.josm.tools.LanguageInfo;
|
---|
27 | import org.openstreetmap.josm.tools.Logging;
|
---|
28 | import org.openstreetmap.josm.tools.MultiMap;
|
---|
29 | import org.openstreetmap.josm.tools.Utils;
|
---|
30 | import org.openstreetmap.josm.tools.XmlUtils;
|
---|
31 | import org.xml.sax.Attributes;
|
---|
32 | import org.xml.sax.InputSource;
|
---|
33 | import org.xml.sax.SAXException;
|
---|
34 | import org.xml.sax.helpers.DefaultHandler;
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * Reader to parse the list of available imagery servers from an XML definition file.
|
---|
38 | * <p>
|
---|
39 | * The format is specified in the <a href="https://josm.openstreetmap.de/wiki/Maps">JOSM wiki</a>.
|
---|
40 | */
|
---|
41 | public class ImageryReader implements Closeable {
|
---|
42 |
|
---|
43 | private final String source;
|
---|
44 | private CachedFile cachedFile;
|
---|
45 | private boolean fastFail;
|
---|
46 |
|
---|
47 | private enum State {
|
---|
48 | INIT, // initial state, should always be at the bottom of the stack
|
---|
49 | IMAGERY, // inside the imagery element
|
---|
50 | ENTRY, // inside an entry
|
---|
51 | ENTRY_ATTRIBUTE, // note we are inside an entry attribute to collect the character data
|
---|
52 | PROJECTIONS, // inside projections block of an entry
|
---|
53 | MIRROR, // inside an mirror entry
|
---|
54 | MIRROR_ATTRIBUTE, // note we are inside an mirror attribute to collect the character data
|
---|
55 | MIRROR_PROJECTIONS, // inside projections block of an mirror entry
|
---|
56 | CODE,
|
---|
57 | BOUNDS,
|
---|
58 | SHAPE,
|
---|
59 | NO_TILE,
|
---|
60 | NO_TILESUM,
|
---|
61 | METADATA,
|
---|
62 | DEFAULT_LAYERS,
|
---|
63 | CUSTOM_HTTP_HEADERS,
|
---|
64 | NOOP,
|
---|
65 | UNKNOWN, // element is not recognized in the current context
|
---|
66 | }
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Constructs a {@code ImageryReader} from a given filename, URL or internal resource.
|
---|
70 | *
|
---|
71 | * @param source can be:<ul>
|
---|
72 | * <li>relative or absolute file name</li>
|
---|
73 | * <li>{@code file:///SOME/FILE} the same as above</li>
|
---|
74 | * <li>{@code http://...} a URL. It will be cached on disk.</li>
|
---|
75 | * <li>{@code resource://SOME/FILE} file from the classpath (usually in the current *.jar)</li>
|
---|
76 | * <li>{@code josmdir://SOME/FILE} file inside josm user data directory (since r7058)</li>
|
---|
77 | * <li>{@code josmplugindir://SOME/FILE} file inside josm plugin directory (since r7834)</li></ul>
|
---|
78 | */
|
---|
79 | public ImageryReader(String source) {
|
---|
80 | this.source = source;
|
---|
81 | }
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Parses imagery source.
|
---|
85 | * @return list of imagery info
|
---|
86 | * @throws SAXException if any SAX error occurs
|
---|
87 | * @throws IOException if any I/O error occurs
|
---|
88 | */
|
---|
89 | public List<ImageryInfo> parse() throws SAXException, IOException {
|
---|
90 | Parser parser = new Parser();
|
---|
91 | try {
|
---|
92 | cachedFile = new CachedFile(source);
|
---|
93 | cachedFile.setParam(String.join(",", ImageryInfo.getActiveIds()));
|
---|
94 | cachedFile.setFastFail(fastFail);
|
---|
95 | try (BufferedReader in = cachedFile
|
---|
96 | .setMaxAge(CachedFile.DAYS)
|
---|
97 | .setCachingStrategy(CachedFile.CachingStrategy.IfModifiedSince)
|
---|
98 | .getContentReader()) {
|
---|
99 | InputSource is = new InputSource(in);
|
---|
100 | XmlUtils.parseSafeSAX(is, parser);
|
---|
101 | return parser.entries;
|
---|
102 | }
|
---|
103 | } catch (SAXException e) {
|
---|
104 | throw e;
|
---|
105 | } catch (ParserConfigurationException e) {
|
---|
106 | Logging.error(e); // broken SAXException chaining
|
---|
107 | throw new SAXException(e);
|
---|
108 | }
|
---|
109 | }
|
---|
110 |
|
---|
111 | private static class Parser extends DefaultHandler {
|
---|
112 | private static final String MAX_ZOOM = "max-zoom";
|
---|
113 | private static final String MIN_ZOOM = "min-zoom";
|
---|
114 | private static final String TILE_SIZE = "tile-size";
|
---|
115 | private static final String TRUE = "true";
|
---|
116 |
|
---|
117 | private StringBuilder accumulator = new StringBuilder();
|
---|
118 |
|
---|
119 | private Stack<State> states;
|
---|
120 |
|
---|
121 | private List<ImageryInfo> entries;
|
---|
122 |
|
---|
123 | /**
|
---|
124 | * Skip the current entry because it has mandatory attributes
|
---|
125 | * that this version of JOSM cannot process.
|
---|
126 | */
|
---|
127 | private boolean skipEntry;
|
---|
128 |
|
---|
129 | private ImageryInfo entry;
|
---|
130 | /** In case of mirror parsing this contains the mirror entry */
|
---|
131 | private ImageryInfo mirrorEntry;
|
---|
132 | private ImageryBounds bounds;
|
---|
133 | private Shape shape;
|
---|
134 | // language of last element, does only work for simple ENTRY_ATTRIBUTE's
|
---|
135 | private String lang;
|
---|
136 | private List<String> projections;
|
---|
137 | private MultiMap<String, String> noTileHeaders;
|
---|
138 | private MultiMap<String, String> noTileChecksums;
|
---|
139 | private Map<String, String> metadataHeaders;
|
---|
140 | private List<DefaultLayer> defaultLayers;
|
---|
141 | private Map<String, String> customHttpHeaders;
|
---|
142 |
|
---|
143 | @Override
|
---|
144 | public void startDocument() {
|
---|
145 | accumulator = new StringBuilder();
|
---|
146 | skipEntry = false;
|
---|
147 | states = new Stack<>();
|
---|
148 | states.push(State.INIT);
|
---|
149 | entries = new ArrayList<>();
|
---|
150 | entry = null;
|
---|
151 | bounds = null;
|
---|
152 | projections = null;
|
---|
153 | noTileHeaders = null;
|
---|
154 | noTileChecksums = null;
|
---|
155 | customHttpHeaders = null;
|
---|
156 | }
|
---|
157 |
|
---|
158 | @Override
|
---|
159 | public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
|
---|
160 | accumulator.setLength(0);
|
---|
161 | State newState = null;
|
---|
162 | switch (states.peek()) {
|
---|
163 | case INIT:
|
---|
164 | if ("imagery".equals(qName)) {
|
---|
165 | newState = State.IMAGERY;
|
---|
166 | }
|
---|
167 | break;
|
---|
168 | case IMAGERY:
|
---|
169 | if ("entry".equals(qName)) {
|
---|
170 | entry = new ImageryInfo();
|
---|
171 | skipEntry = false;
|
---|
172 | newState = State.ENTRY;
|
---|
173 | noTileHeaders = new MultiMap<>();
|
---|
174 | noTileChecksums = new MultiMap<>();
|
---|
175 | metadataHeaders = new ConcurrentHashMap<>();
|
---|
176 | defaultLayers = new ArrayList<>();
|
---|
177 | customHttpHeaders = new ConcurrentHashMap<>();
|
---|
178 | String best = atts.getValue("eli-best");
|
---|
179 | if (TRUE.equals(best)) {
|
---|
180 | entry.setBestMarked(true);
|
---|
181 | }
|
---|
182 | String overlay = atts.getValue("overlay");
|
---|
183 | if (TRUE.equals(overlay)) {
|
---|
184 | entry.setOverlay(true);
|
---|
185 | }
|
---|
186 | }
|
---|
187 | break;
|
---|
188 | case MIRROR:
|
---|
189 | if (Arrays.asList(
|
---|
190 | "type",
|
---|
191 | "url",
|
---|
192 | "id",
|
---|
193 | MIN_ZOOM,
|
---|
194 | MAX_ZOOM,
|
---|
195 | TILE_SIZE
|
---|
196 | ).contains(qName)) {
|
---|
197 | newState = State.MIRROR_ATTRIBUTE;
|
---|
198 | lang = atts.getValue("lang");
|
---|
199 | } else if ("projections".equals(qName)) {
|
---|
200 | projections = new ArrayList<>();
|
---|
201 | newState = State.MIRROR_PROJECTIONS;
|
---|
202 | }
|
---|
203 | break;
|
---|
204 | case ENTRY:
|
---|
205 | if (Arrays.asList(
|
---|
206 | "name",
|
---|
207 | "id",
|
---|
208 | "oldid",
|
---|
209 | "type",
|
---|
210 | "description",
|
---|
211 | "default",
|
---|
212 | "url",
|
---|
213 | "eula",
|
---|
214 | MIN_ZOOM,
|
---|
215 | MAX_ZOOM,
|
---|
216 | "attribution-text",
|
---|
217 | "attribution-url",
|
---|
218 | "logo-image",
|
---|
219 | "logo-url",
|
---|
220 | "terms-of-use-text",
|
---|
221 | "terms-of-use-url",
|
---|
222 | "privacy-policy-url",
|
---|
223 | "permission-ref",
|
---|
224 | "country-code",
|
---|
225 | "category",
|
---|
226 | "icon",
|
---|
227 | "date",
|
---|
228 | TILE_SIZE,
|
---|
229 | "valid-georeference",
|
---|
230 | "mod-tile-features",
|
---|
231 | "transparent",
|
---|
232 | "minimum-tile-expire"
|
---|
233 | ).contains(qName)) {
|
---|
234 | newState = State.ENTRY_ATTRIBUTE;
|
---|
235 | lang = atts.getValue("lang");
|
---|
236 | } else if ("bounds".equals(qName)) {
|
---|
237 | try {
|
---|
238 | bounds = new ImageryBounds(
|
---|
239 | atts.getValue("min-lat") + ',' +
|
---|
240 | atts.getValue("min-lon") + ',' +
|
---|
241 | atts.getValue("max-lat") + ',' +
|
---|
242 | atts.getValue("max-lon"), ",");
|
---|
243 | } catch (IllegalArgumentException e) {
|
---|
244 | Logging.trace(e);
|
---|
245 | break;
|
---|
246 | }
|
---|
247 | newState = State.BOUNDS;
|
---|
248 | } else if ("projections".equals(qName)) {
|
---|
249 | projections = new ArrayList<>();
|
---|
250 | newState = State.PROJECTIONS;
|
---|
251 | } else if ("mirror".equals(qName)) {
|
---|
252 | projections = new ArrayList<>();
|
---|
253 | newState = State.MIRROR;
|
---|
254 | mirrorEntry = new ImageryInfo();
|
---|
255 | } else if ("no-tile-header".equals(qName)) {
|
---|
256 | noTileHeaders.put(atts.getValue("name"), atts.getValue("value"));
|
---|
257 | newState = State.NO_TILE;
|
---|
258 | } else if ("no-tile-checksum".equals(qName)) {
|
---|
259 | noTileChecksums.put(atts.getValue("type"), atts.getValue("value"));
|
---|
260 | newState = State.NO_TILESUM;
|
---|
261 | } else if ("metadata-header".equals(qName)) {
|
---|
262 | metadataHeaders.put(atts.getValue("header-name"), atts.getValue("metadata-key"));
|
---|
263 | newState = State.METADATA;
|
---|
264 | } else if ("default-layers".equals(qName)) {
|
---|
265 | newState = State.DEFAULT_LAYERS;
|
---|
266 | } else if ("custom-http-header".equals(qName)) {
|
---|
267 | customHttpHeaders.put(atts.getValue("header-name"), atts.getValue("header-value"));
|
---|
268 | newState = State.CUSTOM_HTTP_HEADERS;
|
---|
269 | }
|
---|
270 | break;
|
---|
271 | case BOUNDS:
|
---|
272 | if ("shape".equals(qName)) {
|
---|
273 | shape = new Shape();
|
---|
274 | newState = State.SHAPE;
|
---|
275 | }
|
---|
276 | break;
|
---|
277 | case SHAPE:
|
---|
278 | if ("point".equals(qName)) {
|
---|
279 | try {
|
---|
280 | shape.addPoint(atts.getValue("lat"), atts.getValue("lon"));
|
---|
281 | } catch (IllegalArgumentException e) {
|
---|
282 | Logging.trace(e);
|
---|
283 | break;
|
---|
284 | }
|
---|
285 | }
|
---|
286 | break;
|
---|
287 | case PROJECTIONS:
|
---|
288 | case MIRROR_PROJECTIONS:
|
---|
289 | if ("code".equals(qName)) {
|
---|
290 | newState = State.CODE;
|
---|
291 | }
|
---|
292 | break;
|
---|
293 | case DEFAULT_LAYERS:
|
---|
294 | if ("layer".equals(qName)) {
|
---|
295 | newState = State.NOOP;
|
---|
296 | defaultLayers.add(new DefaultLayer(
|
---|
297 | entry.getImageryType(),
|
---|
298 | atts.getValue("name"),
|
---|
299 | atts.getValue("style"),
|
---|
300 | atts.getValue("tile-matrix-set")
|
---|
301 | ));
|
---|
302 | }
|
---|
303 | break;
|
---|
304 | default: // Do nothing
|
---|
305 | }
|
---|
306 | /**
|
---|
307 | * Did not recognize the element, so the new state is UNKNOWN.
|
---|
308 | * This includes the case where we are already inside an unknown
|
---|
309 | * element, i.e. we do not try to understand the inner content
|
---|
310 | * of an unknown element, but wait till it's over.
|
---|
311 | */
|
---|
312 | if (newState == null) {
|
---|
313 | newState = State.UNKNOWN;
|
---|
314 | }
|
---|
315 | states.push(newState);
|
---|
316 | if (newState == State.UNKNOWN && TRUE.equals(atts.getValue("mandatory"))) {
|
---|
317 | skipEntry = true;
|
---|
318 | }
|
---|
319 | }
|
---|
320 |
|
---|
321 | @Override
|
---|
322 | public void characters(char[] ch, int start, int length) {
|
---|
323 | accumulator.append(ch, start, length);
|
---|
324 | }
|
---|
325 |
|
---|
326 | @Override
|
---|
327 | public void endElement(String namespaceURI, String qName, String rqName) {
|
---|
328 | switch (states.pop()) {
|
---|
329 | case INIT:
|
---|
330 | throw new JosmRuntimeException("parsing error: more closing than opening elements");
|
---|
331 | case ENTRY:
|
---|
332 | if ("entry".equals(qName)) {
|
---|
333 | entry.setNoTileHeaders(noTileHeaders);
|
---|
334 | noTileHeaders = null;
|
---|
335 | entry.setNoTileChecksums(noTileChecksums);
|
---|
336 | noTileChecksums = null;
|
---|
337 | entry.setMetadataHeaders(metadataHeaders);
|
---|
338 | metadataHeaders = null;
|
---|
339 | entry.setDefaultLayers(defaultLayers);
|
---|
340 | defaultLayers = null;
|
---|
341 | entry.setCustomHttpHeaders(customHttpHeaders);
|
---|
342 | customHttpHeaders = null;
|
---|
343 |
|
---|
344 | if (!skipEntry) {
|
---|
345 | entries.add(entry);
|
---|
346 | }
|
---|
347 | entry = null;
|
---|
348 | }
|
---|
349 | break;
|
---|
350 | case MIRROR:
|
---|
351 | if (mirrorEntry != null && "mirror".equals(qName)) {
|
---|
352 | entry.addMirror(mirrorEntry);
|
---|
353 | mirrorEntry = null;
|
---|
354 | }
|
---|
355 | break;
|
---|
356 | case MIRROR_ATTRIBUTE:
|
---|
357 | if (mirrorEntry != null) {
|
---|
358 | switch(qName) {
|
---|
359 | case "type":
|
---|
360 | boolean found = false;
|
---|
361 | for (ImageryType type : ImageryType.values()) {
|
---|
362 | if (Objects.equals(accumulator.toString(), type.getTypeString())) {
|
---|
363 | mirrorEntry.setImageryType(type);
|
---|
364 | found = true;
|
---|
365 | break;
|
---|
366 | }
|
---|
367 | }
|
---|
368 | if (!found) {
|
---|
369 | mirrorEntry = null;
|
---|
370 | }
|
---|
371 | break;
|
---|
372 | case "id":
|
---|
373 | mirrorEntry.setId(accumulator.toString());
|
---|
374 | break;
|
---|
375 | case "url":
|
---|
376 | mirrorEntry.setUrl(accumulator.toString());
|
---|
377 | break;
|
---|
378 | case MIN_ZOOM:
|
---|
379 | case MAX_ZOOM:
|
---|
380 | Integer val = null;
|
---|
381 | try {
|
---|
382 | val = Integer.valueOf(accumulator.toString());
|
---|
383 | } catch (NumberFormatException e) {
|
---|
384 | val = null;
|
---|
385 | }
|
---|
386 | if (val == null) {
|
---|
387 | mirrorEntry = null;
|
---|
388 | } else {
|
---|
389 | if (MIN_ZOOM.equals(qName)) {
|
---|
390 | mirrorEntry.setDefaultMinZoom(val);
|
---|
391 | } else {
|
---|
392 | mirrorEntry.setDefaultMaxZoom(val);
|
---|
393 | }
|
---|
394 | }
|
---|
395 | break;
|
---|
396 | case TILE_SIZE:
|
---|
397 | Integer tileSize = null;
|
---|
398 | try {
|
---|
399 | tileSize = Integer.valueOf(accumulator.toString());
|
---|
400 | } catch (NumberFormatException e) {
|
---|
401 | tileSize = null;
|
---|
402 | }
|
---|
403 | if (tileSize == null) {
|
---|
404 | mirrorEntry = null;
|
---|
405 | } else {
|
---|
406 | entry.setTileSize(tileSize.intValue());
|
---|
407 | }
|
---|
408 | break;
|
---|
409 | default: // Do nothing
|
---|
410 | }
|
---|
411 | }
|
---|
412 | break;
|
---|
413 | case ENTRY_ATTRIBUTE:
|
---|
414 | switch(qName) {
|
---|
415 | case "name":
|
---|
416 | entry.setName(lang == null ? LanguageInfo.getJOSMLocaleCode(null) : lang, accumulator.toString());
|
---|
417 | break;
|
---|
418 | case "description":
|
---|
419 | entry.setDescription(lang, accumulator.toString());
|
---|
420 | break;
|
---|
421 | case "date":
|
---|
422 | entry.setDate(accumulator.toString());
|
---|
423 | break;
|
---|
424 | case "id":
|
---|
425 | entry.setId(accumulator.toString());
|
---|
426 | break;
|
---|
427 | case "oldid":
|
---|
428 | entry.addOldId(accumulator.toString());
|
---|
429 | break;
|
---|
430 | case "type":
|
---|
431 | ImageryType type = ImageryType.fromString(accumulator.toString());
|
---|
432 | if (type != null)
|
---|
433 | entry.setImageryType(type);
|
---|
434 | else
|
---|
435 | skipEntry = true;
|
---|
436 | break;
|
---|
437 | case "default":
|
---|
438 | switch (accumulator.toString()) {
|
---|
439 | case TRUE:
|
---|
440 | entry.setDefaultEntry(true);
|
---|
441 | break;
|
---|
442 | case "false":
|
---|
443 | entry.setDefaultEntry(false);
|
---|
444 | break;
|
---|
445 | default:
|
---|
446 | skipEntry = true;
|
---|
447 | }
|
---|
448 | break;
|
---|
449 | case "url":
|
---|
450 | entry.setUrl(accumulator.toString());
|
---|
451 | break;
|
---|
452 | case "eula":
|
---|
453 | entry.setEulaAcceptanceRequired(accumulator.toString());
|
---|
454 | break;
|
---|
455 | case MIN_ZOOM:
|
---|
456 | case MAX_ZOOM:
|
---|
457 | Integer val = null;
|
---|
458 | try {
|
---|
459 | val = Integer.valueOf(accumulator.toString());
|
---|
460 | } catch (NumberFormatException e) {
|
---|
461 | val = null;
|
---|
462 | }
|
---|
463 | if (val == null) {
|
---|
464 | skipEntry = true;
|
---|
465 | } else {
|
---|
466 | if (MIN_ZOOM.equals(qName)) {
|
---|
467 | entry.setDefaultMinZoom(val);
|
---|
468 | } else {
|
---|
469 | entry.setDefaultMaxZoom(val);
|
---|
470 | }
|
---|
471 | }
|
---|
472 | break;
|
---|
473 | case "attribution-text":
|
---|
474 | entry.setAttributionText(accumulator.toString());
|
---|
475 | break;
|
---|
476 | case "attribution-url":
|
---|
477 | entry.setAttributionLinkURL(accumulator.toString());
|
---|
478 | break;
|
---|
479 | case "logo-image":
|
---|
480 | entry.setAttributionImage(accumulator.toString());
|
---|
481 | break;
|
---|
482 | case "logo-url":
|
---|
483 | entry.setAttributionImageURL(accumulator.toString());
|
---|
484 | break;
|
---|
485 | case "terms-of-use-text":
|
---|
486 | entry.setTermsOfUseText(accumulator.toString());
|
---|
487 | break;
|
---|
488 | case "privacy-policy-url":
|
---|
489 | entry.setPrivacyPolicyURL(accumulator.toString());
|
---|
490 | break;
|
---|
491 | case "permission-ref":
|
---|
492 | entry.setPermissionReferenceURL(accumulator.toString());
|
---|
493 | break;
|
---|
494 | case "terms-of-use-url":
|
---|
495 | entry.setTermsOfUseURL(accumulator.toString());
|
---|
496 | break;
|
---|
497 | case "country-code":
|
---|
498 | entry.setCountryCode(accumulator.toString());
|
---|
499 | break;
|
---|
500 | case "icon":
|
---|
501 | entry.setIcon(accumulator.toString());
|
---|
502 | break;
|
---|
503 | case TILE_SIZE:
|
---|
504 | Integer tileSize = null;
|
---|
505 | try {
|
---|
506 | tileSize = Integer.valueOf(accumulator.toString());
|
---|
507 | } catch (NumberFormatException e) {
|
---|
508 | tileSize = null;
|
---|
509 | }
|
---|
510 | if (tileSize == null) {
|
---|
511 | skipEntry = true;
|
---|
512 | } else {
|
---|
513 | entry.setTileSize(tileSize.intValue());
|
---|
514 | }
|
---|
515 | break;
|
---|
516 | case "valid-georeference":
|
---|
517 | entry.setGeoreferenceValid(Boolean.parseBoolean(accumulator.toString()));
|
---|
518 | break;
|
---|
519 | case "mod-tile-features":
|
---|
520 | entry.setModTileFeatures(Boolean.parseBoolean(accumulator.toString()));
|
---|
521 | break;
|
---|
522 | case "transparent":
|
---|
523 | entry.setTransparent(Boolean.parseBoolean(accumulator.toString()));
|
---|
524 | break;
|
---|
525 | case "minimum-tile-expire":
|
---|
526 | entry.setMinimumTileExpire(Integer.parseInt(accumulator.toString()));
|
---|
527 | break;
|
---|
528 | case "category":
|
---|
529 | String cat = accumulator.toString();
|
---|
530 | ImageryCategory category = ImageryCategory.fromString(cat);
|
---|
531 | if (category != null)
|
---|
532 | entry.setImageryCategory(category);
|
---|
533 | entry.setImageryCategoryOriginalString(cat);
|
---|
534 | break;
|
---|
535 | default: // Do nothing
|
---|
536 | }
|
---|
537 | break;
|
---|
538 | case BOUNDS:
|
---|
539 | entry.setBounds(bounds);
|
---|
540 | bounds = null;
|
---|
541 | break;
|
---|
542 | case SHAPE:
|
---|
543 | bounds.addShape(shape);
|
---|
544 | shape = null;
|
---|
545 | break;
|
---|
546 | case CODE:
|
---|
547 | projections.add(accumulator.toString());
|
---|
548 | break;
|
---|
549 | case PROJECTIONS:
|
---|
550 | entry.setServerProjections(projections);
|
---|
551 | projections = null;
|
---|
552 | break;
|
---|
553 | case MIRROR_PROJECTIONS:
|
---|
554 | mirrorEntry.setServerProjections(projections);
|
---|
555 | projections = null;
|
---|
556 | break;
|
---|
557 | case NO_TILE:
|
---|
558 | case NO_TILESUM:
|
---|
559 | case METADATA:
|
---|
560 | case UNKNOWN:
|
---|
561 | default:
|
---|
562 | // nothing to do for these or the unknown type
|
---|
563 | }
|
---|
564 | }
|
---|
565 | }
|
---|
566 |
|
---|
567 | /**
|
---|
568 | * Sets whether opening HTTP connections should fail fast, i.e., whether a
|
---|
569 | * {@link HttpClient#setConnectTimeout(int) low connect timeout} should be used.
|
---|
570 | * @param fastFail whether opening HTTP connections should fail fast
|
---|
571 | * @see CachedFile#setFastFail(boolean)
|
---|
572 | */
|
---|
573 | public void setFastFail(boolean fastFail) {
|
---|
574 | this.fastFail = fastFail;
|
---|
575 | }
|
---|
576 |
|
---|
577 | @Override
|
---|
578 | public void close() throws IOException {
|
---|
579 | Utils.close(cachedFile);
|
---|
580 | }
|
---|
581 | }
|
---|