Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d001f8
commit 0f28169
Showing
6 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package cgeo.geocaching.utils; | ||
|
||
import cgeo.geocaching.Geocache; | ||
|
||
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 url; | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package cgeo.geocaching.utils; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import cgeo.geocaching.Geocache; | ||
|
||
import junit.framework.TestCase; | ||
|
||
public class CheckerUtilsTest extends TestCase { | ||
|
||
public static void testGetCheckerUrl() throws Exception { | ||
assertUrl("<p style=\"text-align:center;\"><a href=\"http://geocheck.org/geo_inputchkcoord.php?gid=618932716cc7e68-c4bb-4f41-8bb1-3e0a3e374a1f\" target=\"_blank\"><img", "http://geocheck.org/geo_inputchkcoord.php?gid=618932716cc7e68-c4bb-4f41-8bb1-3e0a3e374a1f"); | ||
assertUrl("<p style=\"text-align:center;\"><a href=\"http://google.com/geo_inputchkcoord.php?gid=618932716cc7e68-c4bb-4f41-8bb1-3e0a3e374a1f\" target=\"_blank\"><img", null); | ||
assertUrl("http://www.certitudes.org/certitude?wp=GC5MVX7", "http://www.certitudes.org/certitude?wp=GC5MVX7"); | ||
assertUrl("http://geochecker.com/index.php?code=e001928e3c2682ec2bae0f24b9d02cfb&action=check&wp=474350573454&name=47656f636865636b6572205465737420666f72204e33382030302e303030205737362030302e303030", "http://geochecker.com/index.php?code=e001928e3c2682ec2bae0f24b9d02cfb&action=check&wp=474350573454&name=47656f636865636b6572205465737420666f72204e33382030302e303030205737362030302e303030"); | ||
} | ||
|
||
private static void assertUrl(final String description, final String expected) { | ||
final Geocache geocache = new Geocache(); | ||
geocache.setDescription(description); | ||
assertThat(CheckerUtils.getCheckerUrl(geocache)).isEqualTo(expected); | ||
} | ||
|
||
} |