Changeset 5010 in josm for trunk/src/org
- Timestamp:
- 2012-02-20T23:36:37+01:00 (13 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io/remotecontrol/handler
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImageryHandler.java
r4861 r5010 55 55 56 56 @Override 57 public void parseArgs() { 58 StringTokenizer st = new StringTokenizer(request, "&?"); 57 protected void parseArgs() { 59 58 HashMap<String, String> args = new HashMap<String, String>(); 60 // skip first element which is the command 61 if(st.hasMoreTokens()) { 62 st.nextToken(); 63 } 64 while (st.hasMoreTokens()) { 65 String param = st.nextToken(); 66 int eq = param.indexOf("="); 67 if (eq > -1) 68 { 69 String key = param.substring(0, eq); 70 /* "url=" terminates normal parameters 71 * and will be handled separately 72 */ 73 if("url".equals(key)) { 74 break; 59 if (request.indexOf('?') != -1) { 60 String query = request.substring(request.indexOf('?') + 1); 61 if (query.indexOf("url=") == 0) { 62 args.put("url", decodeURL(query.substring(4))); 63 } else { 64 int urlIdx = query.indexOf("&url="); 65 if (urlIdx != -1) { 66 String url = query.substring(urlIdx + 1); 67 args.put("url", decodeURL(query.substring(urlIdx + 5))); 68 query = query.substring(0, urlIdx); 69 } else { 70 if (query.indexOf('#') != -1) { 71 query = query.substring(0, query.indexOf('#')); 72 } 75 73 } 76 77 String value = param.substring(eq + 1); 78 // urldecode all normal values 79 try { 80 value = URLDecoder.decode(value, "UTF-8"); 81 } catch (UnsupportedEncodingException e) { 82 // TODO Auto-generated catch block 83 e.printStackTrace(); 84 } 85 args.put(key, 86 value); 87 } 88 } 89 // url as second or later parameter 90 int urlpos = request.indexOf("&url="); 91 // url as first (and only) parameter 92 if(urlpos < 0) { 93 urlpos = request.indexOf("?url="); 94 } 95 // url found? 96 if(urlpos >= 0) { 97 // URL value 98 String value = request.substring(urlpos + 5); 99 // allow skipping URL decoding with urldecode=false 100 String urldecode = args.get("urldecode"); 101 if((urldecode == null) || (Boolean.valueOf(urldecode) == true)) 102 { 103 try { 104 value = URLDecoder.decode(value, "UTF-8"); 105 } catch (UnsupportedEncodingException e) { 106 // TODO Auto-generated catch block 107 e.printStackTrace(); 74 String[] params = query.split("&", -1); 75 for (String param : params) { 76 int eq = param.indexOf('='); 77 if (eq != -1) { 78 args.put(param.substring(0, eq), param.substring(eq + 1)); 79 } 108 80 } 109 81 } 110 args.put("url", value);111 82 } 112 83 this.args = args; 113 84 } 85 86 private String decodeURL(String url) { 87 try { 88 return URLDecoder.decode(url, "UTF-8"); 89 } catch (UnsupportedEncodingException e) { 90 throw new RuntimeException(); 91 } 92 } 114 93 } -
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/ImportHandler.java
r4834 r5010 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.UnsupportedEncodingException; 6 7 import java.net.URLDecoder; 8 import java.util.HashMap; 7 9 8 10 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; … … 23 25 try { 24 26 DownloadTask osmTask = new DownloadOsmTask(); 25 osmTask.loadUrl(false, URLDecoder.decode(args.get("url"), "UTF-8"), null);27 osmTask.loadUrl(false, args.get("url"), null); 26 28 } catch (Exception ex) { 27 29 System.out.println("RemoteControl: Error parsing import remote control request:"); … … 49 51 "RemoteControl: import forbidden by preferences"); 50 52 } 53 54 @Override 55 protected void parseArgs() { 56 HashMap<String, String> args = new HashMap<String, String>(); 57 if (request.indexOf('?') != -1) { 58 String query = request.substring(request.indexOf('?') + 1); 59 if (query.indexOf("url=") == 0) { 60 args.put("url", decodeURL(query.substring(4))); 61 } else { 62 int urlIdx = query.indexOf("&url="); 63 if (urlIdx != -1) { 64 String url = query.substring(urlIdx + 1); 65 args.put("url", decodeURL(query.substring(urlIdx + 5))); 66 query = query.substring(0, urlIdx); 67 } else { 68 if (query.indexOf('#') != -1) { 69 query = query.substring(0, query.indexOf('#')); 70 } 71 } 72 String[] params = query.split("&", -1); 73 for (String param : params) { 74 int eq = param.indexOf('='); 75 if (eq != -1) { 76 args.put(param.substring(0, eq), param.substring(eq + 1)); 77 } 78 } 79 } 80 } 81 this.args = args; 82 } 83 84 private String decodeURL(String url) { 85 try { 86 return URLDecoder.decode(url, "UTF-8"); 87 } catch (UnsupportedEncodingException e) { 88 throw new RuntimeException(); 89 } 90 } 51 91 }
Note:
See TracChangeset
for help on using the changeset viewer.