diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2014-02-28 21:21:30 +0100 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2014-02-28 21:21:30 +0100 |
| commit | b738cfa8fea4a6ac1eacdf23c66b8ddb1de76565 (patch) | |
| tree | ffdd9d9d027ca99e6b945948c5242e61d692d6aa /main/src/cgeo/geocaching/connector | |
| parent | b9b4e7e7ec541e97b5948f8469d1c93dd9b7f3e5 (diff) | |
| download | cgeo-b738cfa8fea4a6ac1eacdf23c66b8ddb1de76565.zip cgeo-b738cfa8fea4a6ac1eacdf23c66b8ddb1de76565.tar.gz cgeo-b738cfa8fea4a6ac1eacdf23c66b8ddb1de76565.tar.bz2 | |
refactoring: move GC specific code in GCParser
Diffstat (limited to 'main/src/cgeo/geocaching/connector')
| -rw-r--r-- | main/src/cgeo/geocaching/connector/gc/GCParser.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/main/src/cgeo/geocaching/connector/gc/GCParser.java b/main/src/cgeo/geocaching/connector/gc/GCParser.java index 9d6762b..8e59e5e 100644 --- a/main/src/cgeo/geocaching/connector/gc/GCParser.java +++ b/main/src/cgeo/geocaching/connector/gc/GCParser.java @@ -62,6 +62,7 @@ import java.util.GregorianCalendar; import java.util.List; import java.util.Locale; import java.util.Set; +import java.util.regex.Pattern; public abstract class GCParser { private final static SynchronizedDateFormat dateTbIn1 = new SynchronizedDateFormat("EEEEE, dd MMMMM yyyy", Locale.ENGLISH); // Saturday, 28 March 2009 @@ -1310,7 +1311,7 @@ public abstract class GCParser { return false; // error } - final boolean guidOnPage = cache.isGuidContainedInPage(page); + final boolean guidOnPage = isGuidContainedInPage(cache, page); if (guidOnPage) { Log.i("GCParser.addToWatchlist: cache is on watchlist"); cache.setOnWatchlist(true); @@ -1344,7 +1345,7 @@ public abstract class GCParser { GCLogin.transferViewstates(page, params); page = Network.getResponseData(Network.postRequest(uri, params)); - final boolean guidOnPage = cache.isGuidContainedInPage(page); + final boolean guidOnPage = isGuidContainedInPage(cache, page); if (!guidOnPage) { Log.i("GCParser.removeFromWatchlist: cache removed from watchlist"); cache.setOnWatchlist(false); @@ -1354,6 +1355,21 @@ public abstract class GCParser { return !guidOnPage; // on watch list (=error) / not on watch list } + /** + * Checks if a page contains the guid of a cache + * + * @param cache the geocache + * @param page + * the page to search in, may be null + * @return true if the page contains the guid of the cache, false otherwise + */ + private static boolean isGuidContainedInPage(final Geocache cache, final String page) { + if (StringUtils.isBlank(page) || StringUtils.isBlank(cache.getGuid())) { + return false; + } + return Pattern.compile(cache.getGuid(), Pattern.CASE_INSENSITIVE).matcher(page).find(); + } + @Nullable static String requestHtmlPage(@Nullable final String geocode, @Nullable final String guid, final String log, final String numlogs) { final Parameters params = new Parameters("decrypt", "y"); |
