diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2012-03-20 19:51:02 +0100 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2012-03-20 19:51:02 +0100 |
commit | 02f1ba2c07ec824e9d8df04908ecb2cde1ab3644 (patch) | |
tree | a44656e580be1e56be3a924007b3beceb5c2bade /main/src/cgeo | |
parent | 7212666e3ca6f7f84e3a00388fd221ad59073dd2 (diff) | |
download | cgeo-02f1ba2c07ec824e9d8df04908ecb2cde1ab3644.zip cgeo-02f1ba2c07ec824e9d8df04908ecb2cde1ab3644.tar.gz cgeo-02f1ba2c07ec824e9d8df04908ecb2cde1ab3644.tar.bz2 |
fix #1281: .gpx import fails to recognize most caches in TX Challenge
package
Diffstat (limited to 'main/src/cgeo')
-rw-r--r-- | main/src/cgeo/geocaching/files/GPXParser.java | 38 |
1 files changed, 25 insertions, 13 deletions
diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index 10f3fa8..579c080 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -47,7 +47,10 @@ public abstract class GPXParser extends FileParser { private static final SimpleDateFormat formatSimpleZ = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'"); // 2010-04-20T07:00:00Z private static final SimpleDateFormat formatTimezone = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); // 2010-04-20T01:01:03-04:00 - private static final Pattern patternGeocode = Pattern.compile("([A-Z]{2}[0-9A-Z]+)", Pattern.CASE_INSENSITIVE); + /** + * Attention: case sensitive geocode pattern to avoid matching normal words in the name or description of the cache. + */ + 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); /** * supported groundspeak extensions of the GPX format @@ -61,7 +64,10 @@ public abstract class GPXParser extends FileParser { /** * supported GSAK extension of the GPX format */ - private static final String GSAK_NS = "http://www.gsak.net/xmlv1/5"; + private static final String[] GSAK_NS = new String[] { + "http://www.gsak.net/xmlv1/5", + "http://www.gsak.net/xmlv1/6" + }; private static final Pattern PATTERN_MILLISECONDS = Pattern.compile("\\.\\d{3,7}"); @@ -287,7 +293,11 @@ public abstract class GPXParser extends FileParser { createNoteFromGSAKUserdata(); - result.put(cache.getGeocode(), cache); + final String key = cache.getGeocode(); + if (result.containsKey(key)) { + Log.w(Settings.tag, "Duplicate geocode during GPX import: " + key); + } + result.put(key, cache); showProgressMessage(progressHandler, progressStream.getProgress()); } else if (StringUtils.isNotBlank(cache.getName()) && cache.getCoords() != null @@ -421,19 +431,21 @@ public abstract class GPXParser extends FileParser { final Element cacheParent = getCacheParent(waypoint); // GSAK extensions - final Element gsak = cacheParent.getChild(GSAK_NS, "wptExtension"); - gsak.getChild(GSAK_NS, "Watch").setEndTextElementListener(new EndTextElementListener() { + for (String gsakNamespace : GSAK_NS) { + final Element gsak = cacheParent.getChild(gsakNamespace, "wptExtension"); + gsak.getChild(gsakNamespace, "Watch").setEndTextElementListener(new EndTextElementListener() { - @Override - public void end(String watchList) { - cache.setOnWatchlist(Boolean.valueOf(watchList.trim()).booleanValue()); - } - }); + @Override + public void end(String watchList) { + cache.setOnWatchlist(Boolean.valueOf(watchList.trim()).booleanValue()); + } + }); - gsak.getChild(GSAK_NS, "UserData").setEndTextElementListener(new UserDataListener(1)); + gsak.getChild(gsakNamespace, "UserData").setEndTextElementListener(new UserDataListener(1)); - for (int i = 2; i <= 4; i++) { - gsak.getChild(GSAK_NS, "User" + i).setEndTextElementListener(new UserDataListener(i)); + for (int i = 2; i <= 4; i++) { + gsak.getChild(gsakNamespace, "User" + i).setEndTextElementListener(new UserDataListener(i)); + } } // 3 different versions of the GC schema |