aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2013-06-08 11:42:58 +0200
committerBananeweizen <bananeweizen@gmx.de>2013-06-08 11:42:58 +0200
commit4db2bf20294175048bf1124bc29143074d01c42b (patch)
tree0e2428604c2793213f9fcc0e1932cb43b2361f4a
parent934945bddf33ec77ee77daff1add6498fe08e400 (diff)
downloadcgeo-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.
-rw-r--r--main/src/cgeo/geocaching/connector/ConnectorFactory.java1
-rw-r--r--main/src/cgeo/geocaching/connector/WaymarkingConnector.java40
-rw-r--r--main/src/cgeo/geocaching/files/GPXParser.java30
-rw-r--r--tests/res/raw/waymarking_gpx.gpx20
-rw-r--r--tests/src/cgeo/geocaching/files/GPXParserTest.java14
5 files changed, 100 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"));
+ }
}
diff --git a/tests/res/raw/waymarking_gpx.gpx b/tests/res/raw/waymarking_gpx.gpx
new file mode 100644
index 0000000..5f93da9
--- /dev/null
+++ b/tests/res/raw/waymarking_gpx.gpx
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="utf-8"?>
+<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" version="1.0" creator="Groundspeak, Inc. All Rights Reserved. http://www.groundspeak.com" xsi:schemaLocation="http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd" xmlns="http://www.topografix.com/GPX/1/0">
+ <name>GPX Lite Waymark List Generated from Waymarking.com</name>
+ <desc>A list of waymarks generated from Waymarking.com</desc>
+ <author />
+ <email>contact@waymarking.com</email>
+ <url>http://www.waymarking.com</url>
+ <urlname>Waymarking - Unique and Interesting Locations</urlname>
+ <time>2013-06-08T07:06:36.3821125Z</time>
+ <keywords>waymark</keywords>
+ <bounds minlat="48.86422" minlon="9.1836" maxlat="48.86422" maxlon="9.1836" />
+ <wpt lat="48.86422" lon="9.1836">
+ <name>WM7BM7</name>
+ <desc>Roman water pipe Kornwestheim - A water fountain from an originally Roman water pipe.</desc>
+ <url>http://www.waymarking.com/waymarks/WM7BM7_Roman_water_pipe_Kornwestheim</url>
+ <urlname>Roman water pipe Kornwestheim</urlname>
+ <sym>Waymark</sym>
+ <type>Ancient Roman Civilization</type>
+ </wpt>
+</gpx> \ No newline at end of file
diff --git a/tests/src/cgeo/geocaching/files/GPXParserTest.java b/tests/src/cgeo/geocaching/files/GPXParserTest.java
index 8fd962e..5732f9a 100644
--- a/tests/src/cgeo/geocaching/files/GPXParserTest.java
+++ b/tests/src/cgeo/geocaching/files/GPXParserTest.java
@@ -13,6 +13,8 @@ import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.test.AbstractResourceInstrumentationTestCase;
import cgeo.geocaching.test.R;
+import org.apache.commons.lang3.StringUtils;
+
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
@@ -281,4 +283,16 @@ public class GPXParserTest extends AbstractResourceInstrumentationTestCase {
removeCacheCompletely(geocode);
}
+ public void testWaymarking() throws Exception {
+ final List<Geocache> caches = readGPX10(R.raw.waymarking_gpx);
+ assertEquals(1, caches.size());
+ final Geocache waymark = caches.get(0);
+ assertNotNull(waymark);
+ assertEquals("WM7BM7", waymark.getGeocode());
+ assertEquals("Roman water pipe Kornwestheim", waymark.getName());
+ assertTrue(StringUtils.isNotBlank(waymark.getUrl())); // connector must be able to create it
+ assertEquals(CacheType.UNKNOWN, waymark.getType());
+ assertEquals(CacheSize.UNKNOWN, waymark.getSize());
+ }
+
}