aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/utils/CheckerUtils.java
blob: 39ef078e78636281365bcb7127afbf15035eb026 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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;
    }
}