diff options
Diffstat (limited to 'main/src/cgeo/geocaching/files/GPXParser.java')
| -rw-r--r-- | main/src/cgeo/geocaching/files/GPXParser.java | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index b9d3f53..2ac19bb 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -4,6 +4,7 @@ import cgeo.geocaching.LogEntry; import cgeo.geocaching.R; import cgeo.geocaching.StoredList; import cgeo.geocaching.cgCache; +import cgeo.geocaching.cgData; import cgeo.geocaching.cgTrackable; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.cgeoapplication; @@ -287,7 +288,7 @@ public abstract class GPXParser extends FileParser { // take the name as code, if nothing else is available if (StringUtils.isBlank(cache.getGeocode())) { if (StringUtils.isNotBlank(name)) { - cache.setGeocode(name.trim().toUpperCase()); + cache.setGeocode(name.trim()); } } @@ -311,8 +312,8 @@ public abstract class GPXParser extends FileParser { // finally store the cache in the database result.add(geocode); - cgeoapplication.getInstance().saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB)); - cgeoapplication.getInstance().removeAllFromCache(); + cgData.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB)); + cgData.removeAllFromCache(); showProgressMessage(progressHandler, progressStream.getProgress()); } else if (StringUtils.isNotBlank(cache.getName()) && StringUtils.containsIgnoreCase(type, "waypoint")) { @@ -326,10 +327,9 @@ public abstract class GPXParser extends FileParser { fixCache(cache); if (cache.getName().length() > 2) { - final String cacheGeocodeForWaypoint = "GC" + cache.getName().substring(2).toUpperCase(); - + final String cacheGeocodeForWaypoint = "GC" + cache.getName().substring(2).toUpperCase(Locale.US); // lookup cache for waypoint in already parsed caches - final cgCache cacheForWaypoint = cgeoapplication.getInstance().loadCache(cacheGeocodeForWaypoint, LoadFlags.LOAD_CACHE_OR_DB); + final cgCache cacheForWaypoint = cgData.loadCache(cacheGeocodeForWaypoint, LoadFlags.LOAD_CACHE_OR_DB); if (cacheForWaypoint != null) { final cgWaypoint waypoint = new cgWaypoint(cache.getShortdesc(), convertWaypointSym2Type(sym), false); waypoint.setId(-1); @@ -347,7 +347,7 @@ public abstract class GPXParser extends FileParser { newPoints.add(waypoint); cgWaypoint.mergeWayPoints(newPoints, mergedWayPoints, true); cacheForWaypoint.setWaypoints(newPoints, false); - cgeoapplication.getInstance().saveCache(cacheForWaypoint, EnumSet.of(SaveFlag.SAVE_DB)); + cgData.saveCache(cacheForWaypoint, EnumSet.of(SaveFlag.SAVE_DB)); showProgressMessage(progressHandler, progressStream.getProgress()); } } @@ -410,7 +410,7 @@ public abstract class GPXParser extends FileParser { public void end(String body) { final String[] content = body.split("\\|"); if (content.length > 0) { - type = content[0].toLowerCase().trim(); + type = content[0].toLowerCase(Locale.US).trim(); } } }); @@ -420,7 +420,7 @@ public abstract class GPXParser extends FileParser { @Override public void end(final String body) { - sym = body.toLowerCase(); + sym = body.toLowerCase(Locale.US); if (sym.contains("geocache") && sym.contains("found")) { cache.setFound(true); } @@ -526,7 +526,7 @@ public abstract class GPXParser extends FileParser { @Override public void end(String body) { - cache.setType(CacheType.getByPattern(validate(body.toLowerCase()))); + cache.setType(CacheType.getByPattern(validate(body))); } }); @@ -535,7 +535,7 @@ public abstract class GPXParser extends FileParser { @Override public void end(String body) { - cache.setSize(CacheSize.getById(validate(body.toLowerCase()))); + cache.setSize(CacheSize.getById(validate(body))); } }); @@ -665,7 +665,7 @@ public abstract class GPXParser extends FileParser { try { if (attrs.getIndex("ref") > -1) { - trackable.setGeocode(attrs.getValue("ref").toUpperCase()); + trackable.setGeocode(attrs.getValue("ref")); } } catch (Exception e) { // nothing @@ -745,7 +745,7 @@ public abstract class GPXParser extends FileParser { @Override public void end(String body) { - final String logType = validate(body).toLowerCase(); + final String logType = validate(body); log.type = LogType.getByType(logType); } }); @@ -772,9 +772,9 @@ public abstract class GPXParser extends FileParser { try { progressStream = new ProgressInputStream(stream); Xml.parse(progressStream, Xml.Encoding.UTF_8, root.getContentHandler()); - return cgeoapplication.getInstance().loadCaches(result, EnumSet.of(LoadFlag.LOAD_DB_MINIMAL)); + return cgData.loadCaches(result, EnumSet.of(LoadFlag.LOAD_DB_MINIMAL)); } catch (SAXException e) { - Log.e("Cannot parse .gpx file as GPX " + version + ": could not parse XML - " + e.toString()); + Log.w("Cannot parse .gpx file as GPX " + version + ": could not parse XML - " + e.toString()); throw new ParserException("Cannot parse .gpx file as GPX " + version + ": could not parse XML", e); } } @@ -806,17 +806,21 @@ public abstract class GPXParser extends FileParser { static WaypointType convertWaypointSym2Type(final String sym) { if ("parking area".equalsIgnoreCase(sym)) { return WaypointType.PARKING; - } else if ("stages of a multicache".equalsIgnoreCase(sym)) { + } + if ("stages of a multicache".equalsIgnoreCase(sym)) { return WaypointType.STAGE; - } else if ("question to answer".equalsIgnoreCase(sym)) { + } + if ("question to answer".equalsIgnoreCase(sym)) { return WaypointType.PUZZLE; - } else if ("trailhead".equalsIgnoreCase(sym)) { + } + if ("trailhead".equalsIgnoreCase(sym)) { return WaypointType.TRAILHEAD; - } else if ("final location".equalsIgnoreCase(sym)) { + } + if ("final location".equalsIgnoreCase(sym)) { return WaypointType.FINAL; } // this is not fully correct, but lets also look for localized waypoint types - for (WaypointType waypointType : WaypointType.ALL_TYPES_EXCEPT_OWN) { + for (WaypointType waypointType : WaypointType.ALL_TYPES_EXCEPT_OWN_AND_ORIGINAL) { final String localized = waypointType.getL10n(); if (StringUtils.isNotEmpty(localized)) { if (localized.equalsIgnoreCase(sym)) { |
