diff options
Diffstat (limited to 'main/src/cgeo/geocaching/connector/gc/GCParser.java')
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCParser.java | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java index b373cb1..fe7780a 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCParser.java +++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java @@ -1,5 +1,7 @@ package cgeo.geocaching.connector.gc; +import cgeo.geocaching.CgeoApplication; +import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; import cgeo.geocaching.Image; import cgeo.geocaching.LogEntry; @@ -8,8 +10,6 @@ import cgeo.geocaching.SearchResult; import cgeo.geocaching.Trackable; import cgeo.geocaching.TrackableLog; import cgeo.geocaching.Waypoint; -import cgeo.geocaching.cgData; -import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.enumerations.CacheSize; import cgeo.geocaching.enumerations.CacheType; import cgeo.geocaching.enumerations.LoadFlags; @@ -35,11 +35,11 @@ import cgeo.geocaching.utils.TextUtils; import ch.boye.httpclientandroidlib.HttpResponse; import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.collections.ListUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; +import org.eclipse.jdt.annotation.NonNull; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -147,7 +147,7 @@ public abstract class GCParser { } } } - } catch (final Exception e) { + } catch (final RuntimeException e) { // failed to parse GUID and/or Disabled Log.w("GCParser.parseSearch: Failed to parse GUID and/or Disabled data"); } @@ -308,19 +308,15 @@ public abstract class GCParser { final String coordinates = Network.getResponseData(Network.postRequest("http://www.geocaching.com/seek/nearest.aspx", params), false); - if (StringUtils.isNotBlank(coordinates)) { - if (coordinates.contains("You have not agreed to the license agreement. The license agreement is required before you can start downloading GPX or LOC files from Geocaching.com")) { - Log.i("User has not agreed to the license agreement. Can\'t download .loc file."); - - searchResult.setError(StatusCode.UNAPPROVED_LICENSE); - - return searchResult; - } + if (StringUtils.contains(coordinates, "You have not agreed to the license agreement. The license agreement is required before you can start downloading GPX or LOC files from Geocaching.com")) { + Log.i("User has not agreed to the license agreement. Can\'t download .loc file."); + searchResult.setError(StatusCode.UNAPPROVED_LICENSE); + return searchResult; } LocParser.parseLoc(searchResult, coordinates); - } catch (final Exception e) { + } catch (final RuntimeException e) { Log.e("GCParser.parseSearch.CIDs", e); } } @@ -357,7 +353,7 @@ public abstract class GCParser { // save full detailed caches CancellableHandler.sendLoadProgressDetail(handler, R.string.cache_dialog_loading_details_status_cache); - cgData.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB)); + DataStore.saveCache(cache, EnumSet.of(SaveFlag.SAVE_DB)); // update progress message so user knows we're still working. This is more of a place holder than // actual indication of what the program is doing @@ -569,7 +565,7 @@ public abstract class GCParser { } cache.setAttributes(attributes); } - } catch (final Exception e) { + } catch (final RuntimeException e) { // failed to parse cache attributes Log.w("GCParser.parseCache: Failed to parse cache attributes"); } @@ -598,7 +594,7 @@ public abstract class GCParser { } cache.addSpoiler(new Image(url, title, description)); } - } catch (final Exception e) { + } catch (final RuntimeException e) { // failed to parse cache spoilers Log.w("GCParser.parseCache: Failed to parse cache spoilers"); } @@ -632,7 +628,7 @@ public abstract class GCParser { } } } - } catch (final Exception e) { + } catch (final RuntimeException e) { // failed to parse cache inventory Log.w("GCParser.parseCache: Failed to parse cache inventory (2)"); } @@ -654,7 +650,7 @@ public abstract class GCParser { } } } - } catch (final Exception e) { + } catch (final NumberFormatException e) { // failed to parse logs Log.w("GCParser.parseCache: Failed to parse cache log count"); } @@ -667,7 +663,7 @@ public abstract class GCParser { final String originalCoords = TextUtils.getMatch(page, GCConstants.PATTERN_LATLON_ORIG, false, null); if (null != originalCoords) { - final Waypoint waypoint = new Waypoint(cgeoapplication.getInstance().getString(R.string.cache_coordinates_original), WaypointType.ORIGINAL, false); + final Waypoint waypoint = new Waypoint(CgeoApplication.getInstance().getString(R.string.cache_coordinates_original), WaypointType.ORIGINAL, false); waypoint.setCoords(new Geopoint(originalCoords)); cache.addOrChangeWaypoint(waypoint, false); cache.setUserModifiedCoords(true); @@ -706,7 +702,7 @@ public abstract class GCParser { // waypoint name // res is null during the unit tests - final String name = TextUtils.getMatch(wp[6], GCConstants.PATTERN_WPNAME, true, 1, cgeoapplication.getInstance().getString(R.string.waypoint), true); + final String name = TextUtils.getMatch(wp[6], GCConstants.PATTERN_WPNAME, true, 1, CgeoApplication.getInstance().getString(R.string.waypoint), true); // waypoint type final String resulttype = TextUtils.getMatch(wp[3], GCConstants.PATTERN_WPTYPE, null); @@ -1083,7 +1079,7 @@ public abstract class GCParser { page = Network.getResponseData(Network.postRequest(uri, params)); } - } catch (final Exception e) { + } catch (final RuntimeException e) { Log.e("GCParser.postLog.confim", e); } @@ -1094,7 +1090,7 @@ public abstract class GCParser { Log.i("Log successfully posted to cache #" + cacheid); if (geocode != null) { - cgData.saveVisitDate(geocode); + DataStore.saveVisitDate(geocode); } Login.getLoginStatus(page); @@ -1396,7 +1392,7 @@ public abstract class GCParser { trackable.setOwnerGuid(matcherOwner.group(1)); trackable.setOwner(matcherOwner.group(2).trim()); } - } catch (final Exception e) { + } catch (final RuntimeException e) { // failed to parse trackable owner name Log.w("GCParser.parseTrackable: Failed to parse trackable owner name"); } @@ -1427,7 +1423,7 @@ public abstract class GCParser { if (TextUtils.matches(page, GCConstants.PATTERN_TRACKABLE_SPOTTEDOWNER)) { trackable.setSpottedType(Trackable.SPOTTED_OWNER); } - } catch (final Exception e) { + } catch (final RuntimeException e) { // failed to parse trackable last known place Log.w("GCParser.parseTrackable: Failed to parse trackable last known place"); } @@ -1476,12 +1472,12 @@ public abstract class GCParser { trackable.setDetails(convertLinks(details)); } } - } catch (final Exception e) { + } catch (final RuntimeException e) { // failed to parse trackable details & image Log.w("GCParser.parseTrackable: Failed to parse trackable details & image"); } if (StringUtils.isEmpty(trackable.getDetails()) && page.contains(GCConstants.ERROR_TB_NOT_ACTIVATED)) { - trackable.setDetails(cgeoapplication.getInstance().getString(R.string.trackable_not_activated)); + trackable.setDetails(CgeoApplication.getInstance().getString(R.string.trackable_not_activated)); } // trackable logs @@ -1538,8 +1534,8 @@ public abstract class GCParser { trackable.setTrackingcode(possibleTrackingcode); } - if (cgeoapplication.getInstance() != null) { - cgData.saveTrackable(trackable); + if (CgeoApplication.getInstance() != null) { + DataStore.saveTrackable(trackable); } return trackable; @@ -1658,9 +1654,10 @@ public abstract class GCParser { return logs; } + @NonNull public static List<LogType> parseTypes(String page) { if (StringUtils.isEmpty(page)) { - return ListUtils.EMPTY_LIST; + return Collections.emptyList(); } final List<LogType> types = new ArrayList<LogType>(); |
