- Timestamp:
- 2012-03-14T23:33:27+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/RemoteControlPreference.java
r4976 r5085 9 9 import java.awt.event.ActionEvent; 10 10 import java.awt.event.ActionListener; 11 import java.util.LinkedHashMap; 12 import java.util.Map; 13 import java.util.Map.Entry; 11 14 12 15 import javax.swing.BorderFactory; … … 16 19 import javax.swing.JPanel; 17 20 import javax.swing.JSeparator; 18 import javax.swing.UIManager;19 21 20 22 import org.openstreetmap.josm.Main; 21 23 import org.openstreetmap.josm.gui.util.GuiHelper; 24 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; 22 25 import org.openstreetmap.josm.io.remotecontrol.RemoteControl; 23 import org.openstreetmap.josm.io.remotecontrol.handler.AddNodeHandler;24 import org.openstreetmap.josm.io.remotecontrol.handler.ImageryHandler;25 import org.openstreetmap.josm.io.remotecontrol.handler.ImportHandler;26 import org.openstreetmap.josm.io.remotecontrol.handler.LoadAndZoomHandler;27 26 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler; 28 import org.openstreetmap.josm.io.remotecontrol.handler.VersionHandler;29 27 import org.openstreetmap.josm.tools.GBC; 30 28 … … 34 32 * @author Frederik Ramm 35 33 */ 36 public class RemoteControlPreference extends DefaultTabPreferenceSetting 37 { 34 public class RemoteControlPreference extends DefaultTabPreferenceSetting { 35 38 36 public static class Factory implements PreferenceSettingFactory { 37 39 38 @Override 40 39 public PreferenceSetting createPreferenceSetting() { … … 42 41 } 43 42 } 44 43 45 44 private RemoteControlPreference() { 46 45 super("remotecontrol", tr("Remote Control"), tr("Settings for the remote control feature.")); 46 for (PermissionPrefWithDefault p : PermissionPrefWithDefault.getPermissionPrefs()) { 47 JCheckBox cb = new JCheckBox(p.preferenceText); 48 cb.setSelected(p.isAllowed()); 49 prefs.put(p, cb); 50 } 47 51 } 48 52 private final Map<PermissionPrefWithDefault, JCheckBox> prefs = 53 new LinkedHashMap<PermissionPrefWithDefault, JCheckBox>(); 49 54 private JCheckBox enableRemoteControl; 50 51 private JCheckBox permissionLoadData = new JCheckBox(tr("Load data from API"));52 private JCheckBox permissionImportData = new JCheckBox(tr("Import data from URL"));53 private JCheckBox permissionLoadImagery = new JCheckBox(tr("Load imagery layers"));54 private JCheckBox permissionCreateObjects = new JCheckBox(tr("Create new objects"));55 private JCheckBox permissionChangeSelection = new JCheckBox(tr("Change the selection"));56 private JCheckBox permissionChangeViewport = new JCheckBox(tr("Change the viewport"));57 private JCheckBox permissionReadProtocolversion = new JCheckBox(tr("Read protocol version"));58 55 private JCheckBox loadInNewLayer = new JCheckBox(tr("Download objects to new layer")); 59 56 private JCheckBox alwaysAskUserConfirm = new JCheckBox(tr("Confirm all Remote Control actions manually")); 60 57 58 @Override 61 59 public void addGui(final PreferenceTabbedPane gui) { 62 60 63 61 JPanel remote = new JPanel(new GridBagLayout()); 62 63 final JLabel descLabel = new JLabel("<html>" 64 + tr("Allows JOSM to be controlled from other applications, e.g. from a web browser.") 65 + "</html>"); 66 descLabel.setFont(descLabel.getFont().deriveFont(Font.PLAIN)); 67 remote.add(descLabel, GBC.eol().insets(5, 5, 0, 10).fill(GBC.HORIZONTAL)); 68 69 final JLabel portLabel = new JLabel("<html>" + tr("JOSM will always listen at <b>port 8111</b> on localhost. " 70 + "<br>This port is not configurable because it is referenced by external applications talking to JOSM.") + "</html>"); 71 portLabel.setFont(portLabel.getFont().deriveFont(Font.PLAIN)); 72 remote.add(portLabel, GBC.eol().insets(5, 5, 0, 10).fill(GBC.HORIZONTAL)); 64 73 65 74 remote.add(enableRemoteControl = new JCheckBox(tr("Enable remote control"), RemoteControl.PROP_REMOTECONTROL_ENABLED.get()), GBC.eol()); … … 71 80 remote.add(wrapper, GBC.eol().fill(GBC.HORIZONTAL).insets(5, 5, 5, 5)); 72 81 73 final JLabel descLabel = new JLabel("<html>"+74 tr("The remote control feature allows JOSM to be controlled from other applications, e.g. from a web browser.")75 + "</html>");76 wrapper.add(descLabel, GBC.eol().insets(5,5,0,10).fill(GBC.HORIZONTAL));77 descLabel.setFont(descLabel.getFont().deriveFont(Font.PLAIN));78 79 82 wrapper.add(new JLabel(tr("Permitted actions:")), GBC.eol()); 80 83 int INDENT = 15; 81 wrapper.add(permissionLoadData, GBC.eol().insets(INDENT,5,0,0).fill(GBC.HORIZONTAL)); 82 wrapper.add(permissionImportData, GBC.eol().insets(INDENT,5,0,0).fill(GBC.HORIZONTAL)); 83 wrapper.add(permissionLoadImagery, GBC.eol().insets(INDENT,5,0,0).fill(GBC.HORIZONTAL)); 84 wrapper.add(permissionChangeSelection, GBC.eol().insets(INDENT,5,0,0).fill(GBC.HORIZONTAL)); 85 wrapper.add(permissionChangeViewport, GBC.eol().insets(INDENT,5,0,0).fill(GBC.HORIZONTAL)); 86 wrapper.add(permissionCreateObjects, GBC.eol().insets(INDENT,5,0,0).fill(GBC.HORIZONTAL)); 87 wrapper.add(permissionReadProtocolversion, GBC.eol().insets(INDENT,5,0,0).fill(GBC.HORIZONTAL)); 84 for (JCheckBox p : prefs.values()) { 85 wrapper.add(p, GBC.eol().insets(INDENT, 5, 0, 0).fill(GBC.HORIZONTAL)); 86 } 88 87 89 88 wrapper.add(new JSeparator(), GBC.eop().fill(GBC.HORIZONTAL).insets(15, 5, 15, 5)); 90 91 89 wrapper.add(loadInNewLayer, GBC.eol().fill(GBC.HORIZONTAL)); 92 93 90 wrapper.add(alwaysAskUserConfirm, GBC.eol().fill(GBC.HORIZONTAL)); 94 95 final JLabel portLabel = new JLabel("<html>"+tr("JOSM will always listen at port 8111 on localhost. " +96 "This port is not configurable because it is referenced by external applications talking to JOSM.") + "</html>");97 portLabel.setFont(portLabel.getFont().deriveFont(Font.PLAIN));98 99 wrapper.add(portLabel, GBC.eol().insets(5,5,0,10).fill(GBC.HORIZONTAL));100 91 101 92 remote.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.VERTICAL)); 102 93 103 permissionLoadData.setSelected(Main.pref.getBoolean(LoadAndZoomHandler.loadDataPermissionKey, LoadAndZoomHandler.loadDataPermissionDefault));104 permissionImportData.setSelected(Main.pref.getBoolean(ImportHandler.permissionKey, ImportHandler.permissionDefault));105 permissionLoadImagery.setSelected(Main.pref.getBoolean(ImageryHandler.permissionKey, ImageryHandler.permissionDefault));106 permissionChangeSelection.setSelected(Main.pref.getBoolean(LoadAndZoomHandler.changeSelectionPermissionKey, LoadAndZoomHandler.changeSelectionPermissionDefault));107 permissionChangeViewport.setSelected(Main.pref.getBoolean(LoadAndZoomHandler.changeViewportPermissionKey, LoadAndZoomHandler.changeViewportPermissionDefault));108 permissionCreateObjects.setSelected(Main.pref.getBoolean(AddNodeHandler.permissionKey, AddNodeHandler.permissionDefault));109 permissionReadProtocolversion.setSelected(Main.pref.getBoolean(VersionHandler.permissionKey, VersionHandler.permissionDefault));110 94 loadInNewLayer.setSelected(Main.pref.getBoolean(RequestHandler.loadInNewLayerKey, RequestHandler.loadInNewLayerDefault)); 111 95 alwaysAskUserConfirm.setSelected(Main.pref.getBoolean(RequestHandler.globalConfirmationKey, RequestHandler.globalConfirmationDefault)); 112 96 113 97 ActionListener remoteControlEnabled = new ActionListener() { 98 99 @Override 114 100 public void actionPerformed(ActionEvent e) { 115 boolean enabled = enableRemoteControl.isSelected();116 101 GuiHelper.setEnabledRec(wrapper, enableRemoteControl.isSelected()); 117 102 // 'setEnabled(false)' does not work for JLabel with html text, so do it manually 118 portLabel.setForeground(enabled ? UIManager.getColor("Label.foreground") : UIManager.getColor("Label.disabledForeground"));119 descLabel.setForeground(enabled ? UIManager.getColor("Label.foreground") : UIManager.getColor("Label.disabledForeground"));120 103 // FIXME: use QuadStateCheckBox to make checkboxes unset when disabled 121 104 } … … 126 109 } 127 110 111 @Override 128 112 public boolean ok() { 129 113 boolean enabled = enableRemoteControl.isSelected(); 130 114 boolean changed = RemoteControl.PROP_REMOTECONTROL_ENABLED.put(enabled); 131 115 if (enabled) { 132 Main.pref.put(LoadAndZoomHandler.loadDataPermissionKey, permissionLoadData.isSelected()); 133 Main.pref.put(ImportHandler.permissionKey, permissionImportData.isSelected()); 134 Main.pref.put(ImageryHandler.permissionKey, permissionLoadImagery.isSelected()); 135 Main.pref.put(LoadAndZoomHandler.changeSelectionPermissionKey, permissionChangeSelection.isSelected()); 136 Main.pref.put(LoadAndZoomHandler.changeViewportPermissionKey, permissionChangeViewport.isSelected()); 137 Main.pref.put(AddNodeHandler.permissionKey, permissionCreateObjects.isSelected()); 138 Main.pref.put(VersionHandler.permissionKey, permissionReadProtocolversion.isSelected()); 116 for (Entry<PermissionPrefWithDefault, JCheckBox> p : prefs.entrySet()) { 117 Main.pref.put(p.getKey().pref, p.getValue().isSelected()); 118 } 139 119 Main.pref.put(RequestHandler.loadInNewLayerKey, loadInNewLayer.isSelected()); 140 120 Main.pref.put(RequestHandler.globalConfirmationKey, alwaysAskUserConfirm.isSelected()); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/PermissionPrefWithDefault.java
r4191 r5085 2 2 package org.openstreetmap.josm.io.remotecontrol; 3 3 4 import java.util.Arrays; 5 import java.util.List; 6 import org.openstreetmap.josm.Main; 7 import static org.openstreetmap.josm.tools.I18n.tr; 8 4 9 /** 5 10 * Contains a preference name to control permission for the operation 6 * implemented by the RequestHandler, and an error message to be displayed 7 * ifnot permitted.11 * implemented by the RequestHandler, and an error message to be displayed if 12 * not permitted. 8 13 * 9 14 * @author Bodo Meissner … … 11 16 public class PermissionPrefWithDefault { 12 17 13 /** name of the preference setting to permit the remote operation */ 14 public String pref; 15 /** message to be displayed if operation is not permitted */ 16 public String message; 18 public static final PermissionPrefWithDefault LOAD_DATA = 19 new PermissionPrefWithDefault("remotecontrol.permission.load-data", true, tr("Load data from API")); 20 public static final PermissionPrefWithDefault IMPORT_DATA = 21 new PermissionPrefWithDefault("remotecontrol.permission.import", true, tr("Import data from URL")); 22 public static final PermissionPrefWithDefault OPEN_FILES = 23 new PermissionPrefWithDefault("remotecontrol.permission.open-files", false, tr("Open local files")); 24 public static final PermissionPrefWithDefault LOAD_IMAGERY = 25 new PermissionPrefWithDefault("remotecontrol.permission.imagery", true, tr("Load imagery layers")); 26 public static final PermissionPrefWithDefault CHANGE_SELECTION = 27 new PermissionPrefWithDefault("remotecontrol.permission.change-selection", true, tr("Change the selection")); 28 public static final PermissionPrefWithDefault CHANGE_VIEWPORT = 29 new PermissionPrefWithDefault("remotecontrol.permission.change-viewport", true, tr("Change the viewport")); 30 public static final PermissionPrefWithDefault CREATE_OBJECTS = 31 new PermissionPrefWithDefault("remotecontrol.permission.create-objects", true, tr("Create new objects")); 32 public static final PermissionPrefWithDefault READ_PROTOCOL_VERSION = 33 new PermissionPrefWithDefault("remotecontrol.permission.read-protocolversion", true, tr("Read protocol version")); 34 /** 35 * name of the preference setting to permit the remote operation 36 */ 37 public final String pref; 38 /** 39 * default preference setting 40 */ 41 public final boolean defaultVal; 42 /** 43 * text for the preference dialog checkbox 44 */ 45 public final String preferenceText; 17 46 18 public boolean defaultVal = true; 47 public PermissionPrefWithDefault(String pref, boolean defaultVal, String preferenceText) { 48 this.pref = pref; 49 this.defaultVal = defaultVal; 50 this.preferenceText = preferenceText; 51 } 19 52 20 public PermissionPrefWithDefault(String pref, boolean defaultVal, String message) { 21 this.pref = pref; 22 this.message = message; 23 this.defaultVal = defaultVal; 53 public boolean isAllowed() { 54 return Main.pref.getBoolean(pref, defaultVal); 55 } 56 57 public static List<PermissionPrefWithDefault> getPermissionPrefs() { 58 return Arrays.asList( 59 LOAD_DATA, IMPORT_DATA, OPEN_FILES, LOAD_IMAGERY, 60 CHANGE_SELECTION, CHANGE_VIEWPORT, 61 CREATE_OBJECTS, READ_PROTOCOL_VERSION); 24 62 } 25 63 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/RequestProcessor.java
r4834 r5085 13 13 import java.util.Arrays; 14 14 import java.util.Date; 15 import java.util.HashMap;16 15 import java.util.Map; 17 16 import java.util.Map.Entry; 18 17 import java.util.StringTokenizer; 19 18 import java.util.TreeMap; 20 import java.util.TreeSet;21 19 22 20 import org.openstreetmap.josm.io.remotecontrol.handler.AddNodeHandler; … … 26 24 import org.openstreetmap.josm.io.remotecontrol.handler.LoadAndZoomHandler; 27 25 import org.openstreetmap.josm.io.remotecontrol.handler.LoadObjectHandler; 26 import org.openstreetmap.josm.io.remotecontrol.handler.OpenFileHandler; 28 27 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler; 29 28 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; … … 117 116 /** Add default request handlers */ 118 117 static { 119 addRequestHandlerClass(LoadAndZoomHandler.command, 120 LoadAndZoomHandler.class, true); 121 addRequestHandlerClass(LoadAndZoomHandler.command2, 122 LoadAndZoomHandler.class, true); 118 addRequestHandlerClass(LoadAndZoomHandler.command, LoadAndZoomHandler.class, true); 119 addRequestHandlerClass(LoadAndZoomHandler.command2, LoadAndZoomHandler.class, true); 123 120 addRequestHandlerClass(ImageryHandler.command, ImageryHandler.class, true); 124 121 addRequestHandlerClass(AddNodeHandler.command, AddNodeHandler.class, true); … … 127 124 addRequestHandlerClass(VersionHandler.command, VersionHandler.class, true); 128 125 addRequestHandlerClass(LoadObjectHandler.command, LoadObjectHandler.class, true); 126 addRequestHandlerClass(OpenFileHandler.command, OpenFileHandler.class, true); 129 127 } 130 128 … … 203 201 handler.setCommand(command); 204 202 handler.setUrl(url); 205 handler.checkPermission();206 203 handler.handle(); 207 204 sendHeader(out, "200 OK", handler.getContentType(), false); … … 216 213 sendBadRequest(out, ex.getMessage()); 217 214 } catch (RequestHandlerForbiddenException ex) { 218 sendForbidden(out );215 sendForbidden(out, ex.getMessage()); 219 216 } 220 217 } … … 281 278 * If the error can not be written 282 279 */ 283 private void sendForbidden(Writer out ) throws IOException {280 private void sendForbidden(Writer out, String help) throws IOException { 284 281 sendHeader(out, "403 Forbidden", "text/html", true); 285 282 out.write("<HTML>\r\n"); … … 288 285 out.write("<BODY>"); 289 286 out.write("<H1>HTTP Error 403: Forbidden</h2>\r\n"); 287 if (help != null) { 288 out.write(help); 289 } 290 290 out.write("</BODY></HTML>\r\n"); 291 291 out.flush(); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java
r4946 r5085 18 18 19 19 public static final String command = "add_node"; 20 public static final String permissionKey = "remotecontrol.permission.create-objects";21 public static final boolean permissionDefault = false;22 20 23 21 @Override … … 39 37 @Override 40 38 public PermissionPrefWithDefault getPermissionPref() { 41 return new PermissionPrefWithDefault(permissionKey, permissionDefault, 42 "RemoteControl: creating objects forbidden by preferences"); 39 return PermissionPrefWithDefault.CREATE_OBJECTS; 43 40 } 44 41 … … 61 58 Main.main.undoRedo.add(new AddCommand(nnew)); 62 59 Main.main.getCurrentDataSet().setSelected(nnew); 63 if ( Main.pref.getBoolean(LoadAndZoomHandler.changeViewportPermissionKey, LoadAndZoomHandler.changeViewportPermissionDefault)) {60 if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) { 64 61 AutoScaleAction.autoScale("selection"); 65 62 } else { -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java
r4946 r5085 13 13 import org.openstreetmap.josm.data.osm.Node; 14 14 import org.openstreetmap.josm.data.osm.Way; 15 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; 15 16 16 17 /** … … 41 42 Main.main.undoRedo.add(new SequenceCommand(tr("Add way"), commands)); 42 43 Main.main.getCurrentDataSet().setSelected(way); 43 if ( Main.pref.getBoolean(LoadAndZoomHandler.changeViewportPermissionKey, LoadAndZoomHandler.changeViewportPermissionDefault)) {44 if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) { 44 45 AutoScaleAction.autoScale("selection"); 45 46 } else { … … 52 53 return tr("Remote Control has been asked to create a new way."); 53 54 } 55 56 @Override 57 public PermissionPrefWithDefault getPermissionPref() { 58 return PermissionPrefWithDefault.CREATE_OBJECTS; 59 } 54 60 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandler.java
r5010 r5085 7 7 import java.net.URLDecoder; 8 8 import java.util.HashMap; 9 import java.util.StringTokenizer;10 9 11 10 import org.openstreetmap.josm.Main; … … 15 14 16 15 public class ImageryHandler extends RequestHandler { 16 17 17 public static final String command = "imagery"; 18 public static final String permissionKey = "remotecontrol.permission.imagery";19 public static final boolean permissionDefault = true;20 18 21 19 @Override 22 20 public String getPermissionMessage() { 23 return tr("Remote Control has been asked to load an imagery layer from the following URL:") +24 "<br>" + args.get("url");21 return tr("Remote Control has been asked to load an imagery layer from the following URL:") 22 + "<br>" + args.get("url"); 25 23 } 26 24 27 25 @Override 28 public String[] getMandatoryParams() 29 { 30 return new String[] { "url" }; 26 public String[] getMandatoryParams() { 27 return new String[]{"url"}; 31 28 } 32 29 33 30 @Override 34 public PermissionPrefWithDefault getPermissionPref() 35 { 36 return new PermissionPrefWithDefault(permissionKey, permissionDefault, 37 "RemoteControl: import forbidden by preferences"); 31 public PermissionPrefWithDefault getPermissionPref() { 32 return PermissionPrefWithDefault.LOAD_IMAGERY; 38 33 } 39 34 … … 41 36 protected void handleRequest() throws RequestHandlerErrorException { 42 37 if (Main.map == null) //Avoid exception when creating ImageryLayer with null MapFrame 38 { 43 39 throw new RequestHandlerErrorException(); 40 } 44 41 String url = args.get("url"); 45 42 String title = args.get("title"); 46 43 String type = args.get("type"); 47 if((title == null) || (title.length() == 0)) 48 { 44 if ((title == null) || (title.length() == 0)) { 49 45 title = tr("Remote imagery"); 50 46 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandler.java
r5010 r5085 18 18 19 19 public static final String command = "import"; 20 public static final String permissionKey = "remotecontrol.permission.import";21 public static final boolean permissionDefault = true;22 20 23 21 @Override … … 34 32 35 33 @Override 36 public String[] getMandatoryParams() 37 { 38 return new String[] { "url" }; 34 public String[] getMandatoryParams() { 35 return new String[]{"url"}; 39 36 } 40 37 41 38 @Override 42 39 public String getPermissionMessage() { 43 return tr("Remote Control has been asked to import data from the following URL:") +44 "<br>" + request;40 return tr("Remote Control has been asked to import data from the following URL:") 41 + "<br>" + request; 45 42 } 46 43 47 44 @Override 48 public PermissionPrefWithDefault getPermissionPref() 49 { 50 return new PermissionPrefWithDefault(permissionKey, permissionDefault, 51 "RemoteControl: import forbidden by preferences"); 45 public PermissionPrefWithDefault getPermissionPref() { 46 return PermissionPrefWithDefault.IMPORT_DATA; 52 47 } 53 48 -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java
r4945 r5085 25 25 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 26 26 import org.openstreetmap.josm.io.remotecontrol.AddTagsDialog; 27 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; 27 28 import org.openstreetmap.josm.tools.Utils; 28 29 … … 34 35 public static final String command = "load_and_zoom"; 35 36 public static final String command2 = "zoom"; 36 37 public static final String loadDataPermissionKey = "remotecontrol.permission.load-data";38 public static final boolean loadDataPermissionDefault = true;39 public static final String changeSelectionPermissionKey = "remotecontrol.permission.change-selection";40 public static final boolean changeSelectionPermissionDefault = true;41 public static final String changeViewportPermissionKey = "remotecontrol.permission.change-viewport";42 public static final boolean changeViewportPermissionDefault = true;43 37 44 38 @Override … … 72 66 if(command.equals(myCommand)) 73 67 { 74 if (! Main.pref.getBoolean(loadDataPermissionKey, loadDataPermissionDefault))68 if (!PermissionPrefWithDefault.LOAD_DATA.isAllowed()) 75 69 { 76 70 System.out.println("RemoteControl: download forbidden by preferences"); … … 131 125 } 132 126 133 if (args.containsKey("select") && Main.pref.getBoolean(changeSelectionPermissionKey, changeSelectionPermissionDefault)) {127 if (args.containsKey("select") && PermissionPrefWithDefault.CHANGE_SELECTION.isAllowed()) { 134 128 // select objects after downloading, zoom to selection. 135 129 final String selection = args.get("select"); … … 172 166 } 173 167 ds.setSelected(newSel); 174 if ( Main.pref.getBoolean(changeViewportPermissionKey, changeViewportPermissionDefault)) {168 if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) { 175 169 AutoScaleAction.autoScale("selection"); 176 170 } … … 182 176 } 183 177 }); 184 } else if ( Main.pref.getBoolean(changeViewportPermissionKey, changeViewportPermissionDefault)) {178 } else if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) { 185 179 // after downloading, zoom to downloaded area. 186 180 zoom(minlat, maxlat, minlon, maxlon); … … 232 226 } 233 227 } 228 229 @Override 230 public PermissionPrefWithDefault getPermissionPref() { 231 return null; 232 } 234 233 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandler.java
r4883 r5085 5 5 import java.util.LinkedList; 6 6 import java.util.List; 7 import org.openstreetmap.josm.Main;8 7 import org.openstreetmap.josm.actions.DownloadPrimitiveAction; 9 8 import org.openstreetmap.josm.data.osm.PrimitiveId; 10 9 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 10 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; 11 11 12 12 /** … … 26 26 @Override 27 27 protected void handleRequest() throws RequestHandlerErrorException, RequestHandlerBadRequestException { 28 if (! Main.pref.getBoolean(LoadAndZoomHandler.loadDataPermissionKey, LoadAndZoomHandler.loadDataPermissionDefault)) {28 if (!PermissionPrefWithDefault.LOAD_DATA.isAllowed()) { 29 29 System.out.println("RemoteControl: download forbidden by preferences"); 30 30 } … … 42 42 return tr("Remote Control has been asked to load objects (specified by their id) from the API."); 43 43 } 44 45 @Override 46 public PermissionPrefWithDefault getPermissionPref() { 47 return PermissionPrefWithDefault.LOAD_DATA; 48 } 44 49 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandler.java
r5008 r5085 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.text.MessageFormat; 6 7 import java.util.HashMap; 7 8 import java.util.LinkedList; 8 9 import java.util.List; 9 import java.util.StringTokenizer;10 10 11 11 import javax.swing.JOptionPane; … … 50 50 public final void handle() throws RequestHandlerForbiddenException, RequestHandlerBadRequestException, RequestHandlerErrorException 51 51 { 52 checkMandatoryParams(); 52 53 checkPermission(); 53 checkMandatoryParams();54 54 handleRequest(); 55 55 } … … 86 86 * @return the preference name and error message or null 87 87 */ 88 public PermissionPrefWithDefault getPermissionPref() 89 { 90 /* Example: 91 return new PermissionPrefWithDefault("fooobar.remotecontrol", 92 true 93 "RemoteControl: foobar forbidden by preferences"); 94 */ 95 return null; 96 } 97 98 public String[] getMandatoryParams() { 99 return null; 100 } 88 abstract public PermissionPrefWithDefault getPermissionPref(); 89 90 abstract public String[] getMandatoryParams(); 101 91 102 92 /** … … 119 109 { 120 110 if (!Main.pref.getBoolean(permissionPref.pref, permissionPref.defaultVal)) { 121 System.out.println(permissionPref.message); 122 throw new RequestHandlerForbiddenException(); 111 String err = MessageFormat.format("RemoteControl: ''{0}'' forbidden by preferences", myCommand); 112 System.out.println(err); 113 throw new RequestHandlerForbiddenException(err); 123 114 } 124 115 } … … 133 124 tr("Confirm Remote Control action"), 134 125 JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) { 135 throw new RequestHandlerForbiddenException(); 126 String err = MessageFormat.format("RemoteControl: ''{0}'' forbidden by user''s choice", myCommand); 127 throw new RequestHandlerForbiddenException(err); 136 128 } 137 129 } … … 178 170 List<String> missingKeys = new LinkedList<String>(); 179 171 boolean error = false; 180 for (int i = 0; i < mandatory.length; ++i) { 181 String key = mandatory[i]; 172 for (String key : mandatory) { 182 173 String value = args.get(key); 183 174 if ((value == null) || (value.length() == 0)) { … … 243 234 public static class RequestHandlerForbiddenException extends RequestHandlerException { 244 235 private static final long serialVersionUID = 2263904699747115423L; 236 237 public RequestHandlerForbiddenException(String message) { 238 super(message); 239 } 245 240 } 246 241 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/VersionHandler.java
r3707 r5085 13 13 14 14 public static final String command = "version"; 15 public static final String permissionKey = "remotecontrol.permission.read-protocolversion";16 public static final boolean permissionDefault = true;17 15 18 16 @Override … … 22 20 contentType = "application/json"; 23 21 if (args.containsKey("jsonp")) { 24 content = args.get("jsonp") + " && " + args.get("jsonp") + "(" + content + ")";22 content = args.get("jsonp") + " && " + args.get("jsonp") + "(" + content + ")"; 25 23 } 26 24 } … … 32 30 33 31 @Override 34 public PermissionPrefWithDefault getPermissionPref() 35 { 36 return new PermissionPrefWithDefault(permissionKey, permissionDefault, 37 "RemoteControl: /version forbidden by preferences"); 32 public PermissionPrefWithDefault getPermissionPref() { 33 return PermissionPrefWithDefault.READ_PROTOCOL_VERSION; 34 } 35 36 @Override 37 public String[] getMandatoryParams() { 38 return null; 38 39 } 39 40 }
Note:
See TracChangeset
for help on using the changeset viewer.