From e2be3a453815fd8519be5f12914656dd1fc29112 Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Tue, 1 Nov 2011 22:02:31 +0100 Subject: new: import caches from unknown source, fixes #720 --- main/src/cgeo/geocaching/files/GPXParser.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 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 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); + } } } } -- cgit v1.1