diff options
| author | SammysHP <sven@sammyshp.de> | 2011-08-25 22:51:07 +0200 |
|---|---|---|
| committer | SammysHP <sven@sammyshp.de> | 2011-08-25 22:51:07 +0200 |
| commit | 8c6b1528600d0cef981e18c703d39f260b541b1b (patch) | |
| tree | 9c835b2b4667b7d2b67a045e0c01e7c1f86ab0eb /src | |
| parent | 24b958dbf55fd01cd5c932761847dab67d346b0d (diff) | |
| download | cgeo-8c6b1528600d0cef981e18c703d39f260b541b1b.zip cgeo-8c6b1528600d0cef981e18c703d39f260b541b1b.tar.gz cgeo-8c6b1528600d0cef981e18c703d39f260b541b1b.tar.bz2 | |
Fix log count (number of Found It, Didn't found it, Published...)
Diffstat (limited to 'src')
| -rw-r--r-- | src/cgeo/geocaching/cgBase.java | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/src/cgeo/geocaching/cgBase.java b/src/cgeo/geocaching/cgBase.java index e8e23ac..e143ab7 100644 --- a/src/cgeo/geocaching/cgBase.java +++ b/src/cgeo/geocaching/cgBase.java @@ -91,8 +91,8 @@ public class cgBase { private final static Pattern patternPersonalNote = Pattern.compile("<p id=\"cache_note\"[^>]*>([^<]*)</p>", Pattern.CASE_INSENSITIVE); private final static Pattern patternDescShort = Pattern.compile("<div class=\"UserSuppliedContent\">[^<]*<span id=\"ctl00_ContentBody_ShortDescription\"[^>]*>((?:(?!</span>[^\\w^<]*</div>).)*)</span>[^\\w^<]*</div>", Pattern.CASE_INSENSITIVE); private final static Pattern patternDesc = Pattern.compile("<span id=\"ctl00_ContentBody_LongDescription\"[^>]*>" + "(.*)</span>[^<]*</div>[^<]*<p>[^<]*</p>[^<]*<p>[^<]*<strong>\\W*Additional Hints</strong>", Pattern.CASE_INSENSITIVE); - private final static Pattern patternCountLogs = Pattern.compile("<span id=\"ctl00_ContentBody_lblFindCounts\"><p>(.*)<\\/p><\\/span>", Pattern.CASE_INSENSITIVE); - private final static Pattern patternCountLog = Pattern.compile(" src=\"\\/images\\/icons\\/([^\\.]*).gif\" alt=\"[^\"]*\" title=\"[^\"]*\" />([0-9]*)[^0-9]+", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); + private final static Pattern patternCountLogs = Pattern.compile("<span id=\"ctl00_ContentBody_lblFindCounts\"><p(.+?)<\\/p><\\/span>", Pattern.CASE_INSENSITIVE); + private final static Pattern patternCountLog = Pattern.compile("src=\"\\/images\\/icons\\/(.+?).gif\"[^>]+> (\\d+)", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); //private final static Pattern patternLogs = Pattern.compile("<table class=\"LogsTable\">(.*?)</table>\\s*<p", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); private final static Pattern patternLog = Pattern.compile("<tr><td class.+?<a href=\"/profile/\\?guid=.+?>(.+?)</a>.+?(?:logOwnerStats[^>]+><img[^>]+icon_smile.+?> ([,\\d]+).+?)?LogType.+?<img.+?/images/icons/([^\\.]+)\\..+?title=\"(.+?)\".+?LogDate.+?>(.+?)<.+?LogText.+?>(.*?)</p>(.*?)</div></div></div></td></tr>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); private final static Pattern patternLogImgs = Pattern.compile("href=\"(http://img.geocaching.com/cache/log/.+?)\".+?<span>([^<]*)", Pattern.CASE_INSENSITIVE); @@ -1550,37 +1550,32 @@ public class cgBase { } // cache logs counts - try { + try + { final Matcher matcherLogCounts = patternCountLogs.matcher(page); - while (matcherLogCounts.find()) { - if (matcherLogCounts.groupCount() > 0) { - final String[] logs = matcherLogCounts.group(1).split("<img"); - final int logsCnt = logs.length; - - for (int k = 1; k < logsCnt; k++) { - Integer type = null; - Integer count = null; - final Matcher matcherLog = patternCountLog.matcher(logs[k]); + + if (matcherLogCounts.find()) + { + final Matcher matcherLog = patternCountLog.matcher(matcherLogCounts.group(1)); - if (matcherLog.find()) { - String typeStr = matcherLog.group(1); - String countStr = matcherLog.group(2); - if (typeStr != null && typeStr.length() > 0) { - if (logTypes.containsKey(typeStr.toLowerCase())) { - type = logTypes.get(typeStr.toLowerCase()); - } - } - if (countStr != null && countStr.length() > 0) { - count = Integer.parseInt(countStr); - } - if (type != null && count != null) { - cache.logCounts.put(type, count); - } - } + while (matcherLog.find()) + { + String typeStr = matcherLog.group(1); + String countStr = matcherLog.group(2); + + if (typeStr != null + && typeStr.length() > 0 + && logTypes.containsKey(typeStr.toLowerCase()) + && countStr != null + && countStr.length() > 0) + { + cache.logCounts.put(logTypes.get(typeStr.toLowerCase()), Integer.parseInt(countStr)); } } } - } catch (Exception e) { + } + catch (Exception e) + { // failed to parse logs Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache log count"); } |
