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.Main;
|
---|
10 | import org.openstreetmap.josm.data.osm.DataSet;
|
---|
11 | import org.xml.sax.SAXException;
|
---|
12 |
|
---|
13 | import javax.swing.JOptionPane;
|
---|
14 |
|
---|
15 | public class OsmServerObjectReader extends OsmServerReader {
|
---|
16 |
|
---|
17 | public final static String TYPE_WAY = "way";
|
---|
18 | public final static String TYPE_REL = "relation";
|
---|
19 | public final static String TYPE_NODE = "node";
|
---|
20 |
|
---|
21 | long id;
|
---|
22 | String type;
|
---|
23 | boolean full;
|
---|
24 |
|
---|
25 | public OsmServerObjectReader(long id, String type, boolean full) {
|
---|
26 | this.id = id;
|
---|
27 | this.type = type;
|
---|
28 | this.full = full;
|
---|
29 | }
|
---|
30 | /**
|
---|
31 | * Method to download single objects from OSM server. ways, relations, nodes
|
---|
32 | * @return the data requested
|
---|
33 | * @throws SAXException
|
---|
34 | * @throws IOException
|
---|
35 | */
|
---|
36 | public DataSet parseOsm() throws SAXException, IOException {
|
---|
37 | try {
|
---|
38 | Main.pleaseWaitDlg.progress.setValue(0);
|
---|
39 | Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));
|
---|
40 | StringBuffer sb = new StringBuffer();
|
---|
41 | sb.append(type);
|
---|
42 | sb.append("/");
|
---|
43 | sb.append(id);
|
---|
44 | if (full)
|
---|
45 | sb.append("/full");
|
---|
46 |
|
---|
47 | final InputStream in = getInputStream(sb.toString(), Main.pleaseWaitDlg);
|
---|
48 | if (in == null)
|
---|
49 | return null;
|
---|
50 | Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data..."));
|
---|
51 | final OsmReader osm = OsmReader.parseDataSetOsm(in, null, Main.pleaseWaitDlg);
|
---|
52 | final DataSet data = osm.getDs();
|
---|
53 |
|
---|
54 | // String origin = Main.pref.get("osm-server.url")+"/"+Main.pref.get("osm-server.version", "0.5");
|
---|
55 | // Bounds bounds = new Bounds(new LatLon(lat1, lon1), new LatLon(lat2, lon2));
|
---|
56 | // DataSource src = new DataSource(bounds, origin);
|
---|
57 | // data.dataSources.add(src);
|
---|
58 | if (osm.getParseNotes().length() != 0) {
|
---|
59 | JOptionPane.showMessageDialog(Main.parent, osm.getParseNotes());
|
---|
60 | }
|
---|
61 | in.close();
|
---|
62 | activeConnection = null;
|
---|
63 | return data;
|
---|
64 | } catch (IOException e) {
|
---|
65 | if (cancel)
|
---|
66 | return null;
|
---|
67 | throw e;
|
---|
68 | } catch (SAXException e) {
|
---|
69 | throw e;
|
---|
70 | } catch (Exception e) {
|
---|
71 | if (cancel)
|
---|
72 | return null;
|
---|
73 | if (e instanceof RuntimeException)
|
---|
74 | throw (RuntimeException)e;
|
---|
75 | throw new RuntimeException(e);
|
---|
76 | }
|
---|
77 | }
|
---|
78 |
|
---|
79 | }
|
---|