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
RevLine 
[1071]1//License: GPL. For details, see LICENSE file.
[653]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;
[1670]11import org.openstreetmap.josm.data.osm.OsmPrimitiveType;
[653]12import org.xml.sax.SAXException;
13
14public class OsmServerObjectReader extends OsmServerReader {
[1071]15
[1146]16 long id;
[1670]17 OsmPrimitiveType type;
[1146]18 boolean full;
[1169]19
[1670]20 public OsmServerObjectReader(long id, OsmPrimitiveType type, boolean full) {
[1146]21 this.id = id;
22 this.type = type;
23 this.full = full;
24 }
[1071]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 */
[1670]31 @Override
32 public DataSet parseOsm() throws OsmTransferException {
[1071]33 try {
34 Main.pleaseWaitDlg.progress.setValue(0);
35 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));
36 StringBuffer sb = new StringBuffer();
[1670]37 sb.append(type.getAPIName());
[1071]38 sb.append("/");
39 sb.append(id);
[1670]40 if (full && ! type.equals(OsmPrimitiveType.NODE)) {
[1071]41 sb.append("/full");
[1670]42 }
[1071]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..."));
[1772]48 final OsmReader osm = OsmReader.parseDataSetOsm(in,Main.pleaseWaitDlg);
[1444]49 final DataSet data = osm.getDs();
50
[1071]51 in.close();
52 activeConnection = null;
53 return data;
54 } catch (IOException e) {
55 if (cancel)
56 return null;
[1670]57 throw new OsmTransferException(e);
[1071]58 } catch (SAXException e) {
[1670]59 throw new OsmTransferException(e);
60 } catch(OsmTransferException e) {
[1071]61 throw e;
62 } catch (Exception e) {
63 if (cancel)
64 return null;
[1670]65 throw new OsmTransferException(e);
[653]66 }
[1071]67 }
[653]68
69}
Note: See TracBrowser for help on using the repository browser.