- Timestamp:
- 2013-01-27T19:11:23+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io/remotecontrol/handler
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddNodeHandler.java
r5085 r5680 11 11 import org.openstreetmap.josm.data.osm.Node; 12 12 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; 13 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; 13 14 14 15 /** … … 17 18 public class AddNodeHandler extends RequestHandler { 18 19 20 /** 21 * The remote control command name used to add a node. 22 */ 19 23 public static final String command = "add_node"; 24 25 private double lat; 26 private double lon; 20 27 21 28 @Override … … 32 39 @Override 33 40 public String getPermissionMessage() { 34 return tr("Remote Control has been asked to create a new node."); 41 return tr("Remote Control has been asked to create a new node.") + 42 "<br>" + tr("Coordinates: ") + args.get("lat") + ", " + args.get("lon"); 35 43 } 36 44 … … 47 55 48 56 // Parse the arguments 49 double lat = Double.parseDouble(args.get("lat"));50 double lon = Double.parseDouble(args.get("lon"));51 57 System.out.println("Adding node at (" + lat + ", " + lon + ")"); 52 58 … … 64 70 } 65 71 } 72 73 @Override 74 protected void validateRequest() throws RequestHandlerBadRequestException { 75 try { 76 lat = Double.parseDouble(args.get("lat")); 77 lon = Double.parseDouble(args.get("lon")); 78 } catch (NumberFormatException e) { 79 throw new RequestHandlerBadRequestException("NumberFormatException ("+e.getMessage()+")"); 80 } 81 } 66 82 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/AddWayHandler.java
r5085 r5680 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 4 5 import java.util.ArrayList; 6 import java.util.Arrays; 5 7 import java.util.LinkedList; 6 8 import java.util.List; 9 7 10 import org.openstreetmap.josm.Main; 8 11 import org.openstreetmap.josm.actions.AutoScaleAction; … … 14 17 import org.openstreetmap.josm.data.osm.Way; 15 18 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; 19 import org.openstreetmap.josm.io.remotecontrol.handler.RequestHandler.RequestHandlerBadRequestException; 16 20 17 21 /** … … 20 24 public class AddWayHandler extends RequestHandler { 21 25 26 /** 27 * The remote control command name used to add a way. 28 */ 22 29 public static final String command = "add_way"; 30 31 private final List<LatLon> allCoordinates = new ArrayList<LatLon>(); 23 32 24 33 @Override … … 31 40 Way way = new Way(); 32 41 List<Command> commands = new LinkedList<Command>(); 33 for (String coordinatesString : args.get("way").split(";\\s*")) { 34 String[] coordinates = coordinatesString.split(",\\s*", 2); 35 double lat = Double.parseDouble(coordinates[0]); 36 double lon = Double.parseDouble(coordinates[1]); 37 Node node = new Node(new LatLon(lat, lon)); 42 for (LatLon ll : allCoordinates) { 43 Node node = new Node(ll); 38 44 way.addNode(node); 39 45 commands.add(new AddCommand(node)); 40 46 } 47 allCoordinates.clear(); 41 48 commands.add(new AddCommand(way)); 42 49 Main.main.undoRedo.add(new SequenceCommand(tr("Add way"), commands)); … … 58 65 return PermissionPrefWithDefault.CREATE_OBJECTS; 59 66 } 67 68 @Override 69 protected void validateRequest() throws RequestHandlerBadRequestException { 70 allCoordinates.clear(); 71 for (String coordinatesString : args.get("way").split(";\\s*")) { 72 String[] coordinates = coordinatesString.split(",\\s*", 2); 73 if (coordinates.length < 2) { 74 throw new RequestHandlerBadRequestException( 75 tr("Invalid coordinates: {0}", Arrays.toString(coordinates))); 76 } 77 try { 78 double lat = Double.parseDouble(coordinates[0]); 79 double lon = Double.parseDouble(coordinates[1]); 80 allCoordinates.add(new LatLon(lat, lon)); 81 } catch (NumberFormatException e) { 82 throw new RequestHandlerBadRequestException("NumberFormatException ("+e.getMessage()+")"); 83 } 84 } 85 if (allCoordinates.isEmpty()) { 86 throw new RequestHandlerBadRequestException(tr("Empty ways")); 87 } else if (allCoordinates.size() == 1) { 88 throw new RequestHandlerBadRequestException(tr("One node ways")); 89 } 90 } 60 91 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandler.java
r5445 r5680 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.UnsupportedEncodingException;7 import java.net.URLDecoder;8 6 import java.util.HashMap; 9 7 … … 59 57 imgInfo.setDefaultMinZoom(Integer.parseInt(min_zoom)); 60 58 } catch (NumberFormatException e) { 61 System.err.println( e.getMessage());59 System.err.println("NumberFormatException ("+e.getMessage()+")"); 62 60 } 63 61 } … … 67 65 imgInfo.setDefaultMaxZoom(Integer.parseInt(max_zoom)); 68 66 } catch (NumberFormatException e) { 69 System.err.println( e.getMessage());67 System.err.println("NumberFormatException ("+e.getMessage()+")"); 70 68 } 71 69 } … … 102 100 } 103 101 104 private String decodeParam(String param) { 105 try { 106 return URLDecoder.decode(param, "UTF-8"); 107 } catch (UnsupportedEncodingException e) { 108 throw new RuntimeException(); 109 } 102 @Override 103 protected void validateRequest() throws RequestHandlerBadRequestException { 104 // Nothing to do 110 105 } 111 106 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandler.java
r5085 r5680 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.UnsupportedEncodingException;7 import java.net.URLDecoder;8 6 import java.util.HashMap; 9 7 … … 17 15 public class ImportHandler extends RequestHandler { 18 16 17 /** 18 * The remote control command name used to import data. 19 */ 19 20 public static final String command = "import"; 20 21 … … 39 40 public String getPermissionMessage() { 40 41 return tr("Remote Control has been asked to import data from the following URL:") 41 + "<br>" + request;42 + "<br>" + args.get("url"); 42 43 } 43 44 … … 53 54 String query = request.substring(request.indexOf('?') + 1); 54 55 if (query.indexOf("url=") == 0) { 55 args.put("url", decode URL(query.substring(4)));56 args.put("url", decodeParam(query.substring(4))); 56 57 } else { 57 58 int urlIdx = query.indexOf("&url="); 58 59 if (urlIdx != -1) { 59 String url =query.substring(urlIdx + 1);60 args.put("url", decode URL(query.substring(urlIdx + 5)));60 /*String url =*/ query.substring(urlIdx + 1); 61 args.put("url", decodeParam(query.substring(urlIdx + 5))); 61 62 query = query.substring(0, urlIdx); 62 63 } else { … … 77 78 } 78 79 79 private String decodeURL(String url) { 80 try { 81 return URLDecoder.decode(url, "UTF-8"); 82 } catch (UnsupportedEncodingException e) { 83 throw new RuntimeException(); 84 } 80 @Override 81 protected void validateRequest() throws RequestHandlerBadRequestException { 82 // Nothing to do 85 83 } 86 84 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadAndZoomHandler.java
r5668 r5680 20 20 import org.openstreetmap.josm.data.Bounds; 21 21 import org.openstreetmap.josm.data.coor.LatLon; 22 import org.openstreetmap.josm.data.osm.BBox; 22 23 import org.openstreetmap.josm.data.osm.DataSet; 23 24 import org.openstreetmap.josm.data.osm.Node; … … 35 36 public class LoadAndZoomHandler extends RequestHandler 36 37 { 38 /** 39 * The remote control command name used to load data and zoom. 40 */ 37 41 public static final String command = "load_and_zoom"; 42 43 /** 44 * The remote control command name used to zoom. 45 */ 38 46 public static final String command2 = "zoom"; 47 48 // Mandatory arguments 49 private double minlat; 50 private double maxlat; 51 private double minlon; 52 private double maxlon; 53 54 // Optional argument 'select' 55 private final Set<Long> ways = new HashSet<Long>(); 56 private final Set<Long> nodes = new HashSet<Long>(); 57 private final Set<Long> relations = new HashSet<Long>(); 39 58 40 59 @Override 41 60 public String getPermissionMessage() 42 61 { 43 return tr("Remote Control has been asked to load data from the API.") + 44 "<br>" + tr("Request details: {0}", request); 62 String msg = tr("Remote Control has been asked to load data from the API.") + 63 "<br>" + tr("Bounding box: ") + new BBox(minlon, minlat, maxlon, maxlat).toStringCSV(", "); 64 if (args.containsKey("select") && ways.size()+nodes.size()+relations.size() > 0) { 65 msg += "<br>" + tr("Sel.: Rel.:{0} / Ways:{1} / Nodes:{2}", relations.size(), ways.size(), nodes.size()); 66 } 67 return msg; 45 68 } 46 69 … … 55 78 { 56 79 DownloadTask osmTask = new DownloadOsmTask(); 57 double minlat = 0;58 double maxlat = 0;59 double minlon = 0;60 double maxlon = 0;61 80 try { 62 minlat = LatLon.roundToOsmPrecision(Double.parseDouble(args.get("bottom")));63 maxlat = LatLon.roundToOsmPrecision(Double.parseDouble(args.get("top")));64 minlon = LatLon.roundToOsmPrecision(Double.parseDouble(args.get("left")));65 maxlon = LatLon.roundToOsmPrecision(Double.parseDouble(args.get("right")));66 81 boolean newLayer = isLoadInNewLayer(); 67 82 … … 130 145 if (args.containsKey("select") && PermissionPrefWithDefault.CHANGE_SELECTION.isAllowed()) { 131 146 // select objects after downloading, zoom to selection. 132 final String selection = args.get("select"); 133 Main.worker.execute(new Runnable() { 134 public void run() { 135 HashSet<Long> ways = new HashSet<Long>(); 136 HashSet<Long> nodes = new HashSet<Long>(); 137 HashSet<Long> relations = new HashSet<Long>(); 147 Main.worker.execute(new Runnable() { 148 public void run() { 138 149 HashSet<OsmPrimitive> newSel = new HashSet<OsmPrimitive>(); 139 for (String item : selection.split(",")) {140 if (item.startsWith("way")) {141 ways.add(Long.parseLong(item.substring(3)));142 } else if (item.startsWith("node")) {143 nodes.add(Long.parseLong(item.substring(4)));144 } else if (item.startsWith("relation")) {145 relations.add(Long.parseLong(item.substring(8)));146 } else if (item.startsWith("rel")) {147 relations.add(Long.parseLong(item.substring(3)));148 } else {149 System.out.println("RemoteControl: invalid selection '"+item+"' ignored");150 }151 }152 150 DataSet ds = Main.main.getCurrentDataSet(); 153 151 if(ds == null) // e.g. download failed … … 158 156 } 159 157 } 158 ways.clear(); 160 159 for (Node n : ds.getNodes()) { 161 160 if (nodes.contains(n.getId())) { … … 163 162 } 164 163 } 164 nodes.clear(); 165 165 for (Relation r : ds.getRelations()) { 166 166 if (relations.contains(r.getId())) { … … 168 168 } 169 169 } 170 relations.clear(); 170 171 ds.setSelected(newSel); 171 172 if (PermissionPrefWithDefault.CHANGE_VIEWPORT.isAllowed()) { … … 190 191 191 192 addTags(args); 192 193 193 } 194 194 … … 245 245 return null; 246 246 } 247 248 @Override 249 protected void validateRequest() throws RequestHandlerBadRequestException { 250 // Process mandatory arguments 251 minlat = 0; 252 maxlat = 0; 253 minlon = 0; 254 maxlon = 0; 255 try { 256 minlat = LatLon.roundToOsmPrecision(Double.parseDouble(args.get("bottom"))); 257 maxlat = LatLon.roundToOsmPrecision(Double.parseDouble(args.get("top"))); 258 minlon = LatLon.roundToOsmPrecision(Double.parseDouble(args.get("left"))); 259 maxlon = LatLon.roundToOsmPrecision(Double.parseDouble(args.get("right"))); 260 } catch (NumberFormatException e) { 261 throw new RequestHandlerBadRequestException("NumberFormatException ("+e.getMessage()+")"); 262 } 263 264 // Process optional argument 'select' 265 if (args.containsKey("select")) { 266 ways.clear(); 267 nodes.clear(); 268 relations.clear(); 269 for (String item : args.get("select").split(",")) { 270 try { 271 if (item.startsWith("way")) { 272 ways.add(Long.parseLong(item.substring(3))); 273 } else if (item.startsWith("node")) { 274 nodes.add(Long.parseLong(item.substring(4))); 275 } else if (item.startsWith("relation")) { 276 relations.add(Long.parseLong(item.substring(8))); 277 } else if (item.startsWith("rel")) { 278 relations.add(Long.parseLong(item.substring(3))); 279 } else { 280 System.out.println("RemoteControl: invalid selection '"+item+"' ignored"); 281 } 282 } catch (NumberFormatException e) { 283 System.out.println("RemoteControl: invalid selection '"+item+"' ignored"); 284 } 285 } 286 } 287 } 247 288 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/LoadObjectHandler.java
r5116 r5680 18 18 public class LoadObjectHandler extends RequestHandler { 19 19 20 /** 21 * The remote control command name used to load objects using their ID. 22 */ 20 23 public static final String command = "load_object"; 24 25 private final List<PrimitiveId> ps = new LinkedList<PrimitiveId>(); 21 26 22 27 @Override … … 30 35 System.out.println("RemoteControl: download forbidden by preferences"); 31 36 } 32 final List<PrimitiveId> ps = new LinkedList<PrimitiveId>(); 33 for (String i : args.get("objects").split(",\\s*")) { 34 ps.add(SimplePrimitiveId.fromString(i)); 37 if (!ps.isEmpty()) { 38 boolean newLayer = isLoadInNewLayer(); 39 boolean relationMembers = Boolean.parseBoolean(args.get("relation_members")); 40 DownloadPrimitiveAction.processItems(newLayer, ps, true, relationMembers); 41 Main.worker.submit(new Runnable() { 42 43 @Override 44 public void run() { 45 Main.main.getCurrentDataSet().setSelected(ps); 46 LoadAndZoomHandler.addTags(args); 47 ps.clear(); 48 } 49 }); 35 50 } 36 boolean newLayer = isLoadInNewLayer();37 boolean relationMembers = Boolean.parseBoolean(args.get("relation_members"));38 DownloadPrimitiveAction.processItems(newLayer, ps, true, relationMembers);39 Main.worker.submit(new Runnable() {40 41 @Override42 public void run() {43 Main.main.getCurrentDataSet().setSelected(ps);44 LoadAndZoomHandler.addTags(args);45 }46 });47 51 } 48 52 … … 56 60 return PermissionPrefWithDefault.LOAD_DATA; 57 61 } 62 63 @Override 64 protected void validateRequest() throws RequestHandlerBadRequestException { 65 ps.clear(); 66 for (String i : args.get("objects").split(",\\s*")) { 67 try { 68 ps.add(SimplePrimitiveId.fromString(i)); 69 } catch (IllegalArgumentException e) { 70 System.out.println("RemoteControl: invalid selection '"+i+"' ignored"); 71 } 72 } 73 } 58 74 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/OpenFileHandler.java
r5085 r5680 7 7 import static org.openstreetmap.josm.tools.I18n.tr; 8 8 9 /** 10 * Opens a local file 11 */ 9 12 public class OpenFileHandler extends RequestHandler { 10 13 14 /** 15 * The remote control command name used to open a local file. 16 */ 11 17 public static final String command = "open_file"; 12 18 … … 30 36 return tr("Remote Control has been asked to open a local file."); 31 37 } 38 39 @Override 40 protected void validateRequest() throws RequestHandlerBadRequestException { 41 // Nothing to do 42 } 32 43 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandler.java
r5103 r5680 53 53 { 54 54 checkMandatoryParams(); 55 validateRequest(); 55 56 checkPermission(); 56 57 handleRequest(); 57 58 } 59 60 /** 61 * Validates the request before attempting to perform it. 62 * @throws RequestHandlerBadRequestException 63 * @since 5678 64 */ 65 protected abstract void validateRequest() throws RequestHandlerBadRequestException; 58 66 59 67 /** … … 219 227 } 220 228 229 protected final String decodeParam(String param) { 230 try { 231 return URLDecoder.decode(param, "UTF-8"); 232 } catch (UnsupportedEncodingException e) { 233 throw new RuntimeException(); 234 } 235 } 236 221 237 public static class RequestHandlerException extends Exception { 222 238 -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/VersionHandler.java
r5085 r5680 12 12 public class VersionHandler extends RequestHandler { 13 13 14 /** 15 * The remote control command name used to reply version. 16 */ 14 17 public static final String command = "version"; 15 18 … … 38 41 return null; 39 42 } 43 44 @Override 45 protected void validateRequest() throws RequestHandlerBadRequestException { 46 // Nothing to do 47 } 40 48 }
Note:
See TracChangeset
for help on using the changeset viewer.