Changeset 6244 in josm
- Timestamp:
- 2013-09-21T13:19:50+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r6069 r6244 27 27 import org.openstreetmap.josm.io.OsmServerReader; 28 28 import org.openstreetmap.josm.io.OsmTransferException; 29 import org.openstreetmap.josm.tools.CheckParameterUtil; 29 30 import org.xml.sax.SAXException; 30 31 … … 36 37 private DownloadTask downloadTask; 37 38 38 private static final String PATTERN_TRACE_ID = "http://.* openstreetmap.org/trace/\\p{Digit}+/data";39 private static final String PATTERN_TRACE_ID = "http://.*(osm|openstreetmap).org/trace/\\p{Digit}+/data"; 39 40 40 41 private static final String PATTERN_TRACKPOINTS_BBOX = "http://.*/api/0.6/trackpoints\\?bbox=.*,.*,.*,.*"; … … 58 59 public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) { 59 60 downloadTask = new DownloadTask(newLayer, 60 new BoundingBoxDownloader(downloadArea), progressMonitor );61 new BoundingBoxDownloader(downloadArea), progressMonitor, false); 61 62 // We need submit instead of execute so we can wait for it to finish and get the error 62 63 // message if necessary. If no one calls getErrorMessage() it just behaves like execute. … … 66 67 @Override 67 68 public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) { 68 if (url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT) || url.matches(PATTERN_EXTERNAL_GPX_FILE))) { 69 CheckParameterUtil.ensureParameterNotNull(url, "url"); 70 if (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_EXTERNAL_GPX_SCRIPT) || url.matches(PATTERN_EXTERNAL_GPX_FILE)) { 69 71 downloadTask = new DownloadTask(newLayer, 70 new OsmServerLocationReader(url), progressMonitor );72 new OsmServerLocationReader(url), progressMonitor, url.matches(PATTERN_TRACE_ID)); 71 73 // Extract .gpx filename from URL to set the new layer name 72 74 Matcher matcher = Pattern.compile(PATTERN_EXTERNAL_GPX_FILE).matcher(url); … … 76 78 return Main.worker.submit(downloadTask); 77 79 78 } else if (url != null && url.matches(PATTERN_TRACKPOINTS_BBOX)) {80 } else if (url.matches(PATTERN_TRACKPOINTS_BBOX)) { 79 81 String[] table = url.split("\\?|=|&"); 80 82 for (int i = 0; i<table.length; i++) { … … 97 99 private GpxData rawData; 98 100 private final boolean newLayer; 99 100 public DownloadTask(boolean newLayer, OsmServerReader reader, ProgressMonitor progressMonitor) { 101 private final boolean compressed; 102 103 public DownloadTask(boolean newLayer, OsmServerReader reader, ProgressMonitor progressMonitor, boolean compressed) { 101 104 super(tr("Downloading GPS data")); 102 105 this.reader = reader; 103 106 this.newLayer = newLayer; 107 this.compressed = compressed; 104 108 } 105 109 … … 108 112 if (isCanceled()) 109 113 return; 110 rawData = reader.parseRawGps(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 114 ProgressMonitor subMonitor = progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false); 115 if (compressed) { 116 rawData = reader.parseRawGpsBzip2(subMonitor); 117 } else { 118 rawData = reader.parseRawGps(subMonitor); 119 } 111 120 } catch(Exception e) { 112 121 if (isCanceled()) -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmUrlTask.java
r6032 r6244 22 22 @Override 23 23 public String[] getPatterns() { 24 return new String[]{"http://www\\.openstreetmap\\.org/\\?lat=.*&lon=.*"}; 24 return new String[]{ 25 "http://www\\.(osm|openstreetmap)\\.org/\\?lat=.*&lon=.*", 26 "http://www\\.(osm|openstreetmap)\\.org/#map=\\p{Digit}+/.*/.*"}; 25 27 } 26 28 -
trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
r6203 r6244 14 14 import org.xml.sax.SAXException; 15 15 16 /** 17 * Read content from OSM server for a given bounding box 18 * @since 627 19 */ 16 20 public class BoundingBoxDownloader extends OsmServerReader { 17 21 … … 25 29 protected final boolean crosses180th; 26 30 31 /** 32 * Constructs a new {@code BoundingBoxDownloader}. 33 * @param downloadArea The area to download 34 */ 27 35 public BoundingBoxDownloader(Bounds downloadArea) { 28 36 this.lat1 = downloadArea.getMinLat(); … … 60 68 } 61 69 62 /**63 * Retrieve raw gps waypoints from the server API.64 * @return A list of all primitives retrieved. Currently, the list of lists65 * contain only one list, since the server cannot distinguish between66 * ways.67 */68 70 @Override 69 71 public GpxData parseRawGps(ProgressMonitor progressMonitor) throws OsmTransferException { … … 106 108 } 107 109 108 /**109 * Read the data from the osm server address.110 * @return A data set containing all data retrieved from that url111 */112 110 @Override 113 111 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { -
trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
r6070 r6244 6 6 import java.io.IOException; 7 7 import java.io.InputStream; 8 import java.util.zip.GZIPInputStream;9 8 10 import org.apache.tools.bzip2.CBZip2InputStream;11 9 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 12 10 import org.openstreetmap.josm.data.gpx.GpxData; … … 16 14 import org.xml.sax.SAXException; 17 15 16 /** 17 * Read content from OSM server for a given URL 18 * @since 1146 19 */ 18 20 public class OsmServerLocationReader extends OsmServerReader { 19 21 20 22 protected final String url; 21 23 24 /** 25 * Constructs a new {@code OsmServerLocationReader}. 26 * @param url The URL to fetch 27 */ 22 28 public OsmServerLocationReader(String url) { 23 29 this.url = url; … … 25 31 26 32 protected abstract class Parser<T> { 27 public InputStream in = null; 33 protected final ProgressMonitor progressMonitor; 34 protected final Compression compression; 35 protected InputStream in = null; 36 37 public Parser(ProgressMonitor progressMonitor, Compression compression) { 38 this.progressMonitor = progressMonitor; 39 this.compression = compression; 40 } 41 42 protected final InputStream getUncompressedInputStream() throws IOException { 43 switch (compression) { 44 case BZIP2: return FileImporter.getBZip2InputStream(in); 45 case GZIP: return FileImporter.getGZipInputStream(in); 46 case NONE: 47 default: return in; 48 } 49 } 50 28 51 public abstract T parse() throws OsmTransferException, IllegalDataException, IOException, SAXException; 29 52 } … … 47 70 } 48 71 49 /**50 * Method to download OSM files from somewhere51 */52 72 @Override 53 73 public DataSet parseOsm(final ProgressMonitor progressMonitor) throws OsmTransferException { 54 return doParse(new Parser<DataSet>() { 55 @Override 56 public DataSet parse() throws OsmTransferException, IllegalDataException { 57 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 58 if (in == null) 59 return null; 60 progressMonitor.subTask(tr("Downloading OSM data...")); 61 return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false)); 62 } 63 }, progressMonitor); 74 return doParse(new OsmParser(progressMonitor, Compression.NONE), progressMonitor); 64 75 } 65 76 66 /**67 * Method to download BZip2-compressed OSM files from somewhere68 */69 77 @Override 70 78 public DataSet parseOsmBzip2(final ProgressMonitor progressMonitor) throws OsmTransferException { 71 return doParse(new Parser<DataSet>() { 72 @Override 73 public DataSet parse() throws OsmTransferException, IllegalDataException, IOException { 74 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 75 if (in == null) 76 return null; 77 CBZip2InputStream bzin = FileImporter.getBZip2InputStream(in); 78 progressMonitor.subTask(tr("Downloading OSM data...")); 79 return OsmReader.parseDataSet(bzin, progressMonitor.createSubTaskMonitor(1, false)); 80 } 81 }, progressMonitor); 79 return doParse(new OsmParser(progressMonitor, Compression.BZIP2), progressMonitor); 82 80 } 83 81 84 /**85 * Method to download GZip-compressed OSM files from somewhere86 */87 82 @Override 88 83 public DataSet parseOsmGzip(final ProgressMonitor progressMonitor) throws OsmTransferException { 89 return doParse(new Parser<DataSet>() { 90 @Override 91 public DataSet parse() throws OsmTransferException, IllegalDataException, IOException { 92 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 93 if (in == null) 94 return null; 95 GZIPInputStream gzin = FileImporter.getGZipInputStream(in); 96 progressMonitor.subTask(tr("Downloading OSM data...")); 97 return OsmReader.parseDataSet(gzin, progressMonitor.createSubTaskMonitor(1, false)); 98 } 99 }, progressMonitor); 84 return doParse(new OsmParser(progressMonitor, Compression.GZIP), progressMonitor); 100 85 } 101 86 102 /* (non-Javadoc)103 * @see org.openstreetmap.josm.io.OsmServerReader#parseOsmChange(org.openstreetmap.josm.gui.progress.ProgressMonitor)104 */105 87 @Override 106 public DataSet parseOsmChange(final ProgressMonitor progressMonitor) 107 throws OsmTransferException { 108 return doParse(new Parser<DataSet>() { 109 @Override 110 public DataSet parse() throws OsmTransferException, IllegalDataException { 111 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 112 if (in == null) 113 return null; 114 progressMonitor.subTask(tr("Downloading OSM data...")); 115 return OsmChangeReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false)); 116 } 117 }, progressMonitor); 88 public DataSet parseOsmChange(final ProgressMonitor progressMonitor) throws OsmTransferException { 89 return doParse(new OsmChangeParser(progressMonitor, Compression.NONE), progressMonitor); 118 90 } 119 91 120 /**121 * Method to download BZip2-compressed OSM Change files from somewhere122 */123 92 @Override 124 93 public DataSet parseOsmChangeBzip2(final ProgressMonitor progressMonitor) throws OsmTransferException { 125 return doParse(new Parser<DataSet>() { 126 @Override 127 public DataSet parse() throws OsmTransferException, IllegalDataException, IOException { 128 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 129 if (in == null) 130 return null; 131 CBZip2InputStream bzin = FileImporter.getBZip2InputStream(in); 132 progressMonitor.subTask(tr("Downloading OSM data...")); 133 return OsmChangeReader.parseDataSet(bzin, progressMonitor.createSubTaskMonitor(1, false)); 134 } 135 }, progressMonitor); 94 return doParse(new OsmChangeParser(progressMonitor, Compression.BZIP2), progressMonitor); 136 95 } 137 96 138 /**139 * Method to download GZip-compressed OSM Change files from somewhere140 */141 97 @Override 142 98 public DataSet parseOsmChangeGzip(final ProgressMonitor progressMonitor) throws OsmTransferException { 143 return doParse(new Parser<DataSet>() { 144 @Override 145 public DataSet parse() throws OsmTransferException, IllegalDataException, IOException { 146 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 147 if (in == null) 148 return null; 149 GZIPInputStream gzin = FileImporter.getGZipInputStream(in); 150 progressMonitor.subTask(tr("Downloading OSM data...")); 151 return OsmChangeReader.parseDataSet(gzin, progressMonitor.createSubTaskMonitor(1, false)); 152 } 153 }, progressMonitor); 99 return doParse(new OsmChangeParser(progressMonitor, Compression.GZIP), progressMonitor); 154 100 } 155 101 156 102 @Override 157 103 public GpxData parseRawGps(final ProgressMonitor progressMonitor) throws OsmTransferException { 158 return doParse(new Parser<GpxData>() { 159 @Override 160 public GpxData parse() throws OsmTransferException, IllegalDataException, IOException, SAXException { 161 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(1, true)); 162 if (in == null) 163 return null; 164 progressMonitor.subTask(tr("Downloading OSM data...")); 165 GpxReader reader = new GpxReader(in); 166 gpxParsedProperly = reader.parse(false); 167 GpxData result = reader.getGpxData(); 168 result.fromServer = DownloadGpsTask.isFromServer(url); 169 return result; 170 } 171 }, progressMonitor); 104 return doParse(new GpxParser(progressMonitor, Compression.NONE), progressMonitor); 105 } 106 107 @Override 108 public GpxData parseRawGpsBzip2(final ProgressMonitor progressMonitor) throws OsmTransferException { 109 return doParse(new GpxParser(progressMonitor, Compression.BZIP2), progressMonitor); 110 } 111 112 protected class OsmParser extends Parser<DataSet> { 113 protected OsmParser(ProgressMonitor progressMonitor, Compression compression) { 114 super(progressMonitor, compression); 115 } 116 117 @Override 118 public DataSet parse() throws OsmTransferException, IllegalDataException, IOException { 119 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 120 if (in == null) 121 return null; 122 progressMonitor.subTask(tr("Downloading OSM data...")); 123 return OsmReader.parseDataSet(getUncompressedInputStream(), progressMonitor.createSubTaskMonitor(1, false)); 124 } 125 } 126 127 protected class OsmChangeParser extends Parser<DataSet> { 128 protected OsmChangeParser(ProgressMonitor progressMonitor, Compression compression) { 129 super(progressMonitor, compression); 130 } 131 132 @Override 133 public DataSet parse() throws OsmTransferException, IllegalDataException, IOException { 134 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 135 if (in == null) 136 return null; 137 progressMonitor.subTask(tr("Downloading OSM data...")); 138 return OsmChangeReader.parseDataSet(getUncompressedInputStream(), progressMonitor.createSubTaskMonitor(1, false)); 139 } 140 } 141 142 protected class GpxParser extends Parser<GpxData> { 143 protected GpxParser(ProgressMonitor progressMonitor, Compression compression) { 144 super(progressMonitor, compression); 145 } 146 147 @Override 148 public GpxData parse() throws OsmTransferException, IllegalDataException, IOException, SAXException { 149 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(1, true)); 150 if (in == null) 151 return null; 152 progressMonitor.subTask(tr("Downloading OSM data...")); 153 GpxReader reader = new GpxReader(getUncompressedInputStream()); 154 gpxParsedProperly = reader.parse(false); 155 GpxData result = reader.getGpxData(); 156 result.fromServer = DownloadGpsTask.isFromServer(url); 157 return result; 158 } 172 159 } 173 160 } -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r6089 r6244 34 34 private boolean doAuthenticate = false; 35 35 protected boolean gpxParsedProperly; 36 37 protected enum Compression { 38 NONE, 39 BZIP2, 40 GZIP 41 } 36 42 37 43 /** … … 162 168 } 163 169 170 /** 171 * Download OSM files from somewhere 172 * @param progressMonitor The progress monitor 173 * @return The corresponding dataset 174 * @throws OsmTransferException if any error occurs 175 */ 164 176 public abstract DataSet parseOsm(final ProgressMonitor progressMonitor) throws OsmTransferException; 165 177 178 /** 179 * Download OSM Change files from somewhere 180 * @param progressMonitor The progress monitor 181 * @return The corresponding dataset 182 * @throws OsmTransferException if any error occurs 183 */ 166 184 public DataSet parseOsmChange(final ProgressMonitor progressMonitor) throws OsmTransferException { 167 185 return null; 168 186 } 169 187 188 /** 189 * Download BZip2-compressed OSM Change files from somewhere 190 * @param progressMonitor The progress monitor 191 * @return The corresponding dataset 192 * @throws OsmTransferException if any error occurs 193 */ 170 194 public DataSet parseOsmChangeBzip2(final ProgressMonitor progressMonitor) throws OsmTransferException { 171 195 return null; 172 196 } 173 197 198 /** 199 * Download GZip-compressed OSM Change files from somewhere 200 * @param progressMonitor The progress monitor 201 * @return The corresponding dataset 202 * @throws OsmTransferException if any error occurs 203 */ 174 204 public DataSet parseOsmChangeGzip(final ProgressMonitor progressMonitor) throws OsmTransferException { 175 205 return null; 176 206 } 177 207 208 /** 209 * Retrieve raw gps waypoints from the server API. 210 * @param progressMonitor The progress monitor 211 * @return The corresponding GPX tracks 212 * @throws OsmTransferException if any error occurs 213 */ 178 214 public GpxData parseRawGps(final ProgressMonitor progressMonitor) throws OsmTransferException { 179 215 return null; 180 216 } 181 217 218 /** 219 * Retrieve BZip2-compressed GPX files from somewhere. 220 * @param progressMonitor The progress monitor 221 * @return The corresponding GPX tracks 222 * @throws OsmTransferException if any error occurs 223 * @since 6244 224 */ 225 public GpxData parseRawGpsBzip2(final ProgressMonitor progressMonitor) throws OsmTransferException { 226 return null; 227 } 228 229 /** 230 * Download BZip2-compressed OSM files from somewhere 231 * @param progressMonitor The progress monitor 232 * @return The corresponding dataset 233 * @throws OsmTransferException if any error occurs 234 */ 182 235 public DataSet parseOsmBzip2(final ProgressMonitor progressMonitor) throws OsmTransferException { 183 236 return null; 184 237 } 185 238 239 /** 240 * Download GZip-compressed OSM files from somewhere 241 * @param progressMonitor The progress monitor 242 * @return The corresponding dataset 243 * @throws OsmTransferException if any error occurs 244 */ 186 245 public DataSet parseOsmGzip(final ProgressMonitor progressMonitor) throws OsmTransferException { 187 246 return null;
Note:
See TracChangeset
for help on using the changeset viewer.