Changeset 8193 in josm
- Timestamp:
- 2015-04-14T22:37:51+02:00 (9 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandler.java
r7999 r8193 5 5 6 6 import java.util.Arrays; 7 import java.util.HashMap;8 7 9 8 import org.openstreetmap.josm.Main; … … 20 19 * @since 3715 21 20 */ 22 public class ImageryHandler extends RequestHandler {21 public class ImageryHandler extends RequestHandler.RawURLParseRequestHandler { 23 22 24 23 /** … … 116 115 117 116 @Override 118 protected void parseArgs() {119 HashMap<String, String> args = new HashMap<>();120 if (request.indexOf('?') != -1) {121 String query = request.substring(request.indexOf('?') + 1);122 if (query.indexOf("url=") == 0) {123 args.put("url", decodeParam(query.substring(4)));124 } else {125 int urlIdx = query.indexOf("&url=");126 if (urlIdx != -1) {127 args.put("url", decodeParam(query.substring(urlIdx + 5)));128 query = query.substring(0, urlIdx);129 } else if (query.indexOf('#') != -1) {130 query = query.substring(0, query.indexOf('#'));131 }132 String[] params = query.split("&", -1);133 for (String param : params) {134 int eq = param.indexOf('=');135 if (eq != -1) {136 args.put(param.substring(0, eq), decodeParam(param.substring(eq + 1)));137 }138 }139 }140 }141 this.args = args;142 }143 144 @Override145 117 protected void validateRequest() throws RequestHandlerBadRequestException { 146 118 String url = args.get("url"); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandler.java
r7937 r8193 7 7 import java.net.URL; 8 8 import java.util.Collection; 9 import java.util.HashMap;10 9 11 10 import org.openstreetmap.josm.Main; … … 18 17 * Handler for import request 19 18 */ 20 public class ImportHandler extends RequestHandler {19 public class ImportHandler extends RequestHandler.RawURLParseRequestHandler { 21 20 22 21 /** … … 84 83 85 84 @Override 86 protected void parseArgs() {87 HashMap<String, String> args = new HashMap<>();88 if (request.indexOf('?') != -1) {89 String query = request.substring(request.indexOf('?') + 1);90 if (query.indexOf("url=") == 0) {91 args.put("url", decodeParam(query.substring(4)));92 } else {93 int urlIdx = query.indexOf("&url=");94 if (urlIdx != -1) {95 args.put("url", decodeParam(query.substring(urlIdx + 5)));96 query = query.substring(0, urlIdx);97 } else {98 if (query.indexOf('#') != -1) {99 query = query.substring(0, query.indexOf('#'));100 }101 }102 String[] params = query.split("&", -1);103 for (String param : params) {104 int eq = param.indexOf('=');105 if (eq != -1) {106 args.put(param.substring(0, eq), param.substring(eq + 1));107 }108 }109 }110 }111 this.args = args;112 }113 114 @Override115 85 protected void validateRequest() throws RequestHandlerBadRequestException { 116 86 String urlString = args.get("url"); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandler.java
r7937 r8193 2 2 package org.openstreetmap.josm.io.remotecontrol.handler; 3 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 4 import org.openstreetmap.josm.Main; 5 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; 6 import org.openstreetmap.josm.tools.Utils; 7 8 import javax.swing.JLabel; 9 import javax.swing.JOptionPane; 6 10 import java.io.UnsupportedEncodingException; 11 import java.net.URI; 12 import java.net.URISyntaxException; 7 13 import java.net.URLDecoder; 8 14 import java.text.MessageFormat; … … 14 20 import java.util.Map; 15 21 16 import javax.swing.JLabel; 17 import javax.swing.JOptionPane; 18 19 import org.openstreetmap.josm.Main; 20 import org.openstreetmap.josm.io.remotecontrol.PermissionPrefWithDefault; 21 import org.openstreetmap.josm.tools.Utils; 22 import static org.openstreetmap.josm.tools.I18n.tr; 22 23 23 24 /** … … 193 194 protected void parseArgs() { 194 195 try { 195 String req = URLDecoder.decode(this.request, "UTF-8"); 196 HashMap<String, String> args = new HashMap<>(); 197 if (req.indexOf('?') != -1) { 198 String query = req.substring(req.indexOf('?') + 1); 199 if (query.indexOf('#') != -1) { 200 query = query.substring(0, query.indexOf('#')); 201 } 202 String[] params = query.split("&", -1); 203 for (String param : params) { 204 int eq = param.indexOf('='); 205 if (eq != -1) { 206 args.put(param.substring(0, eq), param.substring(eq + 1)); 207 } 208 } 209 } 210 this.args = args; 211 } catch (UnsupportedEncodingException ex) { 212 throw new IllegalStateException(ex); 213 } 196 this.args = getRequestParameter(new URI(this.request)); 197 } catch (URISyntaxException ex) { 198 throw new RuntimeException(ex); 199 } 200 } 201 202 /** 203 * @see <a href="http://blog.lunatech.com/2009/02/03/what-every-web-developer-must-know-about-url-encoding"> 204 * What every web developer must know about URL encoding</a> 205 */ 206 static Map<String, String> getRequestParameter(URI uri) { 207 Map<String, String> r = new HashMap<>(); 208 if (uri.getRawQuery() == null) { 209 return r; 210 } 211 for (String kv : uri.getRawQuery().split("&")) { 212 try { 213 final String[] kvs = URLDecoder.decode(kv, "UTF-8").split("=", 2); 214 r.put(kvs[0], kvs.length > 1 ? kvs[1] : null); 215 } catch (UnsupportedEncodingException ex) { 216 throw new IllegalStateException(ex); 217 } 218 } 219 return r; 214 220 } 215 221 … … 269 275 } 270 276 271 protected finalString decodeParam(String param) {277 protected static String decodeParam(String param) { 272 278 try { 273 279 return URLDecoder.decode(param, "UTF-8"); … … 319 325 } 320 326 } 327 328 public static abstract class RawURLParseRequestHandler extends RequestHandler { 329 @Override 330 protected void parseArgs() { 331 HashMap<String, String> args = new HashMap<>(); 332 if (request.indexOf('?') != -1) { 333 String query = request.substring(request.indexOf('?') + 1); 334 if (query.indexOf("url=") == 0) { 335 args.put("url", decodeParam(query.substring(4))); 336 } else { 337 int urlIdx = query.indexOf("&url="); 338 if (urlIdx != -1) { 339 args.put("url", decodeParam(query.substring(urlIdx + 5))); 340 query = query.substring(0, urlIdx); 341 } else if (query.indexOf('#') != -1) { 342 query = query.substring(0, query.indexOf('#')); 343 } 344 String[] params = query.split("&", -1); 345 for (String param : params) { 346 int eq = param.indexOf('='); 347 if (eq != -1) { 348 args.put(param.substring(0, eq), decodeParam(param.substring(eq + 1))); 349 } 350 } 351 } 352 } 353 this.args = args; 354 } 355 } 321 356 }
Note:
See TracChangeset
for help on using the changeset viewer.