diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2011-11-01 22:02:31 +0100 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2011-11-01 22:02:31 +0100 |
| commit | e2be3a453815fd8519be5f12914656dd1fc29112 (patch) | |
| tree | 6b4ab398674b12e6203f52cd9ee4a1138cd4dbef /main/src/cgeo/geocaching/files/GPXParser.java | |
| parent | 8579c883dbc8c1aea42483b943a1bc79b4d645d8 (diff) | |
| download | cgeo-e2be3a453815fd8519be5f12914656dd1fc29112.zip cgeo-e2be3a453815fd8519be5f12914656dd1fc29112.tar.gz cgeo-e2be3a453815fd8519be5f12914656dd1fc29112.tar.bz2 | |
new: import caches from unknown source, fixes #720
Diffstat (limited to 'main/src/cgeo/geocaching/files/GPXParser.java')
| -rw-r--r-- | main/src/cgeo/geocaching/files/GPXParser.java | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index 01929c6..c1cc1a3 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -260,12 +260,18 @@ public abstract class GPXParser extends FileParser { @Override public void end() { + // try to find geocode somewhere else if (StringUtils.isBlank(cache.getGeocode())) { - // try to find geocode somewhere else findGeoCode(name); findGeoCode(desc); findGeoCode(cmt); } + // take the name as code, if nothing else is available + if (StringUtils.isBlank(cache.getGeocode())) { + if (StringUtils.isNotBlank(name)) { + cache.setGeocode(name.trim()); + } + } if (StringUtils.isNotBlank(cache.getGeocode()) && cache.getCoords() != null @@ -772,11 +778,15 @@ public abstract class GPXParser extends FileParser { if (input == null || StringUtils.isNotBlank(cache.getGeocode())) { return; } - final Matcher matcherGeocode = patternGeocode.matcher(input); + final String trimmed = input.trim(); + final Matcher matcherGeocode = patternGeocode.matcher(trimmed); if (matcherGeocode.find()) { final String geocode = matcherGeocode.group(1); - if (ConnectorFactory.canHandle(geocode)) { - cache.setGeocode(geocode); + // a geocode should not be part of a word + if (geocode.length() == trimmed.length() || Character.isWhitespace(trimmed.charAt(geocode.length()))) { + if (ConnectorFactory.canHandle(geocode)) { + cache.setGeocode(geocode); + } } } } |
