Skip to content
Browse files

Refactoring: Move some strings into GCConstants

Fix: issue with gc.com update

Tests are not green because mocked data was not updated.
  • Loading branch information...
1 parent 26364ec commit bfae2ebb59bb481a85ad4c19e9ce1fb7cec6248e @SammysHP SammysHP committed
View
2 main/src/cgeo/geocaching/cgCache.java
@@ -1386,7 +1386,7 @@ public void drop(Handler handler) {
public void checkFields() {
if (StringUtils.isBlank(getGeocode())) {
- Log.e("cgBase.loadLogsFromDetails: geo code not parsed correctly");
+ Log.e("geo code not parsed correctly");
}
if (StringUtils.isBlank(getName())) {
Log.e("name not parsed correctly");
View
13 main/src/cgeo/geocaching/connector/gc/GCConstants.java
@@ -28,7 +28,7 @@
public final static Pattern PATTERN_HINT = Pattern.compile("<div id=\"div_hint\"[^>]*>(.*?)</div>");
public final static Pattern PATTERN_DESC = Pattern.compile("<span id=\"ctl00_ContentBody_LongDescription\">(.*?)</span>[^<]*</div>[^<]*<p>[^<]*</p>[^<]*<p>[^<]*<strong>\\W*Additional Hints</strong>");
public final static Pattern PATTERN_SHORTDESC = Pattern.compile("<span id=\"ctl00_ContentBody_ShortDescription\">(.*?)</span>[^\\w^<]*</div>");
- public final static Pattern PATTERN_GEOCODE = Pattern.compile("<meta name=\"og:url\" content=\"[^\"]+/(GC[0-9A-Z]+)\"");
+ public final static Pattern PATTERN_GEOCODE = Pattern.compile("class=\"CoordInfoCode\">(GC[0-9A-Z]+)</span>");
public final static Pattern PATTERN_CACHEID = Pattern.compile("/seek/log\\.aspx\\?ID=(\\d+)");
public final static Pattern PATTERN_GUID = Pattern.compile(Pattern.quote("&wid=") + "([0-9a-z\\-]+)" + Pattern.quote("&"));
public final static Pattern PATTERN_SIZE = Pattern.compile("<div class=\"CacheSize[^\"]*\">[^<]*<p[^>]*>[^S]*Size[^:]*:[^<]*<span[^>]*>[^<]*<img src=\"[^\"]*/icons/container/[a-z_]+\\.gif\" alt=\"\\w+: ([^\"]+)\"[^>]*>[^<]*<small>[^<]*</small>[^<]*</span>[^<]*</p>");
@@ -155,6 +155,17 @@
/** Live Map since 14.02.2012 */
public final static Pattern PATTERN_USERSESSION = Pattern.compile("UserSession\\('([^']+)'");
public final static Pattern PATTERN_SESSIONTOKEN = Pattern.compile("sessionToken:'([^']+)'");
+
+ public final static String STRING_PREMIUMONLY_2 = "Sorry, the owner of this listing has made it viewable to Premium Members only.";
+ public final static String STRING_PREMIUMONLY_1 = "has chosen to make this cache listing visible to Premium Members only.";
+ public final static String STRING_UNPUBLISHED_OWNER = "Cache is Unpublished";
+ public final static String STRING_UNPUBLISHED_OTHER = "you cannot view this cache listing until it has been published";
+ public final static String STRING_UNKNOWN_ERROR = "An Error Has Occurred";
+ public final static String STRING_CACHEINFORMATIONTABLE = "<div id=\"ctl00_ContentBody_CacheInformationTable\" class=\"CacheInformationTable\">";
+ public final static String STRING_DISABLED = "<li>This cache is temporarily unavailable.";
+ public final static String STRING_ARCHIVED = "<li>This cache has been archived,";
+ public final static String STRING_CACHEDETAILS = "id=\"cacheDetails\"";
+
/** Number of logs to retrieve from GC.com */
public final static int NUMBER_OF_LOGS = 35;
View
19 main/src/cgeo/geocaching/connector/gc/GCParser.java
@@ -338,31 +338,26 @@ static SearchResult parseCacheFromText(final String page, final CancellableHandl
final SearchResult searchResult = new SearchResult();
- if (page.contains("Cache is Unpublished") || page.contains("you cannot view this cache listing until it has been published")) {
+ if (page.contains(GCConstants.STRING_UNPUBLISHED_OTHER) || page.contains(GCConstants.STRING_UNPUBLISHED_OWNER)) {
searchResult.setError(StatusCode.UNPUBLISHED_CACHE);
return searchResult;
}
- if (page.contains("Sorry, the owner of this listing has made it viewable to Premium Members only.")) {
- searchResult.setError(StatusCode.PREMIUM_ONLY);
- return searchResult;
- }
-
- if (page.contains("has chosen to make this cache listing visible to Premium Members only.")) {
+ if (page.contains(GCConstants.STRING_PREMIUMONLY_1) || page.contains(GCConstants.STRING_PREMIUMONLY_2)) {
searchResult.setError(StatusCode.PREMIUM_ONLY);
return searchResult;
}
final String cacheName = Html.fromHtml(BaseUtils.getMatch(page, GCConstants.PATTERN_NAME, true, "")).toString();
- if ("An Error Has Occurred".equalsIgnoreCase(cacheName)) {
+ if (GCConstants.STRING_UNKNOWN_ERROR.equalsIgnoreCase(cacheName)) {
searchResult.setError(StatusCode.UNKNOWN_ERROR);
return searchResult;
}
final cgCache cache = new cgCache();
- cache.setDisabled(page.contains("<li>This cache is temporarily unavailable."));
+ cache.setDisabled(page.contains(GCConstants.STRING_DISABLED));
- cache.setArchived(page.contains("<li>This cache has been archived,"));
+ cache.setArchived(page.contains(GCConstants.STRING_ARCHIVED));
cache.setPremiumMembersOnly(BaseUtils.matches(page, GCConstants.PATTERN_PREMIUMMEMBERS));
@@ -390,7 +385,7 @@ static SearchResult parseCacheFromText(final String page, final CancellableHandl
String tableInside = page;
- int pos = tableInside.indexOf("id=\"cacheDetails\"");
+ int pos = tableInside.indexOf(GCConstants.STRING_CACHEDETAILS);
if (pos == -1) {
Log.e("cgeoBase.parseCache: ID \"cacheDetails\" not found on page");
return null;
@@ -398,7 +393,7 @@ static SearchResult parseCacheFromText(final String page, final CancellableHandl
tableInside = tableInside.substring(pos);
- pos = tableInside.indexOf("<div class=\"CacheInformationTable\"");
+ pos = tableInside.indexOf(GCConstants.STRING_CACHEINFORMATIONTABLE);
if (pos == -1) {
Log.e("cgeoBase.parseCache: class \"CacheInformationTable\" not found on page");
return null;

0 comments on commit bfae2eb

Please sign in to comment.
Something went wrong with that request. Please try again.