source: josm/src/org/openstreetmap/josm/io/ObjectListDownloader.java@ 153

Last change on this file since 153 was 153, checked in by imi, 18 years ago
  • added possibility to create new download tasks (download data types).
  • removed WMS stuff (now available as landsat - plugin)
  • updated translation files
File size: 2.2 KB
Line 
1package org.openstreetmap.josm.io;
2
3import static org.openstreetmap.josm.tools.I18n.tr;
4
5import java.io.IOException;
6import java.io.InputStream;
7import java.util.Collection;
8
9import org.openstreetmap.josm.Main;
10import org.openstreetmap.josm.data.osm.DataSet;
11import org.openstreetmap.josm.data.osm.OsmPrimitive;
12import org.openstreetmap.josm.data.osm.visitor.MergeVisitor;
13import org.openstreetmap.josm.data.osm.visitor.NameVisitor;
14import org.xml.sax.SAXException;
15
16public class ObjectListDownloader extends OsmServerReader {
17
18 /**
19 * All the objects to download (if not downloading bounding boxes instead)
20 */
21 private final Collection<OsmPrimitive> toDownload;
22 private final DataSet ds = new DataSet();
23 private final MergeVisitor merger = new MergeVisitor(ds);
24
25 public ObjectListDownloader(Collection<OsmPrimitive> toDownload) {
26 this.toDownload = toDownload;
27 }
28
29 public DataSet parse() throws SAXException, IOException {
30 Main.pleaseWaitDlg.progress.setMaximum(toDownload.size());
31 Main.pleaseWaitDlg.progress.setValue(0);
32 try {
33 final NameVisitor namer = new NameVisitor();
34 for (OsmPrimitive osm : toDownload) {
35 osm.visit(namer);
36 download(tr(namer.className), osm.id);
37 if (cancel)
38 break;
39 }
40 if (!merger.conflicts.isEmpty())
41 throw new RuntimeException(tr("Conflicts in disjunct objects"));
42 return ds;
43 } catch (IOException e) {
44 if (cancel)
45 return null;
46 throw e;
47 } catch (SAXException e) {
48 throw e;
49 } catch (Exception e) {
50 if (cancel)
51 return null;
52 if (e instanceof RuntimeException)
53 throw (RuntimeException)e;
54 throw new RuntimeException(e);
55 }
56 }
57
58 private void download(String className, long id) throws IOException, SAXException {
59 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading {0} {1}", className, id));
60 InputStream in = getInputStream(className+"/"+id);
61 if (in == null)
62 return;
63 DataSet data = OsmReader.parseDataSet(in, null, null);
64 Main.pleaseWaitDlg.progress.setValue(Main.pleaseWaitDlg.progress.getValue()+1);
65 if (data.allPrimitives().size() > 1)
66 throw new SAXException(tr("Got more than one object when expecting only one."));
67 for (OsmPrimitive osm : data.allPrimitives())
68 osm.visit(merger);
69 }
70}
Note: See TracBrowser for help on using the repository browser.