aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/cgBase.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/cgeo/geocaching/cgBase.java')
-rw-r--r--src/cgeo/geocaching/cgBase.java162
1 files changed, 34 insertions, 128 deletions
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java
index b17c7f8..3a5c3b6 100644
--- a/src/cgeo/geocaching/cgBase.java
+++ b/src/cgeo/geocaching/cgBase.java
@@ -95,7 +95,7 @@ public class cgBase {
public static DateFormat dateOutShort = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
private Resources res = null;
private HashMap<String, String> cookies = new HashMap<String, String>();
- private final String passMatch = "[/\\?&]*[Pp]ass(word)?=[^&^#^$]+";
+ private static final String passMatch = "[/\\?&]*[Pp]ass(word)?=[^&^#^$]+";
private final Pattern patternLoggedIn = Pattern.compile("<span class=\"Success\">You are logged in as[^<]*<strong[^>]*>([^<]+)</strong>[^<]*</span>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
private final Pattern patternLogged2In = Pattern.compile("<strong>[^\\w]*Hello,[^<]*<a[^>]+>([^<]+)</a>[^<]*</strong>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
private final Pattern patternViewstate = Pattern.compile("id=\"__VIEWSTATE\"[^(value)]+value=\"([^\"]+)\"[^>]+>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
@@ -104,9 +104,6 @@ public class cgBase {
public static final double deg2rad = Math.PI / 180;
public static final double rad2deg = 180 / Math.PI;
public static final float erad = 6371.0f;
- public static final int mapAppAny = 0;
- public static final int mapAppLocus = 1;
- public static final int mapAppRmaps = 2;
private cgeoapplication app = null;
private cgSettings settings = null;
private SharedPreferences prefs = null;
@@ -1099,6 +1096,7 @@ public class cgBase {
final Pattern patternCountLog = Pattern.compile(" src=\"\\/images\\/icons\\/([^\\.]*).gif\" alt=\"[^\"]*\" title=\"[^\"]*\" />([0-9]*)[^0-9]+", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
final Pattern patternLogs = Pattern.compile("<table class=\"LogsTable[^\"]*\"[^>]*>[^<]*<tr>(.*)</tr>[^<]*</table>[^<]*<p", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
final Pattern patternLog = Pattern.compile("<td[^>]*>[^<]*<strong>[^<]*<img src=\"[^\"]*/images/icons/([^\\.]+)\\.[a-z]{2,5}\"[^>]*>&nbsp;([a-zA-Z]+) (\\d+)(, (\\d+))? by <a href=[^>]+>([^<]+)</a>[<^]*</strong>([^\\(]*\\((\\d+) found\\))?(<br[^>]*>)+((?:(?!<small>).)*)(<br[^>]*>)+<small>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
+ final Pattern patternLogImgs = Pattern.compile("a href=\"http://img.geocaching.com/cache/log/([^\"]+)\".+?<span>([^<]*)", Pattern.CASE_INSENSITIVE);
final Pattern patternAttributes = Pattern.compile("<h3 class=\"WidgetHeader\">[^<]*<img[^>]+>[^\\w]*Attributes[^<]*</h3>[^<]*<div class=\"WidgetBody\">(([^<]*<img src=\"[^\"]+\" alt=\"[^\"]+\"[^>]*>)+)[^<]*<p", Pattern.CASE_INSENSITIVE);
final Pattern patternAttributesInside = Pattern.compile("[^<]*<img src=\"([^\"]+)\" alt=\"([^\"]+)\"[^>]*>", Pattern.CASE_INSENSITIVE);
final Pattern patternSpoilers = Pattern.compile("<span id=\"ctl00_ContentBody_Images\">((<a href=\"[^\"]+\"[^>]*>[^<]*<img[^>]+>[^<]*<span>[^>]+</span>[^<]*</a>[^<]*<br[^>]*>([^<]*(<br[^>]*>)+)?)+)[^<]*</span>", Pattern.CASE_INSENSITIVE);
@@ -1513,7 +1511,7 @@ public class cgBase {
while (matcherSpoilersInside.find()) {
if (matcherSpoilersInside.groupCount() > 0) {
- final cgSpoiler spoiler = new cgSpoiler();
+ final cgImage spoiler = new cgImage();
spoiler.url = matcherSpoilersInside.group(1);
if (matcherSpoilersInside.group(2) != null) {
@@ -1524,7 +1522,7 @@ public class cgBase {
}
if (cache.spoilers == null) {
- cache.spoilers = new ArrayList<cgSpoiler>();
+ cache.spoilers = new ArrayList<cgImage>();
}
cache.spoilers.add(spoiler);
}
@@ -1695,6 +1693,19 @@ public class cgBase {
if (matcherLog.group(8) != null) {
logDone.found = new Integer(matcherLog.group(8));
}
+
+ final Matcher matcherImg = patternLogImgs.matcher(logs[k]);
+
+ while (matcherImg.find()) {
+ final cgImage logImage = new cgImage();
+ logImage.url = "http://img.geocaching.com/cache/log/" + matcherImg.group(1);
+ logImage.title = matcherImg.group(2);
+ if (logDone.logImages == null) {
+ logDone.logImages = new ArrayList<cgImage>();
+ }
+ logDone.logImages.add(logImage);
+ }
+
logDone.log = logTmp;
if (cache.logs == null) {
@@ -1877,7 +1888,7 @@ public class cgBase {
return caches;
}
- private Date parseDate(String input) {
+ private static Date parseDate(String input) {
if (input == null) {
return null;
}
@@ -3967,7 +3978,7 @@ public class cgBase {
return -1; // error
}
- boolean guidOnPage = checkPageForGuid(cache, page);
+ boolean guidOnPage = cache.isGuidContainedInPage(page);
if (guidOnPage) {
Log.i(cgSettings.tag, "cgBase.addToWatchlist: cache is on watchlist");
cache.onWatchlist = true;
@@ -4008,7 +4019,7 @@ public class cgBase {
params.put("ctl00$ContentBody$btnYes", "Yes");
page = request(false, host, path, method, params, false, false, false).getData();
- boolean guidOnPage = checkPageForGuid(cache, page);
+ boolean guidOnPage = cache.isGuidContainedInPage(page);
if (! guidOnPage) {
Log.i(cgSettings.tag, "cgBase.removeFromWatchlist: cache removed from watchlist");
cache.onWatchlist = false;
@@ -4018,29 +4029,6 @@ public class cgBase {
return guidOnPage ? -1 : 0; // on watchlist (=error) / not on watchlist
}
- /**
- * checks if a page contains the guid of a cache
- *
- * @param cache the cache to look for
- * @param page the page to search in
- *
- * @return true: page contains guid of cache, false: otherwise
- */
- private boolean checkPageForGuid(cgCache cache, String page) {
- // check if the guid of the cache is anywhere in the page
- if (cache.guid == null || cache.guid.length() == 0)
- return false;
- Pattern patternOk = Pattern.compile(cache.guid, Pattern.CASE_INSENSITIVE);
- Matcher matcherOk = patternOk.matcher(page);
- if (matcherOk.find()) {
- Log.i(cgSettings.tag, "cgBase.checkPageForGuid: guid '" + cache.guid + "' found");
- return true;
- } else {
- Log.i(cgSettings.tag, "cgBase.checkPageForGuid: guid '" + cache.guid + "' not found");
- return false;
- }
- }
-
final public static HostnameVerifier doNotVerify = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
@@ -4181,7 +4169,7 @@ public class cgBase {
}
}
- private void readIntoBuffer(BufferedReader br, StringBuffer buffer) throws IOException {
+ private static void readIntoBuffer(BufferedReader br, StringBuffer buffer) throws IOException {
int bufferSize = 1024*16;
char[] bytes = new char[bufferSize];
int bytesRead;
@@ -4195,99 +4183,6 @@ public class cgBase {
}
}
- /*
- public ArrayList<String> translate(ArrayList<String> text, String target) {
- if (settings.translate == false) {
- return text;
- }
-
- String[] languages = null;
- if (settings.languages != null) {
- languages = settings.languages.split(" ");
- }
-
- ArrayList<String> translated = new ArrayList<String>();
- String language = null;
-
- if (text == null || text.isEmpty()) {
- return text;
- }
-
- // cut to 5000 characters (limitation of Google Translation API)
- for (String textOne : text) {
- int len = urlencode_rfc3986(textOne).length();
- if (len > 5000) {
- textOne = Html.fromHtml(textOne).toString();
- len = urlencode_rfc3986(textOne).length();
-
- if (len > 5000) {
- int cut = 2000;
- if (textOne.length() > cut) {
- cut = 1000;
- }
-
- textOne = textOne.substring(0, cut) + "...";
- }
- }
- }
-
- try {
- if (target == null) {
- final Locale locale = Locale.getDefault();
- target = locale.getLanguage();
- }
-
- final String scheme = "https://";
- final String host = "www.googleapis.com";
- final String path = "/language/translate/v2";
-
- final ArrayList<String> params = new ArrayList<String>();
- params.add("key=" + urlencode_rfc3986("AIzaSyAJH8x5etFHUbFifmgChlWoCVmwBFSwShQ"));
- params.add("target=" + urlencode_rfc3986(target));
- for (String textOne : text) {
- params.add("q=" + urlencode_rfc3986(textOne));
- }
- params.add("format=" + urlencode_rfc3986("html"));
-
- String page = requestJSON(scheme, host, path, "POST", implode("&", params.toArray()));
-
- if (page == null || page.length() == 0) {
- return text;
- }
-
- JSONObject json = new JSONObject(page);
- JSONObject jsonData = json.getJSONObject("data");
- JSONArray jsonTranslations = jsonData.getJSONArray("translations");
- int translationCnt = jsonTranslations.length();
-
- for (int i = 0; i < translationCnt; i ++) {
- JSONObject jsonTranslation = jsonTranslations.getJSONObject(i);
- language = jsonTranslation.getString("detectedSourceLanguage");
-
- boolean toTranslate = true;
- if (languages != null) {
- for (String lng : languages) {
- if (lng.equalsIgnoreCase(language)) {
- toTranslate = false;
- }
- }
- }
-
- if (toTranslate == false) {
- translated.add(text.get(i));
- } else {
- Log.i(cgSettings.tag, "Translating #" + i + ": " + language + ">" + target);
- translated.add(jsonTranslation.getString("translatedText"));
- }
- }
- } catch (Exception e) {
- Log.w(cgSettings.tag, "cgBase.translate: " + e.toString());
- }
-
- return translated;
- }
- */
-
public String getLocalIpAddress() {
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
@@ -4671,7 +4566,7 @@ public class cgBase {
return response;
}
- private String replaceWhitespace(final StringBuffer buffer) {
+ private static String replaceWhitespace(final StringBuffer buffer) {
final int length = buffer.length();
final char[] bytes = new char[length];
buffer.getChars(0, length, bytes, 0);
@@ -5135,10 +5030,21 @@ public class cgBase {
// store spoilers
if (cache.spoilers != null && cache.spoilers.isEmpty() == false) {
- for (cgSpoiler oneSpoiler : cache.spoilers) {
+ for (cgImage oneSpoiler : cache.spoilers) {
imgGetter.getDrawable(oneSpoiler.url);
}
}
+
+ // store images from logs
+ if (settings.storelogimages == true) {
+ for (cgLog log : cache.logs) {
+ if (log.logImages != null && log.logImages.isEmpty() == false) {
+ for (cgImage oneLogImg : log.logImages) {
+ imgGetter.getDrawable(oneLogImg.url);
+ }
+ }
+ }
+ }
// store map previews
if (settings.storeOfflineMaps == 1 && cache.latitude != null && cache.longitude != null) {