diff options
Diffstat (limited to 'main/src/cgeo/geocaching/files/GPXParser.java')
| -rw-r--r-- | main/src/cgeo/geocaching/files/GPXParser.java | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index e083f58..454c494 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -51,6 +51,7 @@ public abstract class GPXParser extends FileParser { */ private static final Pattern patternGeocode = Pattern.compile("([A-Z][0-9A-Z]+)"); private static final Pattern patternGuid = Pattern.compile(".*" + Pattern.quote("guid=") + "([0-9a-z\\-]+)", Pattern.CASE_INSENSITIVE); + private static final Pattern patternUrlGeocode = Pattern.compile(".*" + Pattern.quote("wp=") + "([A-Z][0-9A-Z]+)", Pattern.CASE_INSENSITIVE); /** * supported groundspeak extensions of the GPX format */ @@ -228,7 +229,7 @@ public abstract class GPXParser extends FileParser { static Date parseDate(String inputUntrimmed) throws ParseException { String input = inputUntrimmed.trim(); - // remove milli seconds to reduce number of needed patterns + // remove milliseconds to reduce number of needed patterns final Matcher matcher = PATTERN_MILLISECONDS.matcher(input); input = matcher.replaceFirst(""); if (input.contains("Z")) { @@ -254,8 +255,13 @@ public abstract class GPXParser extends FileParser { public void start(Attributes attrs) { try { if (attrs.getIndex("lat") > -1 && attrs.getIndex("lon") > -1) { - cache.setCoords(new Geopoint(Double.valueOf(attrs.getValue("lat")), - Double.valueOf(attrs.getValue("lon")))); + final String latitude = attrs.getValue("lat"); + final String longitude = attrs.getValue("lon"); + // latitude and longitude are required attributes, but we export them empty for waypoints without coordinates + if (StringUtils.isNotBlank(latitude) && StringUtils.isNotBlank(longitude)) { + cache.setCoords(new Geopoint(Double.valueOf(latitude), + Double.valueOf(longitude))); + } } } catch (Exception e) { Log.w("Failed to parse waypoint's latitude and/or longitude."); @@ -299,8 +305,7 @@ public abstract class GPXParser extends FileParser { result.put(key, cache); showProgressMessage(progressHandler, progressStream.getProgress()); } else if (StringUtils.isNotBlank(cache.getName()) - && cache.getCoords() != null - && StringUtils.contains(type, "waypoint")) { + && StringUtils.containsIgnoreCase(type, "waypoint")) { addWaypointToCache(); } @@ -422,6 +427,11 @@ public abstract class GPXParser extends FileParser { cache.setGuid(guid); } } + final Matcher matcherCode = patternUrlGeocode.matcher(url); + if (matcherCode.matches()) { + String geocode = matcherCode.group(1); + cache.setGeocode(geocode); + } } }); @@ -485,8 +495,17 @@ public abstract class GPXParser extends FileParser { gcCache.getChild(nsGC, "owner").setEndTextElementListener(new EndTextElementListener() { @Override - public void end(String cacheOwner) { - cache.setOwner(validate(cacheOwner)); + public void end(String ownerUserId) { + cache.setOwnerUserId(validate(ownerUserId)); + } + }); + + // waypoint.cache.getOwner() + gcCache.getChild(nsGC, "placed_by").setEndTextElementListener(new EndTextElementListener() { + + @Override + public void end(String ownerDisplayName) { + cache.setOwnerDisplayName(validate(ownerDisplayName)); } }); @@ -775,9 +794,17 @@ public abstract class GPXParser extends FileParser { return WaypointType.TRAILHEAD; } else if ("final location".equalsIgnoreCase(sym)) { return WaypointType.FINAL; - } else { - return WaypointType.WAYPOINT; } + // this is not fully correct, but lets also look for localized waypoint types + for (WaypointType waypointType : WaypointType.ALL_TYPES_EXCEPT_OWN) { + final String localized = waypointType.getL10n(); + if (StringUtils.isNotEmpty(localized)) { + if (localized.equalsIgnoreCase(sym)) { + return waypointType; + } + } + } + return WaypointType.WAYPOINT; } private void findGeoCode(final String input) { |
