aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/connector/oc/OCConnector.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/connector/oc/OCConnector.java')
-rw-r--r--main/src/cgeo/geocaching/connector/oc/OCConnector.java40
1 files changed, 33 insertions, 7 deletions
diff --git a/main/src/cgeo/geocaching/connector/oc/OCConnector.java b/main/src/cgeo/geocaching/connector/oc/OCConnector.java
index 1ba88d5..6d7b23a 100644
--- a/main/src/cgeo/geocaching/connector/oc/OCConnector.java
+++ b/main/src/cgeo/geocaching/connector/oc/OCConnector.java
@@ -1,12 +1,13 @@
package cgeo.geocaching.connector.oc;
import cgeo.geocaching.Geocache;
-import cgeo.geocaching.ICache;
import cgeo.geocaching.R;
import cgeo.geocaching.connector.AbstractConnector;
import cgeo.geocaching.enumerations.LogType;
+import org.apache.commons.lang3.StringUtils;
import org.eclipse.jdt.annotation.NonNull;
+import org.eclipse.jdt.annotation.Nullable;
import java.util.Arrays;
import java.util.List;
@@ -29,42 +30,46 @@ public class OCConnector extends AbstractConnector {
}
@Override
- public boolean canHandle(@NonNull String geocode) {
+ public boolean canHandle(@NonNull final String geocode) {
return codePattern.matcher(geocode).matches();
}
@Override
+ @NonNull
public String getName() {
return name;
}
@Override
- public String getCacheUrl(@NonNull Geocache cache) {
+ @NonNull
+ public String getCacheUrl(@NonNull final Geocache cache) {
return getCacheUrlPrefix() + cache.getGeocode();
}
@Override
+ @NonNull
public String getHost() {
return host;
}
@Override
- public boolean isZippedGPXFile(String fileName) {
+ public boolean isZippedGPXFile(@NonNull final String fileName) {
return GPX_ZIP_FILE_PATTERN.matcher(fileName).matches();
}
@Override
- public boolean isOwner(final ICache cache) {
+ public boolean isOwner(@NonNull final Geocache cache) {
return false;
}
@Override
+ @NonNull
protected String getCacheUrlPrefix() {
return "http://" + host + "/viewcache.php?wp=";
}
@Override
- public int getCacheMapMarkerId(boolean disabled) {
+ public int getCacheMapMarkerId(final boolean disabled) {
if (disabled) {
return R.drawable.marker_disabled_oc;
}
@@ -72,11 +77,32 @@ public class OCConnector extends AbstractConnector {
}
@Override
- public final List<LogType> getPossibleLogTypes(Geocache cache) {
+ @NonNull
+ public final List<LogType> getPossibleLogTypes(@NonNull final Geocache cache) {
if (cache.isEventCache()) {
return EVENT_LOG_TYPES;
}
return STANDARD_LOG_TYPES;
}
+
+ @Override
+ @Nullable
+ public String getGeocodeFromUrl(@NonNull final String url) {
+ // different opencaching installations have different supported URLs
+
+ // host.tld/geocode
+ final String shortHost = StringUtils.remove(getHost(), "www.");
+ String geocode = StringUtils.substringAfter(url, shortHost + "/");
+ if (canHandle(geocode)) {
+ return geocode;
+ }
+
+ // host.tld/viewcache.php?wp=geocode
+ geocode = StringUtils.substringAfter(url, shortHost + "/viewcache.php?wp=");
+ if (canHandle(geocode)) {
+ return geocode;
+ }
+ return super.getGeocodeFromUrl(url);
+ }
}