aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/files/GPXParser.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/files/GPXParser.java')
-rw-r--r--main/src/cgeo/geocaching/files/GPXParser.java31
1 files changed, 28 insertions, 3 deletions
diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java
index 3e96291..d26a48c 100644
--- a/main/src/cgeo/geocaching/files/GPXParser.java
+++ b/main/src/cgeo/geocaching/files/GPXParser.java
@@ -104,6 +104,10 @@ public abstract class GPXParser extends FileParser {
*/
private final Set<String> result = new HashSet<String>(100);
private ProgressInputStream progressStream;
+ /**
+ * URL contained in the header of the GPX file. Used to guess where the file is coming from.
+ */
+ protected String scriptUrl;
private final class UserDataListener implements EndTextElementListener {
private final int index;
@@ -265,6 +269,14 @@ public abstract class GPXParser extends FileParser {
final RootElement root = new RootElement(namespace, "gpx");
final Element waypoint = root.getChild(namespace, "wpt");
+ root.getChild(namespace, "url").setEndTextElementListener(new EndTextElementListener() {
+
+ @Override
+ public void end(String body) {
+ scriptUrl = body;
+ }
+ });
+
// waypoint - attributes
waypoint.setStartElementListener(new StartElementListener() {
@@ -338,7 +350,12 @@ public abstract class GPXParser extends FileParser {
if (cache.getName().length() > 2 || StringUtils.isNotBlank(parentCacheCode)) {
if (StringUtils.isBlank(parentCacheCode)) {
- parentCacheCode = "GC" + cache.getName().substring(2).toUpperCase(Locale.US);
+ if (StringUtils.containsIgnoreCase(scriptUrl, "extremcaching")) {
+ parentCacheCode = cache.getName().substring(2);
+ }
+ else {
+ parentCacheCode = "GC" + cache.getName().substring(2).toUpperCase(Locale.US);
+ }
}
// lookup cache for waypoint in already parsed caches
final Geocache cacheForWaypoint = DataStore.loadCache(parentCacheCode, LoadFlags.LOAD_CACHE_OR_DB);
@@ -382,14 +399,19 @@ public abstract class GPXParser extends FileParser {
}
});
- // waypoint.getName()
+ // waypoint.name
waypoint.getChild(namespace, "name").setEndTextElementListener(new EndTextElementListener() {
@Override
public void end(String body) {
name = body;
- final String content = body.trim();
+ String content = body.trim();
+
+ // extremcaching.com manipulates the GC code by adding GC in front of ECxxx
+ if (StringUtils.startsWithIgnoreCase(content, "GCEC") && StringUtils.containsIgnoreCase(scriptUrl, "extremcaching")) {
+ content = content.substring(2);
+ }
cache.setName(content);
findGeoCode(cache.getName());
@@ -834,6 +856,9 @@ public abstract class GPXParser extends FileParser {
}
/**
+ * Overwrite this method in a GPX parser sub class to modify the {@link Geocache}, after it has been fully parsed
+ * from the GPX file and before it gets stored.
+ *
* @param cache
* currently imported cache
*/