aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrsudev <rasch@munin-soft.de>2013-02-15 20:50:41 +0100
committerrsudev <rasch@munin-soft.de>2013-02-15 20:50:41 +0100
commita268af51bcf2ddec2ab4631c6d0aedbd51811ec2 (patch)
treea0ddd3bca219fe4955cc30d7de127426b3102f82
parent379aa516c02aa30708f72f8a01b35c2dbd0767eb (diff)
downloadcgeo-a268af51bcf2ddec2ab4631c6d0aedbd51811ec2.zip
cgeo-a268af51bcf2ddec2ab4631c6d0aedbd51811ec2.tar.gz
cgeo-a268af51bcf2ddec2ab4631c6d0aedbd51811ec2.tar.bz2
Fixes #2486, Archived/Disabled OC-caches returned in nearby search
Correct handling of flags and attributes in Parser Added Testcase Added method for unfiltered parsing for single cache downlaods
-rw-r--r--main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java21
-rw-r--r--main/src/cgeo/geocaching/connector/oc/OCXMLClient.java2
-rw-r--r--tests/src/cgeo/geocaching/connector/opencaching/OCXMLTest.java23
3 files changed, 42 insertions, 4 deletions
diff --git a/main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java b/main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java
index 3c2a826..6231c68 100644
--- a/main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java
+++ b/main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java
@@ -217,6 +217,16 @@ public class OC11XMLParser {
protected static int attributeId;
public static Collection<Geocache> parseCaches(final InputStream stream) throws IOException {
+ // parse and return caches without filtering
+ return parseCaches(stream, true);
+ }
+
+ public static Collection<Geocache> parseCachesFiltered(final InputStream stream) throws IOException {
+ // parse caches and filter result
+ return parseCaches(stream, false);
+ }
+
+ private static Collection<Geocache> parseCaches(final InputStream stream, boolean ignoreFiltersIn) throws IOException {
final Map<String, Geocache> caches = new HashMap<String, Geocache>();
final Map<String, LogEntry> logs = new HashMap<String, LogEntry>();
@@ -228,6 +238,8 @@ public class OC11XMLParser {
final RootElement root = new RootElement("oc11xml");
final Element cacheNode = root.getChild("cache");
+ final boolean ignoreFilters = ignoreFiltersIn;
+
// cache
cacheNode.setStartElementListener(new StartElementListener() {
@@ -245,17 +257,20 @@ public class OC11XMLParser {
Geocache cache = cacheHolder.cache;
Geopoint coords = new Geopoint(cacheHolder.latitude, cacheHolder.longitude);
cache.setCoords(coords);
- if (caches.size() < CACHE_PARSE_LIMIT && isValid(cache) && !isExcluded(cache)) {
+ if (caches.size() < CACHE_PARSE_LIMIT && isValid(cache) && (ignoreFilters || !isExcluded(cache))) {
cache.setDetailedUpdatedNow();
caches.put(cache.getCacheId(), cache);
}
}
private boolean isExcluded(Geocache cache) {
- if (cache.isArchived() && Settings.isExcludeDisabledCaches()) {
+ if (cache.isArchived()) {
+ return true;
+ }
+ if (cache.isDisabled() && Settings.isExcludeDisabledCaches()) {
return true;
}
- if (cache.isFound() && Settings.isExcludeMyCaches()) {
+ if ((cache.isFound() || cache.isOwner()) && Settings.isExcludeMyCaches()) {
return true;
}
return !Settings.getCacheType().contains(cache);
diff --git a/main/src/cgeo/geocaching/connector/oc/OCXMLClient.java b/main/src/cgeo/geocaching/connector/oc/OCXMLClient.java
index dee7bb9..6767b48 100644
--- a/main/src/cgeo/geocaching/connector/oc/OCXMLClient.java
+++ b/main/src/cgeo/geocaching/connector/oc/OCXMLClient.java
@@ -64,7 +64,7 @@ public class OCXMLClient {
return Collections.emptyList();
}
- return OC11XMLParser.parseCaches(new GZIPInputStream(data));
+ return OC11XMLParser.parseCachesFiltered(new GZIPInputStream(data));
} catch (IOException e) {
Log.e("Error parsing nearby search result", e);
return Collections.emptyList();
diff --git a/tests/src/cgeo/geocaching/connector/opencaching/OCXMLTest.java b/tests/src/cgeo/geocaching/connector/opencaching/OCXMLTest.java
index 52e5649..a5631e1 100644
--- a/tests/src/cgeo/geocaching/connector/opencaching/OCXMLTest.java
+++ b/tests/src/cgeo/geocaching/connector/opencaching/OCXMLTest.java
@@ -6,6 +6,8 @@ import cgeo.geocaching.Settings;
import cgeo.geocaching.connector.oc.OCXMLClient;
import cgeo.geocaching.enumerations.CacheType;
+import java.util.Collection;
+
public class OCXMLTest extends CGeoTestCase {
public static void testOCGetCache() {
@@ -57,4 +59,25 @@ public class OCXMLTest extends CGeoTestCase {
assertFalse(cache.getDescription().length() < 100);
}
+
+ public static void testNoArchivedInNearby() {
+
+ boolean oldExcludeDisabled = Settings.isExcludeDisabledCaches();
+ boolean oldExcludeMine = Settings.isExcludeMyCaches();
+ try {
+ Settings.setExcludeDisabledCaches(false);
+ Settings.setExcludeMine(false);
+ // get an archived cache
+ Geocache cache = OCXMLClient.getCache("OCD541");
+ assertNotNull(cache);
+ assertTrue(cache.isArchived());
+ // Get nearby for this cache
+ Collection<Geocache> caches = OCXMLClient.getCachesAround(cache.getCoords(), 0.5);
+ // Should not be in the result!
+ assertFalse(caches.contains(cache));
+ } finally {
+ Settings.setExcludeDisabledCaches(oldExcludeDisabled);
+ Settings.setExcludeMine(oldExcludeMine);
+ }
+ }
}