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.openstreetmap.josm.data.osm.OsmPrimitiveType;
|
---|
12 | import org.xml.sax.SAXException;
|
---|
13 |
|
---|
14 | public class OsmServerObjectReader extends OsmServerReader {
|
---|
15 |
|
---|
16 | long id;
|
---|
17 | OsmPrimitiveType type;
|
---|
18 | boolean full;
|
---|
19 |
|
---|
20 | public OsmServerObjectReader(long id, OsmPrimitiveType type, boolean full) {
|
---|
21 | this.id = id;
|
---|
22 | this.type = type;
|
---|
23 | this.full = full;
|
---|
24 | }
|
---|
25 | /**
|
---|
26 | * Method to download single objects from OSM server. ways, relations, nodes
|
---|
27 | * @return the data requested
|
---|
28 | * @throws SAXException
|
---|
29 | * @throws IOException
|
---|
30 | */
|
---|
31 | @Override
|
---|
32 | public DataSet parseOsm() throws OsmTransferException {
|
---|
33 | try {
|
---|
34 | Main.pleaseWaitDlg.progress.setValue(0);
|
---|
35 | Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));
|
---|
36 | StringBuffer sb = new StringBuffer();
|
---|
37 | sb.append(type.getAPIName());
|
---|
38 | sb.append("/");
|
---|
39 | sb.append(id);
|
---|
40 | if (full && ! type.equals(OsmPrimitiveType.NODE)) {
|
---|
41 | sb.append("/full");
|
---|
42 | }
|
---|
43 |
|
---|
44 | final InputStream in = getInputStream(sb.toString(), Main.pleaseWaitDlg);
|
---|
45 | if (in == null)
|
---|
46 | return null;
|
---|
47 | Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data..."));
|
---|
48 | final OsmReader osm = OsmReader.parseDataSetOsm(in,Main.pleaseWaitDlg);
|
---|
49 | final DataSet data = osm.getDs();
|
---|
50 |
|
---|
51 | in.close();
|
---|
52 | activeConnection = null;
|
---|
53 | return data;
|
---|
54 | } catch (IOException e) {
|
---|
55 | if (cancel)
|
---|
56 | return null;
|
---|
57 | throw new OsmTransferException(e);
|
---|
58 | } catch (SAXException e) {
|
---|
59 | throw new OsmTransferException(e);
|
---|
60 | } catch(OsmTransferException e) {
|
---|
61 | throw e;
|
---|
62 | } catch (Exception e) {
|
---|
63 | if (cancel)
|
---|
64 | return null;
|
---|
65 | throw new OsmTransferException(e);
|
---|
66 | }
|
---|
67 | }
|
---|
68 |
|
---|
69 | }
|
---|