diff options
author | Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> | 2015-05-08 17:10:06 +0200 |
---|---|---|
committer | Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> | 2015-10-11 23:55:58 +0200 |
commit | 8ff62c5f34db48aa15c7252c40fea3381bba0952 (patch) | |
tree | 2a0ffd9bcf9a2648c45f170426cf86fb319509f2 /main/src/cgeo/geocaching/utils/CheckerUtils.java | |
parent | 1d2b34e71a01d6af118ed89258ad0ecb983e1a9c (diff) | |
parent | 59b8b2e26a7fff6072c4d5d96f51035dc900e0bc (diff) | |
download | cgeo-8ff62c5f34db48aa15c7252c40fea3381bba0952.zip cgeo-8ff62c5f34db48aa15c7252c40fea3381bba0952.tar.gz cgeo-8ff62c5f34db48aa15c7252c40fea3381bba0952.tar.bz2 |
merge upstream
Diffstat (limited to 'main/src/cgeo/geocaching/utils/CheckerUtils.java')
-rw-r--r-- | main/src/cgeo/geocaching/utils/CheckerUtils.java | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/utils/CheckerUtils.java b/main/src/cgeo/geocaching/utils/CheckerUtils.java new file mode 100644 index 0000000..39ef078 --- /dev/null +++ b/main/src/cgeo/geocaching/utils/CheckerUtils.java @@ -0,0 +1,35 @@ +package cgeo.geocaching.utils; + +import cgeo.geocaching.Geocache; + +import org.apache.commons.lang3.StringEscapeUtils; +import org.apache.commons.lang3.StringUtils; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; + +import android.util.Patterns; + +import java.util.regex.Matcher; + +public final class CheckerUtils { + private static final String[] CHECKERS = new String[] { "geocheck.org", "geochecker.com", "certitudes.org" }; + + private CheckerUtils() { + // utility class + } + + @Nullable + public static String getCheckerUrl(@NonNull final Geocache cache) { + final String description = cache.getDescription(); + final Matcher matcher = Patterns.WEB_URL.matcher(description); + while (matcher.find()) { + final String url = matcher.group(); + for (final String checker : CHECKERS) { + if (StringUtils.containsIgnoreCase(url, checker)) { + return StringEscapeUtils.unescapeHtml4(url); + } + } + } + return null; + } +} |