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

Last change on this file since 1790 was 1790, checked in by Gubaer, 15 years ago

Relation Editor: complete rework
Relation Editor: had to temporarily remove code for "link information" and "sorting"
IO Subsystem: clean up in exception handling
some cosmetics

File size: 2.1 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.openstreetmap.josm.data.osm.OsmPrimitiveType;
12import org.xml.sax.SAXException;
13
14public 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}
Note: See TracBrowser for help on using the repository browser.