| 381 | | downloadFromParamString(false, s); |
| | 379 | File f = null; |
| | 380 | switch(paramType(s)) { |
| | 381 | case httpUrl: |
| | 382 | downloadFromParamHttp(false, s); |
| | 383 | break; |
| | 384 | case bounds: |
| | 385 | downloadFromParamBounds(false, s); |
| | 386 | break; |
| | 387 | case fileUrl: |
| | 388 | try { |
| | 389 | f = new File(new URI(s)); |
| | 390 | } catch (URISyntaxException e) { |
| | 391 | JOptionPane.showMessageDialog( |
| | 392 | Main.parent, |
| | 393 | tr("Ignoring malformed file URL: \"{0}\"", s), |
| | 394 | tr("Warning"), |
| | 395 | JOptionPane.WARNING_MESSAGE |
| | 396 | ); |
| | 397 | } |
| | 398 | if (f!=null) { |
| | 399 | fileList.add(f); |
| | 400 | } |
| | 401 | break; |
| | 402 | case fileName: |
| | 403 | f = new File(s); |
| | 404 | fileList.add(f); |
| | 405 | break; |
| | 406 | } |
| | 407 | } |
| | 408 | if(!fileList.isEmpty()) |
| | 409 | { |
| | 410 | OpenFileAction.openFiles(fileList); |
| 419 | | private static void downloadFromParamString(final boolean rawGps, String s) { |
| 420 | | if (s.startsWith("http:")) { |
| 421 | | final Bounds b = OsmUrlToBounds.parse(s); |
| 422 | | if (b == null) { |
| 423 | | JOptionPane.showMessageDialog( |
| 424 | | Main.parent, |
| 425 | | tr("Ignoring malformed URL: \"{0}\"", s), |
| 426 | | tr("Warning"), |
| 427 | | JOptionPane.WARNING_MESSAGE |
| 428 | | ); |
| 429 | | } else { |
| 430 | | //DownloadTask osmTask = main.menu.download.downloadTasks.get(0); |
| 431 | | DownloadTask osmTask = new DownloadOsmTask(); |
| 432 | | Future<?> future = osmTask.download(true, b, null); |
| 433 | | Main.worker.submit(new PostDownloadHandler(osmTask, future)); |
| 434 | | } |
| 435 | | return; |
| 436 | | } |
| 438 | | if (s.startsWith("file:")) { |
| 439 | | File f = null; |
| 440 | | try { |
| 441 | | f = new File(new URI(s)); |
| 442 | | } catch (URISyntaxException e) { |
| 443 | | JOptionPane.showMessageDialog( |
| 444 | | Main.parent, |
| 445 | | tr("Ignoring malformed file URL: \"{0}\"", s), |
| 446 | | tr("Warning"), |
| 447 | | JOptionPane.WARNING_MESSAGE |
| 448 | | ); |
| 449 | | } |
| 450 | | try { |
| 451 | | if (f!=null) { |
| 452 | | OpenFileAction.openFile(f); |
| 453 | | } |
| 454 | | } catch(IllegalDataException e) { |
| 455 | | e.printStackTrace(); |
| 456 | | JOptionPane.showMessageDialog( |
| 457 | | Main.parent, |
| 458 | | tr("<html>Could not read file ''{0}\''.<br> Error is: <br>{1}</html>", f.getName(), e.getMessage()), |
| 459 | | tr("Error"), |
| 460 | | JOptionPane.ERROR_MESSAGE |
| 461 | | ); |
| 462 | | }catch(IOException e) { |
| 463 | | e.printStackTrace(); |
| 464 | | JOptionPane.showMessageDialog( |
| 465 | | Main.parent, |
| 466 | | tr("<html>Could not read file ''{0}\''.<br> Error is: <br>{1}</html>", f.getName(), e.getMessage()), |
| 467 | | tr("Error"), |
| 468 | | JOptionPane.ERROR_MESSAGE |
| 469 | | ); |
| 470 | | } |
| 471 | | return; |
| | 464 | /** |
| | 465 | * The type of a command line parameter, to be used in switch statements. |
| | 466 | * @see paramType |
| | 467 | */ |
| | 468 | private enum DownloadParamType { httpUrl, fileUrl, bounds, fileName } |
| | 469 | |
| | 470 | /** |
| | 471 | * Guess the type of a parameter string specified on the command line with --download= or --downloadgps. |
| | 472 | * @param s A parameter string |
| | 473 | * @return The guessed parameter type |
| | 474 | */ |
| | 475 | private DownloadParamType paramType(String s) { |
| | 476 | if(s.startsWith("http:")) return DownloadParamType.httpUrl; |
| | 477 | if(s.startsWith("file:")) return DownloadParamType.fileUrl; |
| | 478 | final StringTokenizer st = new StringTokenizer(s, ","); |
| | 479 | // we assume a string with exactly 3 commas is a bounds parameter |
| | 480 | if (st.countTokens() == 4) return DownloadParamType.bounds; |
| | 481 | // everything else must be a file name |
| | 482 | return DownloadParamType.fileName; |
| | 483 | } |
| | 484 | |
| | 485 | /** |
| | 486 | * Download area specified on the command line as OSM URL. |
| | 487 | * @param rawGps Flag to download raw GPS tracks |
| | 488 | * @param s The URL parameter |
| | 489 | */ |
| | 490 | private static void downloadFromParamHttp(final boolean rawGps, String s) { |
| | 491 | final Bounds b = OsmUrlToBounds.parse(s); |
| | 492 | if (b == null) { |
| | 493 | JOptionPane.showMessageDialog( |
| | 494 | Main.parent, |
| | 495 | tr("Ignoring malformed URL: \"{0}\"", s), |
| | 496 | tr("Warning"), |
| | 497 | JOptionPane.WARNING_MESSAGE |
| | 498 | ); |
| | 499 | } else { |
| | 500 | downloadFromParamBounds(rawGps, b); |
| 480 | | try { |
| 481 | | DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask(); |
| 482 | | // asynchronously launch the download task ... |
| 483 | | Future<?> future = task.download(true, b, null); |
| 484 | | // ... and the continuation when the download is finished (this will wait for the download to finish) |
| 485 | | Main.worker.execute(new PostDownloadHandler(task, future)); |
| 486 | | return; |
| 487 | | } catch (final NumberFormatException e) { |
| 488 | | } |
| 489 | | } |
| 490 | | File f = new File(s); |
| 491 | | try { |
| 492 | | OpenFileAction.openFile(f); |
| 493 | | }catch(IllegalDataException e) { |
| 494 | | e.printStackTrace(); |
| 495 | | JOptionPane.showMessageDialog( |
| 496 | | Main.parent, |
| 497 | | tr("<html>Could not read file ''{0}\''.<br> Error is: <br>{1}</html>", f.getName(), e.getMessage()), |
| 498 | | tr("Error"), |
| 499 | | JOptionPane.ERROR_MESSAGE |
| 500 | | ); |
| 501 | | }catch(IOException e) { |
| 502 | | e.printStackTrace(); |
| 503 | | JOptionPane.showMessageDialog( |
| 504 | | Main.parent, |
| 505 | | tr("<html>Could not read file ''{0}\''.<br> Error is: <br>{1}</html>", f.getName(), e.getMessage()), |
| 506 | | tr("Error"), |
| 507 | | JOptionPane.ERROR_MESSAGE |
| 508 | | ); |
| | 516 | downloadFromParamBounds(rawGps, b); |
| | 520 | /** |
| | 521 | * Download area specified as Bounds value. |
| | 522 | * @param rawGps Flag to download raw GPS tracks |
| | 523 | * @param b The bounds value |
| | 524 | * @see downloadFromParamBounds(final boolean rawGps, String s) |
| | 525 | * @see downloadFromParamHttp |
| | 526 | */ |
| | 527 | private static void downloadFromParamBounds(final boolean rawGps, Bounds b) { |
| | 528 | DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask(); |
| | 529 | // asynchronously launch the download task ... |
| | 530 | Future<?> future = task.download(true, b, null); |
| | 531 | // ... and the continuation when the download is finished (this will wait for the download to finish) |
| | 532 | Main.worker.execute(new PostDownloadHandler(task, future)); |
| | 533 | } |
| | 534 | |
| | 535 | |