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.InputStream;
|
---|
7 |
|
---|
8 | import org.openstreetmap.josm.data.gpx.GpxData;
|
---|
9 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
10 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
11 |
|
---|
12 | public class OsmServerLocationReader extends OsmServerReader {
|
---|
13 |
|
---|
14 | String url;
|
---|
15 |
|
---|
16 | public OsmServerLocationReader(String url) {
|
---|
17 | this.url = url;
|
---|
18 | }
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * Method to download OSM files from somewhere
|
---|
22 | */
|
---|
23 | @Override
|
---|
24 | public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException {
|
---|
25 | InputStream in = null;
|
---|
26 | progressMonitor.beginTask(tr("Contacting Server...", 10));
|
---|
27 | try {
|
---|
28 | in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false));
|
---|
29 | if (in == null)
|
---|
30 | return null;
|
---|
31 | progressMonitor.subTask(tr("Downloading OSM data..."));
|
---|
32 | return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false));
|
---|
33 | } catch(OsmTransferException e) {
|
---|
34 | throw e;
|
---|
35 | } catch (Exception e) {
|
---|
36 | if (cancel)
|
---|
37 | return null;
|
---|
38 | throw new OsmTransferException(e);
|
---|
39 | } finally {
|
---|
40 | progressMonitor.finishTask();
|
---|
41 | try {
|
---|
42 | activeConnection = null;
|
---|
43 | if (in != null) {
|
---|
44 | in.close();
|
---|
45 | }
|
---|
46 | } catch(Exception e) {/* ignore it */}
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | /* (non-Javadoc)
|
---|
51 | * @see org.openstreetmap.josm.io.OsmServerReader#parseOsmChange(org.openstreetmap.josm.gui.progress.ProgressMonitor)
|
---|
52 | */
|
---|
53 | @Override
|
---|
54 | public DataSet parseOsmChange(ProgressMonitor progressMonitor)
|
---|
55 | throws OsmTransferException {
|
---|
56 | InputStream in = null;
|
---|
57 | progressMonitor.beginTask(tr("Contacting Server...", 10));
|
---|
58 | try {
|
---|
59 | in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false));
|
---|
60 | if (in == null)
|
---|
61 | return null;
|
---|
62 | progressMonitor.subTask(tr("Downloading OSM data..."));
|
---|
63 | return OsmChangeReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false));
|
---|
64 | } catch(OsmTransferException e) {
|
---|
65 | throw e;
|
---|
66 | } catch (Exception e) {
|
---|
67 | if (cancel)
|
---|
68 | return null;
|
---|
69 | throw new OsmTransferException(e);
|
---|
70 | } finally {
|
---|
71 | progressMonitor.finishTask();
|
---|
72 | try {
|
---|
73 | activeConnection = null;
|
---|
74 | if (in != null) {
|
---|
75 | in.close();
|
---|
76 | }
|
---|
77 | } catch(Exception e) {/* ignore it */}
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | @Override
|
---|
82 | public GpxData parseRawGps(ProgressMonitor progressMonitor) throws OsmTransferException {
|
---|
83 | InputStream in = null;
|
---|
84 | progressMonitor.beginTask(tr("Contacting Server...", 10));
|
---|
85 | try {
|
---|
86 | in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(1, true));
|
---|
87 | if (in == null)
|
---|
88 | return null;
|
---|
89 | progressMonitor.subTask(tr("Downloading OSM data..."));
|
---|
90 | GpxReader reader = new GpxReader(in);
|
---|
91 | reader.parse(false);
|
---|
92 | GpxData result = reader.data;
|
---|
93 | result.fromServer = true;
|
---|
94 | return result;
|
---|
95 | } catch(OsmTransferException e) {
|
---|
96 | throw e;
|
---|
97 | } catch (Exception e) {
|
---|
98 | if (cancel)
|
---|
99 | return null;
|
---|
100 | throw new OsmTransferException(e);
|
---|
101 | } finally {
|
---|
102 | progressMonitor.finishTask();
|
---|
103 | try {
|
---|
104 | activeConnection = null;
|
---|
105 | if (in != null) {
|
---|
106 | in.close();
|
---|
107 | }
|
---|
108 | } catch(Exception e) {/* ignore it */}
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|