1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.io.InputStream;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
10 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
11 | import org.xml.sax.SAXException;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * GeoJson server reader.
|
---|
15 | * @author Omar Vega Ramos <ovruni@riseup.net>
|
---|
16 | * @since 15424
|
---|
17 | */
|
---|
18 | public class GeoJSONServerReader extends OsmServerLocationReader {
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Constructs a new {@code GeoJSONServerReader}.
|
---|
22 | * @param url geojson URL
|
---|
23 | */
|
---|
24 | public GeoJSONServerReader(String url) {
|
---|
25 | super(url);
|
---|
26 | }
|
---|
27 |
|
---|
28 | protected class GeoJsonParser extends Parser<DataSet> {
|
---|
29 | protected GeoJsonParser(ProgressMonitor progressMonitor, Compression compression) {
|
---|
30 | super(progressMonitor, compression);
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public DataSet parse() throws OsmTransferException, IllegalDataException, IOException, SAXException {
|
---|
35 | in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false));
|
---|
36 | if (in == null)
|
---|
37 | return null;
|
---|
38 | progressMonitor.subTask(tr("Downloading OSM data..."));
|
---|
39 | InputStream uncompressedInputStream = compression.getUncompressedInputStream(in); // NOPMD
|
---|
40 | ProgressMonitor subTaskMonitor = progressMonitor.createSubTaskMonitor(1, false);
|
---|
41 | return GeoJSONReader.parseDataSet(uncompressedInputStream, subTaskMonitor);
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException {
|
---|
47 | return parseOsm(progressMonitor, Compression.NONE);
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public DataSet parseOsm(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException {
|
---|
52 | return doParse(new GeoJsonParser(progressMonitor, compression), progressMonitor);
|
---|
53 | }
|
---|
54 | }
|
---|