aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/connector/gc/GCParser.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/connector/gc/GCParser.java')
-rw-r--r--main/src/cgeo/geocaching/connector/gc/GCParser.java63
1 files changed, 32 insertions, 31 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java
index 7dc048a..7eacb8e 100644
--- a/main/src/cgeo/geocaching/connector/gc/GCParser.java
+++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java
@@ -131,15 +131,15 @@ public abstract class GCParser {
while (matcherGuidAndDisabled.find()) {
if (matcherGuidAndDisabled.groupCount() > 0) {
- cache.setGuid(matcherGuidAndDisabled.group(1));
- if (matcherGuidAndDisabled.group(4) != null) {
- cache.setName(Html.fromHtml(matcherGuidAndDisabled.group(4).trim()).toString());
+ //cache.setGuid(matcherGuidAndDisabled.group(1));
+ if (matcherGuidAndDisabled.group(2) != null) {
+ cache.setName(Html.fromHtml(matcherGuidAndDisabled.group(2).trim()).toString());
}
- if (matcherGuidAndDisabled.group(6) != null) {
- cache.setLocation(Html.fromHtml(matcherGuidAndDisabled.group(6).trim()).toString());
+ if (matcherGuidAndDisabled.group(3) != null) {
+ cache.setLocation(Html.fromHtml(matcherGuidAndDisabled.group(3).trim()).toString());
}
- final String attr = matcherGuidAndDisabled.group(2);
+ final String attr = matcherGuidAndDisabled.group(1);
if (attr != null) {
cache.setDisabled(attr.contains("Strike"));
@@ -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");
}
@@ -238,7 +238,7 @@ public abstract class GCParser {
cache.setPremiumMembersOnly(row.contains("/images/icons/16/premium_only.png"));
// found it
- cache.setFound(row.contains("/images/icons/16/found.png"));
+ cache.setFound(row.contains("/images/icons/16/found.png") || row.contains("uxUserLogDate\" class=\"Success\""));
// id
String result = TextUtils.getMatch(row, GCConstants.PATTERN_SEARCH_ID, null);
@@ -309,7 +309,7 @@ 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")) {
+ if (coordinates != null && 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);
@@ -320,7 +320,7 @@ public abstract class GCParser {
LocParser.parseLoc(searchResult, coordinates);
- } catch (final Exception e) {
+ } catch (final RuntimeException e) {
Log.e("GCParser.parseSearch.CIDs", e);
}
}
@@ -529,9 +529,7 @@ public abstract class GCParser {
if (result != null) {
// replace linebreak and paragraph tags
final String hint = GCConstants.PATTERN_LINEBREAK.matcher(result).replaceAll("\n");
- if (hint != null) {
- cache.setHint(StringUtils.replace(hint, "</p>", "").trim());
- }
+ cache.setHint(StringUtils.replace(hint, "</p>", "").trim());
}
cache.checkFields();
@@ -571,7 +569,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");
}
@@ -600,7 +598,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");
}
@@ -634,7 +632,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)");
}
@@ -656,7 +654,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");
}
@@ -766,7 +764,7 @@ public abstract class GCParser {
public static SearchResult searchByNextPage(final SearchResult search, boolean showCaptcha, RecaptchaReceiver recaptchaReceiver) {
if (search == null) {
- return search;
+ return null;
}
final String[] viewstates = search.getViewstates();
@@ -1085,7 +1083,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);
}
@@ -1131,9 +1129,9 @@ public abstract class GCParser {
* @return status code to indicate success or failure
*/
public static ImmutablePair<StatusCode, String> uploadLogImage(final String logId, final String caption, final String description, final Uri imageUri) {
- final String uri = new Uri.Builder().scheme("http").authority("www.geocaching.com").path("/seek/upload.aspx").build().toString();
+ final String uri = new Uri.Builder().scheme("http").authority("www.geocaching.com").path("/seek/upload.aspx").encodedQuery("LID=" + logId).build().toString();
- final String page = Login.getRequestLogged(uri, new Parameters("LID=", logId));
+ final String page = Login.getRequestLogged(uri, null);
if (StringUtils.isBlank(page)) {
Log.e("GCParser.uploadLogImage: No data from server");
return new ImmutablePair<StatusCode, String>(StatusCode.UNKNOWN_ERROR, null);
@@ -1398,7 +1396,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");
}
@@ -1429,22 +1427,25 @@ 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");
}
// released date - can be missing on the page
- try {
- final String releaseString = TextUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_RELEASES, false, null);
- if (releaseString != null) {
+ final String releaseString = TextUtils.getMatch(page, GCConstants.PATTERN_TRACKABLE_RELEASES, false, null);
+ if (releaseString != null) {
+ try {
trackable.setReleased(dateTbIn1.parse(releaseString));
+ } catch (ParseException e) {
if (trackable.getReleased() == null) {
- trackable.setReleased(dateTbIn2.parse(releaseString));
+ try {
+ trackable.setReleased(dateTbIn2.parse(releaseString));
+ } catch (ParseException e1) {
+ Log.e("Could not parse trackable release " + releaseString);
+ }
}
}
- } catch (final ParseException e1) {
- trackable.setReleased(null);
}
// trackable distance
@@ -1475,7 +1476,7 @@ 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");
}
@@ -1717,7 +1718,7 @@ public abstract class GCParser {
try {
final Integer ctl = Integer.valueOf(trackableMatcher.group(3));
final Integer id = Integer.valueOf(trackableMatcher.group(5));
- if (trackCode != null && name != null && ctl != null && id != null) {
+ if (trackCode != null && ctl != null && id != null) {
final TrackableLog entry = new TrackableLog(trackCode, name, id, ctl);
Log.i("Trackable in inventory (#" + entry.ctl + "/" + entry.id + "): " + entry.trackCode + " - " + entry.name);