source: josm/trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/FeaturesHandler.java@ 7937

Last change on this file since 7937 was 7937, checked in by bastiK, 9 years ago

add subversion property svn:eol=native

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.io.remotecontrol.handler;
3
4import org.openstreetmap.josm.Main;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault;
8import org.openstreetmap.josm.io.remotecontrol.RequestProcessor;
9
10/**
11 * Reports available commands, their parameters and examples
12 * @since 6091
13 */
14public class FeaturesHandler extends RequestHandler {
15
16 /**
17 * The remote control command name used to reply version.
18 */
19 public static final String command = "features";
20
21 @Override
22 protected void handleRequest() throws RequestHandlerErrorException,
23 RequestHandlerBadRequestException {
24 StringBuilder buf = new StringBuilder();
25 String q=args.get("q");
26 if (q!=null) {
27 buf.append("[");
28 boolean first = true;
29 for (String s: q.split("[,\\s]+")) {
30 if (first) {
31 first = false;
32 } else {
33 buf.append(", ");
34 }
35 String info = RequestProcessor.getHandlerInfoAsJSON("/"+s);
36 if (info!=null) {
37 buf.append(info);
38 } else {
39 Main.warn("Unknown handler {0} passed to /features request", s);
40 }
41 }
42 buf.append("]");
43 } else {
44 buf.append(RequestProcessor.getHandlersInfoAsJSON());
45 }
46
47 content = buf.toString();
48 contentType = "application/json";
49 if (args.containsKey("jsonp")) {
50 content = args.get("jsonp") + " && " + args.get("jsonp") + "(" + content + ")";
51 }
52 }
53
54 @Override
55 public String getPermissionMessage() {
56 return tr("Remote Control has been asked to report its supported features. This enables web sites to guess a running JOSM version");
57 }
58
59 @Override
60 public PermissionPrefWithDefault getPermissionPref() {
61 return PermissionPrefWithDefault.READ_PROTOCOL_VERSION;
62 }
63
64 @Override
65 public String[] getMandatoryParams() {
66 return null;
67 }
68
69 @Override
70 public String[] getOptionalParams() {
71 return new String[]{"jsonp", "q"};
72 }
73
74 @Override
75 protected void validateRequest() throws RequestHandlerBadRequestException {
76 // Nothing to do
77 }
78
79 @Override
80 public String getUsage() {
81 return "reports available commands, their parameters and examples";
82 }
83
84 @Override
85 public String[] getUsageExamples() {
86 return new String[] {"/features", "/features?q=import,add_node"};
87 }
88}
Note: See TracBrowser for help on using the repository browser.