From 4db2bf20294175048bf1124bc29143074d01c42b Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Sat, 8 Jun 2013 11:42:58 +0200 Subject: new: support for waymarking GPX files * Now one can load cache and waymark GPX together (as unknown caches) * I do not plan on adding any online features to the connector. * It is only there for creating the URLs for waymarks. --- main/src/cgeo/geocaching/files/GPXParser.java | 30 ++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) (limited to 'main/src/cgeo/geocaching/files/GPXParser.java') diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index 4150b87..8412207 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -296,11 +296,7 @@ public abstract class GPXParser extends FileParser { } } - if (StringUtils.isNotBlank(cache.getGeocode()) - && cache.getCoords() != null - && ((type == null && sym == null) - || StringUtils.contains(type, "geocache") - || StringUtils.contains(sym, "geocache"))) { + if (isValidForImport()) { fixCache(cache); cache.setListId(listId); cache.setDetailed(true); @@ -451,6 +447,17 @@ public abstract class GPXParser extends FileParser { } }); + // waypoint.urlname (name for waymarks) + waypoint.getChild(namespace, "urlname").setEndTextElementListener(new EndTextElementListener() { + + @Override + public void end(String urlName) { + if (cache.getName().equals(cache.getGeocode()) && StringUtils.startsWith(cache.getGeocode(), "WM")) { + cache.setName(StringUtils.trim(urlName)); + } + } + }); + // for GPX 1.0, cache info comes from waypoint node (so called private children, // for GPX 1.1 from extensions node final Element cacheParent = getCacheParent(waypoint); @@ -892,4 +899,17 @@ public abstract class GPXParser extends FileParser { } } } + + private boolean isValidForImport() { + if (StringUtils.isBlank(cache.getGeocode())) { + return false; + } + if (cache.getCoords() == null) { + return false; + } + return ((type == null && sym == null) + || StringUtils.contains(type, "geocache") + || StringUtils.contains(sym, "geocache") + || StringUtils.containsIgnoreCase(sym, "waymark")); + } } -- cgit v1.1