diff options
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/EditWaypointActivity.java | 15 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/Geocache.java | 34 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/StaticMapsActivity.java | 7 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/StaticMapsProvider.java | 75 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/Waypoint.java | 9 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/apps/cache/navi/AbstractStaticMapsApp.java | 5 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 46 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeocaches.java | 53 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/AbstractConnector.java | 5 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/IConnector.java | 10 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCConnector.java | 14 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCConstants.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java | 28 |
13 files changed, 253 insertions, 50 deletions
diff --git a/main/src/cgeo/geocaching/EditWaypointActivity.java b/main/src/cgeo/geocaching/EditWaypointActivity.java index e886dea..7f011fc 100644 --- a/main/src/cgeo/geocaching/EditWaypointActivity.java +++ b/main/src/cgeo/geocaching/EditWaypointActivity.java @@ -488,11 +488,18 @@ public class EditWaypointActivity extends AbstractActivity { waypoint.setId(id); Geocache cache = cgData.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS); - if (null != cache && cache.addOrChangeWaypoint(waypoint, true)) { + if (cache == null) { + finishHandler.sendEmptyMessage(SAVE_ERROR); + return null; + } + Waypoint oldWaypoint = cache.getWaypointById(id); + if (cache.addOrChangeWaypoint(waypoint, true)) { cgData.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB)); - StaticMapsProvider.removeWpStaticMaps(id, geocode); - if (Settings.isStoreOfflineWpMaps()) { - StaticMapsProvider.storeWaypointStaticMap(cache, waypoint, false); + if (!StaticMapsProvider.hasAllStaticMapsForWaypoint(geocode, waypoint)) { + StaticMapsProvider.removeWpStaticMaps(oldWaypoint, geocode); + if (Settings.isStoreOfflineWpMaps()) { + StaticMapsProvider.storeWaypointStaticMap(cache, waypoint, false); + } } final RadioButton modifyLocal = (RadioButton) findViewById(R.id.modify_cache_coordinates_local); final RadioButton modifyBoth = (RadioButton) findViewById(R.id.modify_cache_coordinates_local_and_remote); diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index 18a315c..9a8325d 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -516,13 +516,17 @@ public class Geocache implements ICache, IWaypoint { } public void openInBrowser(Activity fromActivity) { - fromActivity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getCacheUrl()))); + fromActivity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(getBrowserCacheUrl()))); } private String getCacheUrl() { return getConnector().getCacheUrl(this); } + private String getBrowserCacheUrl() { + return getConnector().getLongCacheUrl(this); + } + private IConnector getConnector() { return ConnectorFactory.getConnector(this); } @@ -618,15 +622,27 @@ public class Geocache implements ICache, IWaypoint { @Override public String getHint() { initializeCacheTexts(); + assertTextNotNull(hint, "Hint"); return hint; } /** + * After lazy loading the lazily loaded field must be non {@code null}. + * + */ + private static void assertTextNotNull(final String field, final String name) throws InternalError { + if (field == null) { + throw new InternalError(name + " field is not allowed to be null here"); + } + } + + /** * Attention, calling this method may trigger a database access for the cache! */ @Override public String getDescription() { initializeCacheTexts(); + assertTextNotNull(description, "Description"); return description; } @@ -635,7 +651,19 @@ public class Geocache implements ICache, IWaypoint { */ private void initializeCacheTexts() { if (description == null || shortdesc == null || hint == null || location == null) { - cgData.loadCacheTexts(this); + Geocache partial = cgData.loadCacheTexts(this.getGeocode()); + if (description == null) { + setDescription(partial.getDescription()); + } + if (shortdesc == null) { + setShortDescription(partial.getShortDescription()); + } + if (hint == null) { + setHint(partial.getHint()); + } + if (location == null) { + setLocation(partial.getLocation()); + } } } @@ -645,6 +673,7 @@ public class Geocache implements ICache, IWaypoint { @Override public String getShortDescription() { initializeCacheTexts(); + assertTextNotNull(shortdesc, "Short description"); return shortdesc; } @@ -673,6 +702,7 @@ public class Geocache implements ICache, IWaypoint { @Override public String getLocation() { initializeCacheTexts(); + assertTextNotNull(location, "Location"); return location; } diff --git a/main/src/cgeo/geocaching/StaticMapsActivity.java b/main/src/cgeo/geocaching/StaticMapsActivity.java index d7cef65..005ee9e 100644 --- a/main/src/cgeo/geocaching/StaticMapsActivity.java +++ b/main/src/cgeo/geocaching/StaticMapsActivity.java @@ -134,7 +134,8 @@ public class StaticMapsActivity extends AbstractActivity { for (int level = 1; level <= 5; level++) { try { if (waypoint_id != null) { - final Bitmap image = StaticMapsProvider.getWaypointMap(geocode, waypoint_id, level); + final Geocache cache = cgData.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB); + final Bitmap image = StaticMapsProvider.getWaypointMap(geocode, cache.getWaypointById(waypoint_id), level); if (image != null) { maps.add(image); } @@ -186,8 +187,10 @@ public class StaticMapsActivity extends AbstractActivity { final Waypoint waypoint = cache.getWaypointById(waypoint_id); if (waypoint != null) { showToast(res.getString(R.string.info_storing_static_maps)); + // refresh always removes old waypoint files + StaticMapsProvider.removeWpStaticMaps(waypoint, geocode); StaticMapsProvider.storeWaypointStaticMap(cache, waypoint, true); - return StaticMapsProvider.hasStaticMapForWaypoint(geocode, waypoint_id); + return StaticMapsProvider.hasStaticMapForWaypoint(geocode, waypoint); } showToast(res.getString(R.string.err_detail_not_load_map_static)); return false; diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java index 6feacc2..8e853d6 100644 --- a/main/src/cgeo/geocaching/StaticMapsProvider.java +++ b/main/src/cgeo/geocaching/StaticMapsProvider.java @@ -95,13 +95,29 @@ public class StaticMapsProvider { storeCacheStaticMap(cache, edge, false); } - // download static map for current waypoints + // clean old and download static maps for waypoints if one is missing if (Settings.isStoreOfflineWpMaps() && CollectionUtils.isNotEmpty(cache.getWaypoints())) { - // remove all waypoint static map files due to origin cache waypoint id changed on saveCache - LocalStorage.deleteFilesWithPrefix(cache.getGeocode(), MAP_FILENAME_PREFIX + WAYPOINT_PREFIX); for (Waypoint waypoint : cache.getWaypoints()) { - storeWaypointStaticMap(cache.getGeocode(), edge, waypoint, false); + if (!hasAllStaticMapsForWaypoint(cache.getGeocode(), waypoint)) { + refreshAllWpStaticMaps(cache, edge); + } } + + } + } + + /** + * Deletes and download all Waypoints static maps. + * + * @param cache + * The cache instance + * @param edge + * The boundings + */ + private static void refreshAllWpStaticMaps(Geocache cache, int edge) { + LocalStorage.deleteFilesWithPrefix(cache.getGeocode(), MAP_FILENAME_PREFIX + WAYPOINT_PREFIX); + for (Waypoint waypoint : cache.getWaypoints()) { + storeWaypointStaticMap(cache.getGeocode(), edge, waypoint, false); } } @@ -124,8 +140,10 @@ public class StaticMapsProvider { } String wpLatlonMap = waypoint.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA); String wpMarkerUrl = getWpMarkerUrl(waypoint); - // download map images in separate background thread for higher performance - downloadMaps(geocode, wpMarkerUrl, WAYPOINT_PREFIX + waypoint.getId() + '_', wpLatlonMap, edge, null, waitForResult); + if (!hasAllStaticMapsForWaypoint(geocode, waypoint)) { + // download map images in separate background thread for higher performance + downloadMaps(geocode, wpMarkerUrl, WAYPOINT_PREFIX + waypoint.getId() + '_' + waypoint.calculateStaticMapsHashcode() + "_", wpLatlonMap, edge, null, waitForResult); + } } public static void storeCacheStaticMap(Geocache cache, final boolean waitForResult) { @@ -210,13 +228,15 @@ public class StaticMapsProvider { return MARKERS_URL + "marker_waypoint_" + type + ".png"; } - public static void removeWpStaticMaps(int wp_id, final String geocode) { - if (wp_id <= 0) { + public static void removeWpStaticMaps(Waypoint waypoint, final String geocode) { + if (waypoint == null) { return; } + int waypointId = waypoint.getId(); + int waypointMapHash = waypoint.calculateStaticMapsHashcode(); for (int level = 1; level <= 5; level++) { try { - StaticMapsProvider.getMapFile(geocode, WAYPOINT_PREFIX + wp_id + '_' + level, false).delete(); + StaticMapsProvider.getMapFile(geocode, WAYPOINT_PREFIX + waypointId + "_" + waypointMapHash + '_' + level, false).delete(); } catch (Exception e) { Log.e("StaticMapsProvider.removeWpStaticMaps", e); } @@ -250,12 +270,14 @@ public class StaticMapsProvider { * Checks if at least one map file exists for the given geocode and waypoint ID. * * @param geocode - * @param waypointId + * @param waypoint * @return <code>true</code> if at least one mapfile exists; <code>false</code> otherwise */ - public static boolean hasStaticMapForWaypoint(String geocode, int waypointId) { + public static boolean hasStaticMapForWaypoint(String geocode, Waypoint waypoint) { + int waypointId = waypoint.getId(); + int waypointMapHash = waypoint.calculateStaticMapsHashcode(); for (int level = 1; level <= 5; level++) { - File mapFile = StaticMapsProvider.getMapFile(geocode, WAYPOINT_PREFIX + waypointId + "_" + level, false); + File mapFile = StaticMapsProvider.getMapFile(geocode, WAYPOINT_PREFIX + waypointId + "_" + waypointMapHash + "_" + level, false); if (mapFile != null && mapFile.exists()) { return true; } @@ -263,12 +285,37 @@ public class StaticMapsProvider { return false; } + /** + * Checks if at least one map file exists for the given geocode and waypoint ID. + * + * @param geocode + * @param waypoint + * @return <code>true</code> if at least one mapfile exists; <code>false</code> otherwise + */ + public static boolean hasAllStaticMapsForWaypoint(String geocode, Waypoint waypoint) { + int waypointId = waypoint.getId(); + int waypointMapHash = waypoint.calculateStaticMapsHashcode(); + for (int level = 1; level <= 5; level++) { + File mapFile = StaticMapsProvider.getMapFile(geocode, WAYPOINT_PREFIX + waypointId + "_" + waypointMapHash + "_" + level, false); + if (mapFile == null) { + return false; + } + boolean mapExists = mapFile.exists(); + if (!mapExists) { + return false; + } + } + return true; + } + public static Bitmap getPreviewMap(final String geocode) { return decodeFile(StaticMapsProvider.getMapFile(geocode, PREFIX_PREVIEW, false)); } - public static Bitmap getWaypointMap(final String geocode, int waypoint_id, int level) { - return decodeFile(StaticMapsProvider.getMapFile(geocode, WAYPOINT_PREFIX + waypoint_id + "_" + level, false)); + public static Bitmap getWaypointMap(final String geocode, Waypoint waypoint, int level) { + int waypointId = waypoint.getId(); + int waypointMapHash = waypoint.calculateStaticMapsHashcode(); + return decodeFile(StaticMapsProvider.getMapFile(geocode, WAYPOINT_PREFIX + waypointId + "_" + waypointMapHash + "_" + level, false)); } public static Bitmap getCacheMap(final String geocode, int level) { diff --git a/main/src/cgeo/geocaching/Waypoint.java b/main/src/cgeo/geocaching/Waypoint.java index 4b014a6..53160e5 100644 --- a/main/src/cgeo/geocaching/Waypoint.java +++ b/main/src/cgeo/geocaching/Waypoint.java @@ -269,4 +269,13 @@ public class Waypoint implements IWaypoint, Comparable<Waypoint> { public boolean isVisited() { return visited; } + + public int calculateStaticMapsHashcode() { + long hash = 0; + if (coords != null) { + hash = coords.hashCode(); + } + hash = hash ^ waypointType.markerId; + return (int) hash; + } } diff --git a/main/src/cgeo/geocaching/apps/cache/navi/AbstractStaticMapsApp.java b/main/src/cgeo/geocaching/apps/cache/navi/AbstractStaticMapsApp.java index d089e82..d898d7e 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/AbstractStaticMapsApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/AbstractStaticMapsApp.java @@ -1,11 +1,11 @@ package cgeo.geocaching.apps.cache.navi; +import cgeo.geocaching.Geocache; import cgeo.geocaching.ILogable; import cgeo.geocaching.R; import cgeo.geocaching.StaticMapsActivity; import cgeo.geocaching.StaticMapsProvider; import cgeo.geocaching.Waypoint; -import cgeo.geocaching.Geocache; import cgeo.geocaching.cgData; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.apps.AbstractApp; @@ -34,9 +34,8 @@ abstract class AbstractStaticMapsApp extends AbstractApp implements CacheNavigat return false; } String geocode = waypoint.getGeocode(); - int id = waypoint.getId(); if (StringUtils.isNotEmpty(geocode) && cgData.isOffline(geocode, null)) { - return StaticMapsProvider.hasStaticMapForWaypoint(geocode, id); + return StaticMapsProvider.hasStaticMapForWaypoint(geocode, waypoint); } return false; } diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 7e9b37a..78c28b1 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -2382,6 +2382,22 @@ public class cgData { database.delete(dbTableLogsOffline, "geocode = ?", new String[]{geocode}); } + public static void clearLogsOffline(List<Geocache> caches) { + if (CollectionUtils.isEmpty(caches)) { + return; + } + + init(); + + Set<String> geocodes = new HashSet<String>(caches.size()); + for (Geocache cache : caches) { + geocodes.add(cache.getGeocode()); + cache.setLogOffline(false); + } + + database.execSQL(String.format("DELETE FROM %s where %s", dbTableLogsOffline, whereGeocodeIn(geocodes))); + } + public static boolean hasLogOffline(final String geocode) { if (StringUtils.isBlank(geocode)) { return false; @@ -2644,11 +2660,21 @@ public class cgData { return result; } - public static String loadCacheTexts(final Geocache cache) { - final String geocode = cache.getGeocode(); - if (StringUtils.isBlank(geocode)) { - return null; - } + /** + * Load the lazily initialized fields of a cache and return them as partial cache (all other fields unset). + * + * @param geocode + * @return + */ + public static Geocache loadCacheTexts(final String geocode) { + final Geocache partial = new Geocache(); + + // in case of database issues, we still need to return a result to avoid endless loops + partial.setDescription(StringUtils.EMPTY); + partial.setShortDescription(StringUtils.EMPTY); + partial.setHint(StringUtils.EMPTY); + partial.setLocation(StringUtils.EMPTY); + init(); try { @@ -2663,10 +2689,10 @@ public class cgData { "1"); if (cursor.moveToFirst()) { - cache.setDescription(StringUtils.defaultString(cursor.getString(0))); - cache.setShortDescription(StringUtils.defaultString(cursor.getString(1))); - cache.setHint(StringUtils.defaultString(cursor.getString(2))); - cache.setLocation(StringUtils.defaultString(cursor.getString(3))); + partial.setDescription(StringUtils.defaultString(cursor.getString(0))); + partial.setShortDescription(StringUtils.defaultString(cursor.getString(1))); + partial.setHint(StringUtils.defaultString(cursor.getString(2))); + partial.setLocation(StringUtils.defaultString(cursor.getString(3))); } cursor.close(); @@ -2676,7 +2702,7 @@ public class cgData { Log.e("cgData.getCacheDescription", e); } - return null; + return partial; } /** diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index 726b60e..2c9c80b 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -109,6 +109,7 @@ public class cgeocaches extends AbstractListActivity implements FilteredActivity private static final int MENU_STORE_CACHE = 73; private static final int MENU_FILTER = 74; private static final int MENU_DELETE_EVENTS = 75; + private static final int MENU_CLEAR_OFFLINE_LOGS = 76; private static final int MSG_DONE = -1; private static final int MSG_RESTART_GEO_AND_DIR = -2; @@ -387,6 +388,21 @@ public class cgeocaches extends AbstractListActivity implements FilteredActivity } } }; + private Handler clearOfflineLogsHandler = new Handler() { + + @Override + public void handleMessage(Message msg) { + if (msg.what != MSG_CANCEL) { + adapter.setSelectMode(false); + + refreshCurrentList(); + + replaceCacheListFromSearch(); + + progress.dismiss(); + } + } + }; private Handler importGpxAttachementFinishedHandler = new Handler() { @Override @@ -544,6 +560,7 @@ public class cgeocaches extends AbstractListActivity implements FilteredActivity subMenu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.cache_offline_refresh)); // download details for all caches subMenu.add(0, MENU_MOVE_TO_LIST, 0, res.getString(R.string.cache_menu_move_list)); subMenu.add(0, MENU_DELETE_EVENTS, 0, res.getString(R.string.caches_delete_events)); + subMenu.add(0, MENU_CLEAR_OFFLINE_LOGS, 0, res.getString(R.string.caches_clear_offlinelogs)); //TODO: add submenu/AlertDialog and use R.string.gpx_import_title subMenu.add(0, MENU_IMPORT_GPX, 0, res.getString(R.string.gpx_import_title)); @@ -610,6 +627,7 @@ public class cgeocaches extends AbstractListActivity implements FilteredActivity setVisible(menu, MENU_MOVE_TO_LIST, !isEmpty); setVisible(menu, MENU_EXPORT, !isEmpty); setVisible(menu, MENU_REMOVE_FROM_HISTORY, !isEmpty); + setVisible(menu, MENU_CLEAR_OFFLINE_LOGS, !isEmpty && containsOfflineLogs()); setVisible(menu, MENU_IMPORT_GPX, isConcrete); setVisible(menu, MENU_IMPORT_WEB, isConcrete); @@ -666,6 +684,15 @@ public class cgeocaches extends AbstractListActivity implements FilteredActivity return false; } + private boolean containsOfflineLogs() { + for (Geocache cache : adapter.getCheckedOrAllCaches()) { + if (cache.isLogOffline()) { + return true; + } + } + return false; + } + private void setMenuItemLabel(final Menu menu, final int menuId, final int resIdSelection, final int resId) { final MenuItem menuItem = menu.findItem(menuId); if (menuItem == null) { @@ -751,6 +778,10 @@ public class cgeocaches extends AbstractListActivity implements FilteredActivity deletePastEvents(); invalidateOptionsMenuCompatible(); return true; + case MENU_CLEAR_OFFLINE_LOGS: + clearOfflineLogs(); + invalidateOptionsMenuCompatible(); + return true; default: return CacheListAppFactory.onMenuItemSelected(item, cacheList, this, search); } @@ -770,6 +801,11 @@ public class cgeocaches extends AbstractListActivity implements FilteredActivity new DropDetailsThread(dropDetailsHandler, deletion).start(); } + public void clearOfflineLogs() { + progress.show(this, null, res.getString(R.string.caches_clear_offlinelogs_progress), true, clearOfflineLogsHandler.obtainMessage(MSG_CANCEL)); + new ClearOfflineLogsThread(clearOfflineLogsHandler).start(); + } + /** * called from the filter bar view */ @@ -1361,6 +1397,23 @@ public class cgeocaches extends AbstractListActivity implements FilteredActivity } } + private class ClearOfflineLogsThread extends Thread { + + final private Handler handler; + final private List<Geocache> selected; + + public ClearOfflineLogsThread(Handler handlerIn) { + handler = handlerIn; + selected = adapter.getCheckedOrAllCaches(); + } + + @Override + public void run() { + cgData.clearLogsOffline(selected); + handler.sendEmptyMessage(MSG_DONE); + } + } + private class MoreCachesListener implements View.OnClickListener { @Override diff --git a/main/src/cgeo/geocaching/connector/AbstractConnector.java b/main/src/cgeo/geocaching/connector/AbstractConnector.java index 1eb8fbb..413291c 100644 --- a/main/src/cgeo/geocaching/connector/AbstractConnector.java +++ b/main/src/cgeo/geocaching/connector/AbstractConnector.java @@ -102,6 +102,11 @@ public abstract class AbstractConnector implements IConnector { abstract protected String getCacheUrlPrefix(); + @Override + public String getLongCacheUrl(final Geocache cache) { + return getCacheUrl(cache); + } + /** * {@link IConnector} */ diff --git a/main/src/cgeo/geocaching/connector/IConnector.java b/main/src/cgeo/geocaching/connector/IConnector.java index da626f2..9169b4a 100644 --- a/main/src/cgeo/geocaching/connector/IConnector.java +++ b/main/src/cgeo/geocaching/connector/IConnector.java @@ -1,7 +1,7 @@ package cgeo.geocaching.connector; -import cgeo.geocaching.ICache; import cgeo.geocaching.Geocache; +import cgeo.geocaching.ICache; import cgeo.geocaching.enumerations.CacheRealm; import cgeo.geocaching.geopoint.Geopoint; @@ -30,6 +30,14 @@ public interface IConnector { public String getCacheUrl(final Geocache cache); /** + * get long browser URL for the given cache + * + * @param cache + * @return + */ + public String getLongCacheUrl(final Geocache cache); + + /** * enable/disable watchlist controls in cache details * * @return diff --git a/main/src/cgeo/geocaching/connector/gc/GCConnector.java b/main/src/cgeo/geocaching/connector/gc/GCConnector.java index 2a38bd9..50bf096 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCConnector.java +++ b/main/src/cgeo/geocaching/connector/gc/GCConnector.java @@ -24,7 +24,9 @@ import java.util.regex.Pattern; public class GCConnector extends AbstractConnector implements ISearchByGeocode, ISearchByCenter, ISearchByViewPort { - private static final String HTTP_COORD_INFO = "http://coord.info/"; + private static final String CACHE_URL_SHORT = "http://coord.info/"; + // Double slash is used to force open in browser + private static final String CACHE_URL_LONG = "http://www.geocaching.com//seek/cache_details.aspx?wp="; private static final Pattern gpxZipFilePattern = Pattern.compile("\\d{7,}(_.+)?\\.zip", Pattern.CASE_INSENSITIVE); private GCConnector() { @@ -51,9 +53,13 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode, } @Override + public String getLongCacheUrl(Geocache cache) { + return CACHE_URL_LONG + cache.getGeocode(); + } + + @Override public String getCacheUrl(Geocache cache) { - // it would also be possible to use "http://www.geocaching.com/seek/cache_details.aspx?wp=" + cache.getGeocode(); - return "http://www.geocaching.com//seek/cache_details.aspx?wp=" + cache.getGeocode(); + return CACHE_URL_SHORT + cache.getGeocode(); } @Override @@ -224,7 +230,7 @@ public class GCConnector extends AbstractConnector implements ISearchByGeocode, @Override protected String getCacheUrlPrefix() { - return HTTP_COORD_INFO; + return CACHE_URL_SHORT; } @Override diff --git a/main/src/cgeo/geocaching/connector/gc/GCConstants.java b/main/src/cgeo/geocaching/connector/gc/GCConstants.java index f678797..4d27617 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCConstants.java +++ b/main/src/cgeo/geocaching/connector/gc/GCConstants.java @@ -39,7 +39,7 @@ public final class GCConstants { public final static Pattern PATTERN_NAME = Pattern.compile("<span id=\"ctl00_ContentBody_CacheName\">(.*?)</span>"); public final static Pattern PATTERN_DIFFICULTY = Pattern.compile("<span id=\"ctl00_ContentBody_uxLegendScale\"[^>]*>[^<]*<img src=\"[^\"]*/images/stars/stars([0-9_]+)\\.gif\""); public final static Pattern PATTERN_TERRAIN = Pattern.compile("<span id=\"ctl00_ContentBody_Localize[\\d]+\"[^>]*>[^<]*<img src=\"[^\"]*/images/stars/stars([0-9_]+)\\.gif\""); - public final static Pattern PATTERN_OWNER_USERID = Pattern.compile("<a id=\"ctl00_ContentBody_uxFindLinksHiddenByThisUser\" href=\"[^\"]*/seek/nearest\\.aspx\\?u=(.*?)\""); + public final static Pattern PATTERN_OWNER_USERID = Pattern.compile("other caches <a href=\"/seek/nearest\\.aspx\\?u=(.*?)\">hidden</a> or"); public final static Pattern PATTERN_FOUND = Pattern.compile("<a id=\"ctl00_ContentBody_hlFoundItLog\"[^<]*<img src=\"[^\"]+check\\.\\w+\"[^>]*>[^<]*</a>[^<]*</p>"); public final static Pattern PATTERN_FOUND_ALTERNATIVE = Pattern.compile("<div class=\"StatusInformationWidget FavoriteWidget\""); public final static Pattern PATTERN_FOUND_DATE = Pattern.compile("You logged this as Found on ([^.]+?)\\.[^<]*</a>[^<]*</p>"); diff --git a/main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java b/main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java index 9a76a96..621032f 100644 --- a/main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java +++ b/main/src/cgeo/geocaching/connector/oc/OC11XMLParser.java @@ -43,8 +43,7 @@ import java.util.regex.Pattern; public class OC11XMLParser { - private static final String PARAGRAPH_END = "</p>"; - private static final String PARAGRAPH_BEGIN = "<p>"; + private static final String[] MARKUP = new String[] { "p", "span" }; private static Pattern STRIP_DATE = Pattern.compile("\\+0([0-9]){1}\\:00"); private static Pattern LOCAL_URL = Pattern.compile("href=\"(.*)\""); private static final int CACHE_PARSE_LIMIT = 250; @@ -514,7 +513,7 @@ public class OC11XMLParser { @Override public void end(String body) { final String content = body.trim(); - descHolder.shortDesc = linkify(content); + descHolder.shortDesc = linkify(stripMarkup(content)); } }); @@ -524,7 +523,7 @@ public class OC11XMLParser { @Override public void end(String body) { final String content = body.trim(); - descHolder.desc = linkify(content); + descHolder.desc = linkify(stripMarkup(content)); } }); @@ -733,12 +732,23 @@ public class OC11XMLParser { * rendering. */ protected static String stripMarkup(String input) { - if (StringUtils.startsWith(input, PARAGRAPH_BEGIN) && StringUtils.endsWith(input, PARAGRAPH_END)) { - String inner = input.substring(PARAGRAPH_BEGIN.length(), input.length() - PARAGRAPH_END.length()); - if (!inner.contains(PARAGRAPH_BEGIN)) { - return inner.trim(); + if (!StringUtils.startsWith(input, "<")) { + return input; + } + String result = input.trim(); + for (String tagName : MARKUP) { + final String startTag = "<" + tagName + ">"; + if (StringUtils.startsWith(result, startTag)) { + final String endTag = "</" + tagName + ">"; + if (StringUtils.endsWith(result, endTag)) { + String inner = result.substring(startTag.length(), result.length() - endTag.length()).trim(); + String nested = stripMarkup(inner); + if (!nested.contains(startTag)) { + result = nested; + } + } } } - return input; + return result; } }
\ No newline at end of file |
