Changeset 35944 in osm for applications/editors
- Timestamp:
- 2022-03-23T00:11:16+01:00 (3 years ago)
- Location:
- applications/editors/josm/plugins/DirectDownload
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/DirectDownload/build.xml
r35552 r35944 13 13 <property name="plugin.description" value="Download your GPX tracks from openstreetmap.org"/> 14 14 <property name="plugin.icon" value="images/DownloadAction.svg"/> 15 <property name="plugin.canloadatruntime" value="true"/> 15 16 <!-- <property name="plugin.link" value="..."/>--> 16 17 <!--<property name="plugin.early" value="..."/>--> -
applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/DirectDownload.java
r35221 r35944 5 5 6 6 import java.awt.event.ActionEvent; 7 import java.awt.event.KeyEvent; 7 8 import java.util.ArrayList; 8 9 import java.util.HashMap; 10 import java.util.List; 9 11 10 12 import org.openstreetmap.josm.actions.JosmAction; … … 20 22 import org.openstreetmap.josm.plugins.PluginInformation; 21 23 import org.openstreetmap.josm.spi.preferences.Config; 24 import org.openstreetmap.josm.tools.Shortcut; 22 25 23 26 public class DirectDownload extends Plugin { 24 25 private DownloadAction openaction;26 27 27 /** 28 28 * Will be invoked by JOSM to bootstrap the plugin … … 33 33 super(info); 34 34 35 openaction = new DownloadAction(); 36 MainMenu.add(MainApplication.getMenu().gpsMenu, openaction); 35 MainMenu.add(MainApplication.getMenu().gpsMenu, new DownloadAction()); 37 36 } 38 37 39 38 static class DownloadAction extends JosmAction { 40 39 DownloadAction() { 41 super(tr("Download Track ..."), "DownloadAction", 42 tr("Download GPX track from openstreetmap.org"), null, false); 40 super(tr("Download Track ..."), "DownloadAction", tr("Download GPX track from openstreetmap.org"), 41 Shortcut.registerShortcut("directdownload:downloadgpxaction", tr("DirectDownload: Download GPX Track"), 42 KeyEvent.CHAR_UNDEFINED, Shortcut.NONE), false); 43 43 } 44 44 … … 48 48 go.setVisible(true); 49 49 50 ArrayList<UserTrack> tracks = go.getSelectedUserTracks();50 List<UserTrack> tracks = go.getSelectedUserTracks(); 51 51 52 52 if (!((go.getValue() == 1) && (tracks != null))) { … … 84 84 if (Config.getPref().getBoolean("marker.makeautomarkers", true) && !data.waypoints.isEmpty()) { 85 85 MarkerLayer ml = new MarkerLayer(data, tr("Markers from {0}", track.filename), null, gpxLayer); 86 if ( ml.data.size() > 0) {86 if (!ml.data.isEmpty()) { 87 87 MainApplication.getLayerManager().addLayer(ml); 88 88 } -
applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/DownloadDataGui.java
r34483 r35944 105 105 } 106 106 107 public ArrayList<UserTrack> getSelectedUserTracks() {108 ArrayList<UserTrack> DataArray = model.getDataArrayList();107 public List<UserTrack> getSelectedUserTracks() { 108 List<UserTrack> dataArray = model.getDataArrayList(); 109 109 int[] selected = tblSearchResults.getSelectedRows(); 110 ArrayList<UserTrack> selectedTracks = new ArrayList<>(selected.length); 111 for (int i = 0; i < selected.length; i++) { 112 selectedTracks.add(DataArray.get(selected[i])); 113 } 110 List<UserTrack> selectedTracks = new ArrayList<>(selected.length); 111 112 for (int i : selected) { 113 selectedTracks.add(dataArray.get(i)); 114 } 115 114 116 return selectedTracks; 115 117 } … … 121 123 static class NamedResultTableColumnModel extends DefaultTableColumnModel { 122 124 protected void createColumns() { 123 TableColumn col = null;125 TableColumn col; 124 126 NamedResultCellRenderer renderer = new NamedResultCellRenderer(); 125 127 … … 207 209 208 210 case 3: 209 setText( sr.tags);211 setText(String.join(";", sr.tags)); 210 212 break; 211 213 -
applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/GpxServerReader.java
r34483 r35944 23 23 24 24 public GpxData loadGpx(final long id) { 25 final String urlString = OsmApi.getOsmApi().getBaseUrl() + "gpx/" + id + "/data"; 25 return fetchUrl(OsmApi.getOsmApi().getBaseUrl() + "gpx/" + id + "/data"); 26 } 26 27 28 private GpxData fetchUrl(final String urlString) { 29 HttpClient client = null; 27 30 try { 28 final HttpClient client = HttpClient.create(new URL(urlString)); 29 addAuth(client); 31 client = HttpClient.create(new URL(urlString)); 32 // At some point OSM started hosting the files on Amazon S3. S3 does not like multiple authentication methods. 33 // See JOSM #21935. 34 if (!urlString.contains("X-Amz-Algorithm") && !urlString.contains("Signature")) { 35 addAuth(client); 36 } 30 37 31 38 try (InputStream in = client.connect().uncompressAccordingToContentDisposition(true).getContent()) { … … 34 41 if (!parsedProperly) { 35 42 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), 36 tr("Error occurred while parsing gpx file {0}. Only a part of the file will be available.", urlString)); 43 tr("Error occurred while parsing gpx file {0}. Only a part of the file will be available.", 44 urlString)); 37 45 } 38 46 return r.getGpxData(); 39 47 } 40 48 } catch (IOException | OsmTransferException e) { 49 if (client != null && client.getResponse() != null 50 && !client.getResponse().getURL().toExternalForm().equals(urlString) /* Check if we were redirected */ 51 && client.getRequestHeader("Authorization") != null) { 52 // OK. We may have hit JOSM #21935. 53 return fetchUrl(client.getResponse().getURL().toExternalForm()); 54 } 41 55 Logging.warn(e); 42 56 JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Error fetching URL {0}", urlString)); -
applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/UserTrack.java
r34381 r35944 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.directdownload; 3 4 import java.util.ArrayList; 5 import java.util.List; 3 6 4 7 class UserTrack { … … 6 9 public String filename; 7 10 public String description; 8 public String tags;11 public final List<String> tags = new ArrayList<>(); 9 12 public String datetime; 10 13 } -
applications/editors/josm/plugins/DirectDownload/src/org/openstreetmap/josm/plugins/directdownload/UserTrackReader.java
r34481 r35944 66 66 67 67 @Override 68 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException{68 public void startElement(String namespaceURI, String localName, String qName, Attributes atts) { 69 69 if (qName.equals("gpx_file")) { 70 70 UserTrack track = new UserTrack(); … … 80 80 81 81 @Override 82 public void characters(char[] ch, int start, int length) 83 throws SAXException { 82 public void characters(char[] ch, int start, int length) { 84 83 cdata += new String(ch, start, length); 85 84 } 86 85 87 86 @Override 88 public void endElement(String uri, String localName, String qName) throws SAXException{87 public void endElement(String uri, String localName, String qName) { 89 88 if (qName.equals("description")) { 90 89 data.getFirst().description = cdata; 91 90 } else if (qName.equals("tag")) { 92 data.getFirst().tags = cdata;93 cdata = new String();91 data.getFirst().tags.add(cdata); 92 cdata = ""; 94 93 } 95 94
Note:
See TracChangeset
for help on using the changeset viewer.