source: josm/trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java@ 1530

Last change on this file since 1530 was 1523, checked in by framm, 15 years ago
  • Major redesign of how JOSM talks to the OSM server. Connections now all go through a new OsmApi class that finds out which version the server uses. JOSM should now be able to handle 0.5 and 0.6 without configuration change. Config options osm-server.version and osm-server.additional-versions now obsolete. Handling of error and cancel situations might still need some improvement.
File size: 2.5 KB
Line 
1//License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.IOException;
7import java.io.InputStream;
8
9import org.openstreetmap.josm.Main;
10import org.openstreetmap.josm.data.osm.DataSet;
11import org.xml.sax.SAXException;
12
13import javax.swing.JOptionPane;
14
15public 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// Bounds bounds = new Bounds(new LatLon(lat1, lon1), new LatLon(lat2, lon2));
55// DataSource src = new DataSource(bounds, origin);
56// data.dataSources.add(src);
57 if (osm.getParseNotes().length() != 0) {
58 JOptionPane.showMessageDialog(Main.parent, osm.getParseNotes());
59 }
60 in.close();
61 activeConnection = null;
62 return data;
63 } catch (IOException e) {
64 if (cancel)
65 return null;
66 throw e;
67 } catch (SAXException e) {
68 throw e;
69 } catch (Exception e) {
70 if (cancel)
71 return null;
72 if (e instanceof RuntimeException)
73 throw (RuntimeException)e;
74 throw new RuntimeException(e);
75 }
76 }
77
78}
Note: See TracBrowser for help on using the repository browser.