Changeset 9128 in josm
- Timestamp:
- 2015-12-15T11:03:09+01:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java
r9125 r9128 190 190 85.05112877980659, 180.0, true); 191 191 } else { 192 Map<String, String> parameters = parseParameterList(pref); 192 Map<String, String> parameters = parseParameterList(pref, false); 193 parameters = resolveInits(parameters, false); 193 194 ellps = parseEllipsoid(parameters); 194 195 datum = parseDatum(parameters, ellps); … … 267 268 } 268 269 269 private Map<String, String> parseParameterList(String pref) throws ProjectionConfigurationException { 270 /** 271 * Parse a parameter list to key=value pairs. 272 * 273 * @param pref the parameter list 274 * @param ignoreUnknownParameter true, if unknown parameter should not raise exception 275 * @return parameters map 276 * @throws ProjectionConfigurationException 277 */ 278 public static Map<String, String> parseParameterList(String pref, boolean ignoreUnknownParameter) throws ProjectionConfigurationException { 270 279 Map<String, String> parameters = new HashMap<>(); 271 280 String[] parts = Utils.WHITE_SPACES_PATTERN.split(pref.trim()); … … 293 302 } 294 303 } 295 if (!Param.paramsByKey.containsKey(key)) 296 throw new ProjectionConfigurationException(tr("Unknown parameter: ''{0}''.", key)); 297 if (Param.paramsByKey.get(key).hasValue && value == null) 298 throw new ProjectionConfigurationException(tr("Value expected for parameter ''{0}''.", key)); 299 if (!Param.paramsByKey.get(key).hasValue && value != null) 300 throw new ProjectionConfigurationException(tr("No value expected for parameter ''{0}''.", key)); 304 if (!Param.paramsByKey.containsKey(key)) { 305 if (!ignoreUnknownParameter) 306 throw new ProjectionConfigurationException(tr("Unknown parameter: ''{0}''.", key)); 307 } else { 308 if (Param.paramsByKey.get(key).hasValue && value == null) 309 throw new ProjectionConfigurationException(tr("Value expected for parameter ''{0}''.", key)); 310 if (!Param.paramsByKey.get(key).hasValue && value != null) 311 throw new ProjectionConfigurationException(tr("No value expected for parameter ''{0}''.", key)); 312 } 301 313 parameters.put(key, value); 302 314 } else 303 315 throw new ProjectionConfigurationException(tr("Unexpected parameter format (''{0}'')", part)); 304 316 } 317 return parameters; 318 } 319 320 /** 321 * Recursive resolution of +init includes. 322 * 323 * @param parameters parameters map 324 * @param ignoreUnknownParameter true, if unknown parameter should not raise exception 325 * @return parameters map with +init includes resolved 326 * @throws ProjectionConfigurationException 327 */ 328 public static Map<String, String> resolveInits(Map<String, String> parameters , boolean ignoreUnknownParameter) throws ProjectionConfigurationException { 305 329 // recursive resolution of +init includes 306 330 String initKey = parameters.get(Param.init.key); … … 309 333 if (init == null) 310 334 throw new ProjectionConfigurationException(tr("Value ''{0}'' for option +init not supported.", initKey)); 311 Map<String, String> initp = null;335 Map<String, String> initp; 312 336 try { 313 initp = parseParameterList(init); 337 initp = parseParameterList(init, ignoreUnknownParameter); 338 initp = resolveInits(initp, ignoreUnknownParameter); 314 339 } catch (ProjectionConfigurationException ex) { 315 throw new ProjectionConfigurationException(tr(initKey+": "+ex.getMessage()), ex); 316 } 317 for (Map.Entry<String, String> e : parameters.entrySet()) { 318 initp.put(e.getKey(), e.getValue()); 319 } 340 throw new ProjectionConfigurationException(initKey+": "+ex.getMessage(), ex); 341 } 342 initp.putAll(parameters); 320 343 return initp; 321 344 }
Note:
See TracChangeset
for help on using the changeset viewer.