Changeset 6474 in josm for trunk/src/org/openstreetmap/josm/tools
- Timestamp:
- 2013-12-16T00:22:44+01:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
r6453 r6474 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.tools; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.awt.HeadlessException; … … 15 17 public final class OsmUrlToBounds { 16 18 private static final String SHORTLINK_PREFIX = "http://osm.org/go/"; 17 19 18 20 private OsmUrlToBounds() { 19 21 // Hide default constructor for utils classes 20 22 } 21 23 22 public static Bounds parse(String url) { 24 public static Bounds parse(String url) throws IllegalArgumentException { 23 25 try { 24 26 // a percent sign indicates an encoded URL (RFC 1738). … … 86 88 * @param url string for parsing 87 89 * @return Bounds if hashurl, {@code null} otherwise 88 */ 89 private static Bounds parseHashURLs(String url) { 90 * @throws IllegalArgumentException if URL is invalid 91 */ 92 private static Bounds parseHashURLs(String url) throws IllegalArgumentException { 90 93 int startIndex = url.indexOf("#map="); 91 94 if (startIndex == -1) return null; 92 95 int endIndex = url.indexOf('&', startIndex); 93 96 if (endIndex == -1) endIndex = url.length(); 94 try { 95 String coordPart = url.substring(startIndex+5, endIndex); 96 String[] parts = coordPart.split("/"); 97 Bounds b = positionToBounds(Double.parseDouble(parts[1]), 98 Double.parseDouble(parts[2]), 99 Integer.parseInt(parts[0])); 100 return b; 101 } catch (Exception ex) { 102 Main.debug(ex.getMessage()); 103 return null; 104 } 97 String coordPart = url.substring(startIndex+5, endIndex); 98 String[] parts = coordPart.split("/"); 99 if (parts.length < 3) { 100 throw new IllegalArgumentException(tr("URL does not contain {0}/{1}/{2}", tr("zoom"), tr("latitude"), tr("longitude"))); 101 } 102 int zoom; 103 double lat, lon; 104 try { 105 zoom = Integer.parseInt(parts[0]); 106 } catch (NumberFormatException e) { 107 throw new IllegalArgumentException(tr("URL does not contain valid {0}", tr("zoom")), e); 108 } 109 try { 110 lat = Double.parseDouble(parts[1]); 111 } catch (NumberFormatException e) { 112 throw new IllegalArgumentException(tr("URL does not contain valid {0}", tr("latitude")), e); 113 } 114 try { 115 lon = Double.parseDouble(parts[2]); 116 } catch (NumberFormatException e) { 117 throw new IllegalArgumentException(tr("URL does not contain valid {0}", tr("longitude")), e); 118 } 119 return positionToBounds(lat, lon, zoom); 105 120 } 106 121
Note:
See TracChangeset
for help on using the changeset viewer.
