diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2013-06-08 11:42:58 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2013-06-08 11:42:58 +0200 |
| commit | 4db2bf20294175048bf1124bc29143074d01c42b (patch) | |
| tree | 0e2428604c2793213f9fcc0e1932cb43b2361f4a /main | |
| parent | 934945bddf33ec77ee77daff1add6498fe08e400 (diff) | |
| download | cgeo-4db2bf20294175048bf1124bc29143074d01c42b.zip cgeo-4db2bf20294175048bf1124bc29143074d01c42b.tar.gz cgeo-4db2bf20294175048bf1124bc29143074d01c42b.tar.bz2 | |
new: support for waymarking GPX files
* Now one can load cache and waymark GPX together (as unknown caches)
* I do not plan on adding any online features to the connector.
* It is only there for creating the URLs for waymarks.
Diffstat (limited to 'main')
| -rw-r--r-- | main/src/cgeo/geocaching/connector/ConnectorFactory.java | 1 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/WaymarkingConnector.java | 40 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/files/GPXParser.java | 30 |
3 files changed, 66 insertions, 5 deletions
diff --git a/main/src/cgeo/geocaching/connector/ConnectorFactory.java b/main/src/cgeo/geocaching/connector/ConnectorFactory.java index f63e390..3319fe4 100644 --- a/main/src/cgeo/geocaching/connector/ConnectorFactory.java +++ b/main/src/cgeo/geocaching/connector/ConnectorFactory.java @@ -36,6 +36,7 @@ public final class ConnectorFactory { new OXConnector(), new GeocachingAustraliaConnector(), new GeopeitusConnector(), + new WaymarkingConnector(), UNKNOWN_CONNECTOR // the unknown connector MUST be the last one }; diff --git a/main/src/cgeo/geocaching/connector/WaymarkingConnector.java b/main/src/cgeo/geocaching/connector/WaymarkingConnector.java new file mode 100644 index 0000000..f184f6e --- /dev/null +++ b/main/src/cgeo/geocaching/connector/WaymarkingConnector.java @@ -0,0 +1,40 @@ +package cgeo.geocaching.connector; + +import cgeo.geocaching.Geocache; +import cgeo.geocaching.ICache; + +import org.apache.commons.lang3.StringUtils; + +public class WaymarkingConnector extends AbstractConnector { + + @Override + public String getName() { + return "Waymarking"; + } + + @Override + public String getCacheUrl(Geocache cache) { + return getCacheUrlPrefix() + cache.getGeocode(); + } + + @Override + public String getHost() { + return "www.waymarking.com"; + } + + @Override + public boolean isOwner(ICache cache) { + // this connector has no user management + return false; + } + + @Override + protected String getCacheUrlPrefix() { + return "http://" + getHost() + "/waymarks/"; + } + + @Override + public boolean canHandle(String geocode) { + return StringUtils.startsWith(geocode, "WM"); + } +} diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java index 4150b87..8412207 100644 --- a/main/src/cgeo/geocaching/files/GPXParser.java +++ b/main/src/cgeo/geocaching/files/GPXParser.java @@ -296,11 +296,7 @@ public abstract class GPXParser extends FileParser { } } - if (StringUtils.isNotBlank(cache.getGeocode()) - && cache.getCoords() != null - && ((type == null && sym == null) - || StringUtils.contains(type, "geocache") - || StringUtils.contains(sym, "geocache"))) { + if (isValidForImport()) { fixCache(cache); cache.setListId(listId); cache.setDetailed(true); @@ -451,6 +447,17 @@ public abstract class GPXParser extends FileParser { } }); + // waypoint.urlname (name for waymarks) + waypoint.getChild(namespace, "urlname").setEndTextElementListener(new EndTextElementListener() { + + @Override + public void end(String urlName) { + if (cache.getName().equals(cache.getGeocode()) && StringUtils.startsWith(cache.getGeocode(), "WM")) { + cache.setName(StringUtils.trim(urlName)); + } + } + }); + // for GPX 1.0, cache info comes from waypoint node (so called private children, // for GPX 1.1 from extensions node final Element cacheParent = getCacheParent(waypoint); @@ -892,4 +899,17 @@ public abstract class GPXParser extends FileParser { } } } + + private boolean isValidForImport() { + if (StringUtils.isBlank(cache.getGeocode())) { + return false; + } + if (cache.getCoords() == null) { + return false; + } + return ((type == null && sym == null) + || StringUtils.contains(type, "geocache") + || StringUtils.contains(sym, "geocache") + || StringUtils.containsIgnoreCase(sym, "waymark")); + } } |
