Changeset 31934 in osm
- Timestamp:
- 2016-01-04T15:02:38+01:00 (9 years ago)
- Location:
- applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/DirectDownload.java
r30102 r31934 11 11 import org.openstreetmap.josm.Main; 12 12 import org.openstreetmap.josm.actions.JosmAction; 13 import org.openstreetmap.josm.data.gpx.GpxData; 13 14 import org.openstreetmap.josm.gui.MainMenu; 14 15 import org.openstreetmap.josm.gui.layer.GpxLayer; … … 27 28 * Will be invoked by JOSM to bootstrap the plugin 28 29 * 29 * @param info information about the plugin and its local installation 30 * @param info information about the plugin and its local installation 30 31 */ 31 32 public DirectDownload(PluginInformation info) { … … 48 49 UserTrack track = go.getSelectedUserTrack(); 49 50 50 if ((go.getValue() == 1) && (track != null)) { 51 String urlString = OsmApi.getOsmApi().getBaseUrl() + "gpx/" + track.id + "/data"; 51 if (!((go.getValue() == 1) && (track != null))) { 52 return; 53 } 52 54 53 try { 54 URL trackDataUrl = new URL(urlString); 55 InputStream is = Utils.openURLAndDecompress(trackDataUrl, true); 55 final GpxData data = new GpxServerReader().loadGpx(Long.parseLong(track.id)); 56 if (data == null) { 57 return; 58 } 59 final GpxLayer gpxLayer = new GpxLayer(data); 56 60 57 GpxReader r = new GpxReader(is);58 boolean parsedProperly = r.parse(true);59 GpxLayer gpxLayer = new GpxLayer(r.getGpxData(), track.filename, true);61 if (data.hasRoutePoints() || data.hasTrackPoints()) { 62 Main.main.addLayer(gpxLayer); 63 } 60 64 61 if (r.getGpxData().hasRoutePoints() || r.getGpxData().hasTrackPoints()) { 62 Main.main.addLayer(gpxLayer); 63 } 64 65 if (Main.pref.getBoolean("marker.makeautomarkers", true) && !r.getGpxData().waypoints.isEmpty()) { 66 MarkerLayer ml = new MarkerLayer(r.getGpxData(), tr("Markers from {0}", track.filename), null, gpxLayer); 67 if (ml.data.size() > 0) { 68 Main.main.addLayer(ml); 69 } 70 } 71 if (!parsedProperly) { 72 JOptionPane.showMessageDialog(Main.parent, 73 tr("Error occurred while parsing gpx file {0}. Only a part of the file will be available.", urlString)); 74 } 75 76 } catch (java.net.MalformedURLException e) { 77 JOptionPane.showMessageDialog(Main.parent, 78 tr("Invalid URL {0}", urlString)); 79 } catch (java.io.IOException e) { 80 e.printStackTrace(); 81 JOptionPane.showMessageDialog(Main.parent, 82 tr("Error fetching URL {0}", urlString)); 83 } catch (SAXException e) { 84 e.printStackTrace(); 85 JOptionPane.showMessageDialog(Main.parent, 86 tr("Error parsing data from URL {0}", urlString)); 65 if (Main.pref.getBoolean("marker.makeautomarkers", true) && !data.waypoints.isEmpty()) { 66 MarkerLayer ml = new MarkerLayer(data, tr("Markers from {0}", track.filename), null, gpxLayer); 67 if (ml.data.size() > 0) { 68 Main.main.addLayer(ml); 87 69 } 88 70 } -
applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/DownloadDataGui.java
r30737 r31934 64 64 panel.add(scrollPane, BorderLayout.CENTER); 65 65 66 model.setData( getTrackList());66 model.setData(new UserTrackReader().getTrackList()); 67 67 68 68 setContent(panel); 69 69 setupDialog(); 70 }71 72 private static class TrackListHandler extends DefaultHandler {73 private LinkedList<UserTrack> data = new LinkedList<>();74 75 private String cdata = new String();76 77 @Override78 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {79 if (qName.equals("gpx_file")) {80 UserTrack track = new UserTrack();81 82 track.id = atts.getValue("id");83 track.filename = atts.getValue("name");84 track.datetime = atts.getValue("timestamp").replaceAll("[TZ]", " "); // TODO: do real parsing and time zone conversion85 86 data.addFirst(track);87 }88 cdata = new String();89 }90 91 @Override92 public void characters(char ch[], int start, int length)93 throws SAXException {94 cdata += new String(ch, start, length);95 }96 97 @Override98 public void endElement(String uri, String localName, String qName) throws SAXException {99 if (qName.equals("description")) {100 data.getFirst().description = cdata;101 }102 /*103 else if (qName.equals("tag")) {104 data.getFirst().tags = cdata;105 cdata = new String();106 }107 */108 }109 110 public List<UserTrack> getResult() {111 return data;112 }113 }114 115 private List<UserTrack> getTrackList() {116 String urlString = OsmApi.getOsmApi().getBaseUrl() + "user/gpx_files";117 118 try {119 URL userTracksUrl = new URL(urlString);120 121 SAXParserFactory spf = SAXParserFactory.newInstance();122 TrackListHandler handler = new TrackListHandler();123 124 //get a new instance of parser125 SAXParser sp = spf.newSAXParser();126 127 //parse the file and also register this class for call backs128 sp.parse(userTracksUrl.openStream(), handler);129 130 return handler.getResult();131 } catch (java.net.MalformedURLException e) {132 Main.error(e);133 JOptionPane.showMessageDialog(null, tr("Invalid URL {0}", urlString));134 } catch (java.io.IOException e) {135 Main.error(e);136 JOptionPane.showMessageDialog(null, tr("Error fetching URL {0}", urlString));137 } catch (SAXException e) {138 Main.error(e);139 JOptionPane.showMessageDialog(null, tr("Error parsing data from URL {0}", urlString));140 } catch (ParserConfigurationException e) {141 Main.error(e);142 JOptionPane.showMessageDialog(null, tr("Error parsing data from URL {0}", urlString));143 }144 145 return new LinkedList<>();146 70 } 147 71
Note:
See TracChangeset
for help on using the changeset viewer.