1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.io.remotecontrol.handler;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.io.File;
|
---|
7 | import java.util.Arrays;
|
---|
8 |
|
---|
9 | import org.openstreetmap.josm.actions.OpenFileAction;
|
---|
10 | import org.openstreetmap.josm.gui.util.GuiHelper;
|
---|
11 | import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Opens a local file
|
---|
15 | */
|
---|
16 | public class OpenFileHandler extends RequestHandler {
|
---|
17 |
|
---|
18 | /**
|
---|
19 | * The remote control command name used to open a local file.
|
---|
20 | */
|
---|
21 | public static final String command = "open_file";
|
---|
22 |
|
---|
23 | @Override
|
---|
24 | public String[] getMandatoryParams() {
|
---|
25 | return new String[]{"filename"};
|
---|
26 | }
|
---|
27 |
|
---|
28 | @Override
|
---|
29 | public String getUsage() {
|
---|
30 | return "opens a local file in JOSM";
|
---|
31 | }
|
---|
32 |
|
---|
33 | @Override
|
---|
34 | public String[] getUsageExamples() {
|
---|
35 | return new String[] {"/open_file?filename=/tmp/test.osm"};
|
---|
36 | }
|
---|
37 |
|
---|
38 | @Override
|
---|
39 | public PermissionPrefWithDefault getPermissionPref() {
|
---|
40 | return PermissionPrefWithDefault.OPEN_FILES;
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | protected void handleRequest() throws RequestHandlerErrorException, RequestHandlerBadRequestException {
|
---|
45 | GuiHelper.runInEDTAndWait(new Runnable() {
|
---|
46 | @Override public void run() {
|
---|
47 | OpenFileAction.openFiles(Arrays.asList(new File(args.get("filename"))));
|
---|
48 | }
|
---|
49 | });
|
---|
50 | }
|
---|
51 |
|
---|
52 | @Override
|
---|
53 | public String getPermissionMessage() {
|
---|
54 | return tr("Remote Control has been asked to open a local file.");
|
---|
55 | }
|
---|
56 |
|
---|
57 | @Override
|
---|
58 | protected void validateRequest() throws RequestHandlerBadRequestException {
|
---|
59 | // Nothing to do
|
---|
60 | }
|
---|
61 | }
|
---|