- Timestamp:
- 2012-08-06T00:05:45+02:00 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/GpxReader.java
r5397 r5398 5 5 6 6 import static org.openstreetmap.josm.tools.I18n.tr; 7 import static org.openstreetmap.josm.tools.Utils.equal;8 7 9 8 import java.io.IOException; … … 32 31 33 32 /** 34 * Read a gpx file. Bounds are not read, as we caluclate them. @see GpxData.recalculateBounds() 33 * Read a gpx file. 34 * 35 * Bounds are not read, as we caluclate them. @see GpxData.recalculateBounds() 36 * Both GPX version 1.0 and 1.1 are supported. 37 * 35 38 * @author imi, ramack 36 39 */ 37 40 public class GpxReader { 38 // TODO: implement GPX 1.0 parsing39 41 40 42 private String version; … … 247 249 } else if (version.equals("1.0") && qName.equals("email")) { 248 250 currentData.attr.put(GpxData.META_AUTHOR_EMAIL, accumulator.toString()); 251 } else if (qName.equals("url") || qName.equals("urlname")) { 252 currentData.attr.put(qName, accumulator.toString()); 249 253 } else if ((currentState == State.metadata && qName.equals("metadata")) || 250 254 (currentState == State.gpx && qName.equals("gpx"))) { 255 convertUrlToLink(currentData.attr); 251 256 currentState = states.pop(); 252 257 } … … 296 301 case wpt: 297 302 if ( qName.equals("ele") || qName.equals("magvar") 298 || qName.equals("name") || qName.equals("geoidheight") 299 || qName.equals("type") || qName.equals("sym")) { 303 || qName.equals("name") || qName.equals("src") 304 || qName.equals("geoidheight") || qName.equals("type") 305 || qName.equals("sym") || qName.equals("url") 306 || qName.equals("urlname")) { 300 307 currentWayPoint.attr.put(qName, accumulator.toString()); 301 } else if(qName.equals("hdop") /*|| qName.equals("vdop") ||302 qName.equals("pdop") */) {308 } else if(qName.equals("hdop") || qName.equals("vdop") || 309 qName.equals("pdop")) { 303 310 try { 304 311 currentWayPoint.attr.put(qName, Float.parseFloat(accumulator.toString())); … … 314 321 } else if (qName.equals("rtept")) { 315 322 currentState = states.pop(); 323 convertUrlToLink(currentWayPoint.attr); 316 324 currentRoute.routePoints.add(currentWayPoint); 317 325 } else if (qName.equals("trkpt")) { 318 326 currentState = states.pop(); 327 convertUrlToLink(currentWayPoint.attr); 319 328 currentTrackSeg.add(currentWayPoint); 320 329 } else if (qName.equals("wpt")) { 321 330 currentState = states.pop(); 331 convertUrlToLink(currentWayPoint.attr); 322 332 currentData.waypoints.add(currentWayPoint); 323 333 } … … 332 342 if (qName.equals("trk")) { 333 343 currentState = states.pop(); 344 convertUrlToLink(currentTrackAttr); 334 345 currentData.tracks.add(new ImmutableGpxTrack(currentTrack, currentTrackAttr)); 335 346 } else if (qName.equals("name") || qName.equals("cmt") 336 347 || qName.equals("desc") || qName.equals("src") 337 348 || qName.equals("type") || qName.equals("number") 338 || qName.equals("url") ) {349 || qName.equals("url") || qName.equals("urlname")) { 339 350 currentTrackAttr.put(qName, accumulator.toString()); 340 351 } … … 350 361 } else if (qName.equals("rte")) { 351 362 currentState = states.pop(); 363 convertUrlToLink(currentRoute.attr); 352 364 currentData.routes.add(currentRoute); 353 365 } … … 359 371 throw new SAXException(tr("Parse error: invalid document structure for GPX document.")); 360 372 data = currentData; 373 } 374 375 /** 376 * convert url/urlname to link element (GPX 1.0 -> GPX 1.1). 377 */ 378 private void convertUrlToLink(Map<String, Object> attr) { 379 String url = (String) attr.get("url"); 380 String urlname = (String) attr.get("urlname"); 381 if (url != null) { 382 if (!attr.containsKey(GpxData.META_LINKS)) { 383 attr.put(GpxData.META_LINKS, new LinkedList<GpxLink>()); 384 } 385 GpxLink link = new GpxLink(url); 386 link.text = urlname; 387 ((Collection<GpxLink>) attr.get(GpxData.META_LINKS)).add(link); 388 } 361 389 } 362 390
Note:
See TracChangeset
for help on using the changeset viewer.