1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions.downloadtasks;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.net.URISyntaxException;
|
---|
8 | import java.net.URL;
|
---|
9 | import java.util.concurrent.Future;
|
---|
10 |
|
---|
11 | import org.openstreetmap.josm.Main;
|
---|
12 | import org.openstreetmap.josm.actions.SessionLoadAction.Loader;
|
---|
13 | import org.openstreetmap.josm.data.Bounds;
|
---|
14 | import org.openstreetmap.josm.gui.progress.ProgressMonitor;
|
---|
15 | import org.openstreetmap.josm.tools.HttpClient;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * Task allowing to download JOSM session (*.jos, *.joz file).
|
---|
19 | * @since 6215
|
---|
20 | */
|
---|
21 | public class DownloadSessionTask extends AbstractDownloadTask<Object> {
|
---|
22 |
|
---|
23 | private static final String PATTERN_SESSION = "https?://.*/.*\\.jo(s|z)";
|
---|
24 |
|
---|
25 | private Loader loader;
|
---|
26 |
|
---|
27 | @Override
|
---|
28 | public String getTitle() {
|
---|
29 | return tr("Download session");
|
---|
30 | }
|
---|
31 |
|
---|
32 | @Override
|
---|
33 | public String[] getPatterns() {
|
---|
34 | return new String[]{PATTERN_SESSION};
|
---|
35 | }
|
---|
36 |
|
---|
37 | @Override
|
---|
38 | public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
|
---|
39 | return null;
|
---|
40 | }
|
---|
41 |
|
---|
42 | @Override
|
---|
43 | public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
|
---|
44 | if (url != null && (url.matches(PATTERN_SESSION))) {
|
---|
45 | try {
|
---|
46 | URL u = new URL(url);
|
---|
47 | loader = new Loader(HttpClient.create(u).connect().getContent(), u.toURI(), url.endsWith(".joz"));
|
---|
48 | return Main.worker.submit(loader);
|
---|
49 | } catch (URISyntaxException | IOException e) {
|
---|
50 | Main.error(e);
|
---|
51 | }
|
---|
52 | }
|
---|
53 | return null;
|
---|
54 | }
|
---|
55 |
|
---|
56 | @Override
|
---|
57 | public void cancel() {
|
---|
58 | if (loader != null) {
|
---|
59 | loader.cancel();
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | @Override
|
---|
64 | public String getConfirmationMessage(URL url) {
|
---|
65 | // TODO
|
---|
66 | return null;
|
---|
67 | }
|
---|
68 |
|
---|
69 | /**
|
---|
70 | * Do not allow to load a session file via remotecontrol.
|
---|
71 | *
|
---|
72 | * Session importers can be added by plugins and there is currently
|
---|
73 | * no way to ensure that these are safe for remotecontol.
|
---|
74 | * @return <code>true</code> if session import is allowed
|
---|
75 | */
|
---|
76 | @Override
|
---|
77 | public boolean isSafeForRemotecontrolRequests() {
|
---|
78 | return Main.pref.getBoolean("remotecontrol.import.allow_session", false);
|
---|
79 | }
|
---|
80 | }
|
---|