blob: 98b165643dceb26e23bd997fd52a11a73de3b9c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
package cgeo.geocaching.connector.ox;
import cgeo.geocaching.SearchResult;
import cgeo.geocaching.Settings;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.connector.AbstractConnector;
import cgeo.geocaching.connector.capability.ISearchByCenter;
import cgeo.geocaching.connector.capability.ISearchByGeocode;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.utils.CancellableHandler;
import java.util.Collection;
import java.util.regex.Pattern;
/**
* connector for OpenCaching.com
*
*/
public class OXConnector extends AbstractConnector implements ISearchByCenter, ISearchByGeocode {
private static final Pattern PATTERN_GEOCODE = Pattern.compile("OX[A-Z0-9]+", Pattern.CASE_INSENSITIVE);
@Override
public boolean canHandle(String geocode) {
return PATTERN_GEOCODE.matcher(geocode).matches();
}
@Override
public String getCacheUrl(cgCache cache) {
return getCacheUrlPrefix() + cache.getGeocode();
}
@Override
public String getName() {
return "OpenCaching.com";
}
@Override
public String getHost() {
return "www.opencaching.com";
}
@Override
public String getLicenseText(cgCache cache) {
// NOT TO BE TRANSLATED
return "<a href=\"" + getCacheUrl(cache) + "\">" + getName() + "</a> data licensed under the Creative Commons BY-SA 3.0 License";
}
@Override
public SearchResult searchByGeocode(String geocode, String guid, CancellableHandler handler) {
final cgCache cache = OpenCachingApi.searchByGeoCode(geocode);
if (cache == null) {
return null;
}
final SearchResult searchResult = new SearchResult(cache);
return searchResult.filterSearchResults(false, false, Settings.getCacheType());
}
@Override
public SearchResult searchByCenter(Geopoint center) {
Collection<cgCache> caches = OpenCachingApi.searchByCenter(center);
if (caches == null) {
return null;
}
return new SearchResult(caches);
}
@Override
protected String getCacheUrlPrefix() {
return "http://www.opencaching.com/#!geocache/";
}
}
|