source: osm/applications/editors/josm/plugins/sds/src/org/openstreetmap/hot/sds/ReadPostprocessor.java@ 29684

Last change on this file since 29684 was 29684, checked in by donvip, 12 years ago

[josm_sds] fix #josm8799 - update to JOSM 6010

File size: 3.0 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.hot.sds;
3
4import java.io.ByteArrayInputStream;
5import java.io.IOException;
6import java.io.InputStream;
7import java.io.UnsupportedEncodingException;
8import java.util.ArrayList;
9
10import javax.xml.parsers.ParserConfigurationException;
11import javax.xml.parsers.SAXParserFactory;
12
13import org.openstreetmap.josm.data.osm.Changeset;
14import org.openstreetmap.josm.data.osm.DataSet;
15import org.openstreetmap.josm.data.osm.Node;
16import org.openstreetmap.josm.data.osm.OsmPrimitive;
17import org.openstreetmap.josm.data.osm.Relation;
18import org.openstreetmap.josm.data.osm.Way;
19import org.openstreetmap.josm.data.osm.visitor.Visitor;
20import org.openstreetmap.josm.gui.progress.ProgressMonitor;
21import org.openstreetmap.josm.io.OsmServerReadPostprocessor;
22import org.xml.sax.InputSource;
23import org.xml.sax.SAXException;
24
25public class ReadPostprocessor implements OsmServerReadPostprocessor {
26
27 private ArrayList<Long> nodeList;
28 private ArrayList<Long> wayList;
29 private ArrayList<Long> relationList;
30
31 private SeparateDataStorePlugin plugin;
32
33 public ReadPostprocessor(SeparateDataStorePlugin plugin) {
34 this.plugin = plugin;
35 }
36
37 @Override
38 public void postprocessDataSet(DataSet ds, ProgressMonitor progress) {
39
40 nodeList = new ArrayList<Long>();
41 wayList = new ArrayList<Long>();
42 relationList = new ArrayList<Long>();
43
44 Visitor adder = new Visitor() {
45 @Override
46 public void visit(Node n) {
47 nodeList.add(n.getId());
48 plugin.originalNodes.put(n.getId(), n.save());
49 }
50 @Override
51 public void visit(Way w) {
52 wayList.add(w.getId());
53 plugin.originalWays.put(w.getId(), w.save());
54 }
55 @Override
56 public void visit(Relation e) {
57 relationList.add(e.getId());
58 plugin.originalNodes.put(e.getId(), e.save());
59 }
60 @Override
61 public void visit(Changeset cs) {}
62 };
63
64 for (OsmPrimitive p : ds.allPrimitives()) {
65 p.accept(adder);
66 }
67
68 SdsApi api = SdsApi.getSdsApi();
69 String rv = "";
70 try {
71 rv = api.requestShadowsFromSds(nodeList, wayList, relationList, progress);
72 } catch (SdsTransferException e) {
73 // TODO Auto-generated catch block
74 e.printStackTrace();
75 }
76
77 // this is slightly inefficient, as we're re-making the string into
78 // an input stream when there was an input stream to be had inside the
79 // SdsApi already, but this encapsulates things better.
80 InputStream xmlStream;
81 try {
82 xmlStream = new ByteArrayInputStream(rv.getBytes("UTF-8"));
83 InputSource inputSource = new InputSource(xmlStream);
84 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new SdsParser(ds, plugin));
85 } catch (UnsupportedEncodingException e1) {
86 // TODO Auto-generated catch block
87 e1.printStackTrace();
88 } catch (SAXException e) {
89 // TODO Auto-generated catch block
90 e.printStackTrace();
91 } catch (IOException e) {
92 // TODO Auto-generated catch block
93 e.printStackTrace();
94 } catch (ParserConfigurationException e) {
95 // TODO Auto-generated catch block
96 e.printStackTrace();
97 }
98
99 }
100
101}
Note: See TracBrowser for help on using the repository browser.