[15424] | 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 |
|
---|
[15427] | 6 | import java.io.IOException;
|
---|
[15784] | 7 | import java.io.InputStream;
|
---|
[15424] | 8 |
|
---|
| 9 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
| 10 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
[15784] | 11 | import org.xml.sax.SAXException;
|
---|
[15424] | 12 |
|
---|
| 13 | /**
|
---|
| 14 | * GeoJson server reader.
|
---|
| 15 | * @author Omar Vega Ramos <ovruni@riseup.net>
|
---|
| 16 | * @since 15424
|
---|
| 17 | */
|
---|
[15784] | 18 | public class GeoJSONServerReader extends OsmServerLocationReader {
|
---|
[15424] | 19 |
|
---|
| 20 | /**
|
---|
| 21 | * Constructs a new {@code GeoJSONServerReader}.
|
---|
| 22 | * @param url geojson URL
|
---|
| 23 | */
|
---|
| 24 | public GeoJSONServerReader(String url) {
|
---|
[15784] | 25 | super(url);
|
---|
[15424] | 26 | }
|
---|
| 27 |
|
---|
[15784] | 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 |
|
---|
[15424] | 45 | @Override
|
---|
| 46 | public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException {
|
---|
[15784] | 47 | return parseOsm(progressMonitor, Compression.NONE);
|
---|
[15424] | 48 | }
|
---|
[15784] | 49 |
|
---|
| 50 | @Override
|
---|
| 51 | public DataSet parseOsm(ProgressMonitor progressMonitor, Compression compression) throws OsmTransferException {
|
---|
| 52 | return doParse(new GeoJsonParser(progressMonitor, compression), progressMonitor);
|
---|
| 53 | }
|
---|
[15424] | 54 | }
|
---|