source: josm/trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/OpenFileHandler.java@ 18134

Last change on this file since 18134 was 18134, checked in by Don-vip, 3 years ago

fix #21231 - make sure remote control request handlers do not block thread with time-consuming operations

  • Property svn:eol-style set to native
File size: 1.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.remotecontrol.handler;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.io.File;
7import java.util.Arrays;
8import java.util.EnumSet;
9
10import org.openstreetmap.josm.actions.OpenFileAction;
11import org.openstreetmap.josm.gui.io.importexport.Options;
12import org.openstreetmap.josm.gui.util.GuiHelper;
13import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault;
14
15/**
16 * Opens a local file
17 */
18public class OpenFileHandler extends RequestHandler {
19
20 /**
21 * The remote control command name used to open a local file.
22 */
23 public static final String command = "open_file";
24
25 @Override
26 public String[] getMandatoryParams() {
27 return new String[]{"filename"};
28 }
29
30 @Override
31 public String getUsage() {
32 return "opens a local file in JOSM";
33 }
34
35 @Override
36 public String[] getUsageExamples() {
37 return new String[] {"/open_file?filename=/tmp/test.osm"};
38 }
39
40 @Override
41 public PermissionPrefWithDefault getPermissionPref() {
42 return PermissionPrefWithDefault.OPEN_FILES;
43 }
44
45 @Override
46 protected void handleRequest() throws RequestHandlerErrorException, RequestHandlerBadRequestException {
47 EnumSet<Options> options = EnumSet.noneOf(Options.class);
48 if (PermissionPrefWithDefault.ALLOW_WEB_RESOURCES.isAllowed()) {
49 options.add(Options.ALLOW_WEB_RESOURCES);
50 }
51 GuiHelper.runInEDT(() ->
52 OpenFileAction.openFiles(Arrays.asList(new File(args.get("filename"))), options.toArray(new Options[0])));
53 }
54
55 @Override
56 public String getPermissionMessage() {
57 return tr("Remote Control has been asked to open a local file.");
58 }
59
60 @Override
61 protected void validateRequest() throws RequestHandlerBadRequestException {
62 // Nothing to do
63 }
64}
Note: See TracBrowser for help on using the repository browser.