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