List of usage examples for java.util.regex Pattern MULTILINE
int MULTILINE
To view the source code for java.util.regex Pattern MULTILINE.
Click Source Link
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public String getRenewalCount(String strStatus) { String renewCount = null;/*from w w w. j a va2 s .c o m*/ //String beginStr1 = null; String lookupPattern = "^(.*?)<span class=\"patFuncRenewCount\">Renewed(.*?)(time.*)(.*?)$"; Pattern findPattern = Pattern.compile(lookupPattern, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher findPatternMatch = findPattern.matcher(strStatus); //LOG.debug("strCount in getRenewalCount: " + strStatus); //int y = 1; while (findPatternMatch.find()) { renewCount = findPatternMatch.group(2).trim(); //LOG.debug("group1: " + findPatternMatch.group(1).trim()); //LOG.debug("group2: " + findPatternMatch.group(2).trim()); //LOG.debug("group3: " + findPatternMatch.group(3).trim()); //LOG.debug("group4: " + findPatternMatch.group(4).trim()); //LOG.debug("Process: " + y + " - renewCount: " + renewCount); //y++; } return renewCount; }
From source file:cgeo.geocaching.cgBase.java
public int postLog(cgeoapplication app, String geocode, String cacheid, String[] viewstates, int logType, int year, int month, int day, String log, List<cgTrackableLog> trackables) { if (isEmpty(viewstates)) { Log.e(cgSettings.tag, "cgeoBase.postLog: No viewstate given"); return 1000; }//from w ww. j a va 2 s . co m if (logTypes2.containsKey(logType) == false) { Log.e(cgSettings.tag, "cgeoBase.postLog: Unknown logtype"); return 1000; } if (StringUtils.isBlank(log)) { Log.e(cgSettings.tag, "cgeoBase.postLog: No log text given"); return 1001; } // fix log (non-Latin characters converted to HTML entities) final int logLen = log.length(); final StringBuilder logUpdated = new StringBuilder(); for (int i = 0; i < logLen; i++) { char c = log.charAt(i); if (c > 300) { logUpdated.append("&#"); logUpdated.append(Integer.toString((int) c)); logUpdated.append(';'); } else { logUpdated.append(c); } } log = logUpdated.toString(); log = log.replace("\n", "\r\n"); // windows' eol if (trackables != null) { Log.i(cgSettings.tag, "Trying to post log for cache #" + cacheid + " - action: " + logType + "; date: " + year + "." + month + "." + day + ", log: " + log + "; trackables: " + trackables.size()); } else { Log.i(cgSettings.tag, "Trying to post log for cache #" + cacheid + " - action: " + logType + "; date: " + year + "." + month + "." + day + ", log: " + log + "; trackables: 0"); } final String host = "www.geocaching.com"; final String path = "/seek/log.aspx?ID=" + cacheid; final String method = "POST"; final Map<String, String> params = new HashMap<String, String>(); setViewstates(viewstates, params); params.put("__EVENTTARGET", ""); params.put("__EVENTARGUMENT", ""); params.put("__LASTFOCUS", ""); params.put("ctl00$ContentBody$LogBookPanel1$ddLogType", Integer.toString(logType)); params.put("ctl00$ContentBody$LogBookPanel1$DateTimeLogged", String.format("%02d", month) + "/" + String.format("%02d", day) + "/" + String.format("%04d", year)); params.put("ctl00$ContentBody$LogBookPanel1$DateTimeLogged$Month", Integer.toString(month)); params.put("ctl00$ContentBody$LogBookPanel1$DateTimeLogged$Day", Integer.toString(day)); params.put("ctl00$ContentBody$LogBookPanel1$DateTimeLogged$Year", Integer.toString(year)); params.put("ctl00$ContentBody$LogBookPanel1$uxLogInfo", log); params.put("ctl00$ContentBody$LogBookPanel1$LogButton", "Submit Log Entry"); params.put("ctl00$ContentBody$uxVistOtherListingGC", ""); if (trackables != null && trackables.isEmpty() == false) { // we have some trackables to proceed final StringBuilder hdnSelected = new StringBuilder(); for (cgTrackableLog tb : trackables) { final String action = Integer.toString(tb.id) + logTypesTrackableAction.get(tb.action); if (tb.action > 0) { hdnSelected.append(action); hdnSelected.append(','); } } params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$hdnSelectedActions", hdnSelected.toString()); // selected trackables params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$hdnCurrentFilter", ""); } String page = request(false, host, path, method, params, false, false, false).getData(); if (checkLogin(page) == false) { int loginState = login(); if (loginState == 1) { page = request(false, host, path, method, params, false, false, false).getData(); } else { Log.e(cgSettings.tag, "cgeoBase.postLog: Can not log in geocaching (error: " + loginState + ")"); return loginState; } } if (StringUtils.isBlank(page)) { Log.e(cgSettings.tag, "cgeoBase.postLog: No data from server"); return 1002; } // maintenance, archived needs to be confirmed final Pattern pattern = Pattern.compile( "<span id=\"ctl00_ContentBody_LogBookPanel1_lbConfirm\"[^>]*>([^<]*<font[^>]*>)?([^<]+)(</font>[^<]*)?</span>", Pattern.CASE_INSENSITIVE); final Matcher matcher = pattern.matcher(page); try { if (matcher.find() && matcher.groupCount() > 0) { final String[] viewstatesConfirm = getViewstates(page); if (isEmpty(viewstatesConfirm)) { Log.e(cgSettings.tag, "cgeoBase.postLog: No viewstate for confirm log"); return 1000; } params.clear(); setViewstates(viewstatesConfirm, params); params.put("__EVENTTARGET", ""); params.put("__EVENTARGUMENT", ""); params.put("__LASTFOCUS", ""); params.put("ctl00$ContentBody$LogBookPanel1$btnConfirm", "Yes"); params.put("ctl00$ContentBody$LogBookPanel1$uxLogInfo", log); params.put("ctl00$ContentBody$uxVistOtherListingGC", ""); if (trackables != null && trackables.isEmpty() == false) { // we have some trackables to proceed final StringBuilder hdnSelected = new StringBuilder(); for (cgTrackableLog tb : trackables) { String ctl = null; final String action = Integer.toString(tb.id) + logTypesTrackableAction.get(tb.action); if (tb.ctl < 10) { ctl = "0" + Integer.toString(tb.ctl); } else { ctl = Integer.toString(tb.ctl); } params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$repTravelBugs$ctl" + ctl + "$ddlAction", action); if (tb.action > 0) { hdnSelected.append(action); hdnSelected.append(','); } } params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$hdnSelectedActions", hdnSelected.toString()); // selected trackables params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$hdnCurrentFilter", ""); } page = request(false, host, path, method, params, false, false, false).getData(); } } catch (Exception e) { Log.e(cgSettings.tag, "cgeoBase.postLog.confim: " + e.toString()); } try { final Pattern patternOk = Pattern.compile( "<h2[^>]*>[^<]*<span id=\"ctl00_ContentBody_lbHeading\"[^>]*>[^<]*</span>[^<]*</h2>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); final Matcher matcherOk = patternOk.matcher(page); if (matcherOk.find()) { Log.i(cgSettings.tag, "Log successfully posted to cache #" + cacheid); if (app != null && geocode != null) { app.saveVisitDate(geocode); } return 1; } } catch (Exception e) { Log.e(cgSettings.tag, "cgeoBase.postLog.check: " + e.toString()); } Log.e(cgSettings.tag, "cgeoBase.postLog: Failed to post log because of unknown error"); return 1000; }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public StatusString getRequestItemValue(String html) { Status iStatus = new Status(); StatusString requestItemValue = new StatusString(); String lookupPattern = "^<td(.*?)<input type=\"radio\" name=\"radio\" value=\"(.*?)\"(.*?)</td>$"; Pattern findPattern = Pattern.compile(lookupPattern, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher findPatternMatch = findPattern.matcher(html); if (findPatternMatch.find()) { iStatus.returnStatus = true;/* w w w . ja v a2 s .com*/ iStatus.returnMsg = "MillenniumRemoteServiceManager-getRequestItemValue - Success"; requestItemValue.recordStatus = iStatus; requestItemValue.statusValue = findPatternMatch.group(2).trim(); } else { iStatus.returnStatus = false; iStatus.returnMsg = "MillenniumRemoteServiceManager-getRequestItemValue - Pattern not found"; requestItemValue.recordStatus = iStatus; requestItemValue.statusValue = null; } return requestItemValue; }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public StatusString getRequestItemTitle(String html) { Status iStatus = new Status(); StatusString requestItemTitle = new StatusString(); String lookupPattern = "^(.*?)Requesting <strong>(.*?)</strong>(.*?)$"; Pattern findPattern = Pattern.compile(lookupPattern, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher findPatternMatch = findPattern.matcher(html); if (findPatternMatch.find()) { iStatus.returnStatus = true;// w w w . j av a 2 s .co m iStatus.returnMsg = "MillenniumRemoteServiceManager-getRequestItemTitle - Success"; requestItemTitle.recordStatus = iStatus; requestItemTitle.statusValue = findPatternMatch.group(2).trim(); } else { iStatus.returnStatus = false; iStatus.returnMsg = "MillenniumRemoteServiceManager-getRequestItemTitle - Pattern not found"; requestItemTitle.recordStatus = iStatus; requestItemTitle.statusValue = null; } return requestItemTitle; }
From source file:org.extensiblecatalog.ncip.v2.millennium.MillenniumRemoteServiceManager.java
public String getRequestItemLocationValue(String html) { String requestItemLocationValue = null; String lookupPattern = "^(.*?)<input type=\"hidden\" name=\"locx00\" value=\"(.*?)\"(.*?)/>$"; Pattern findPattern = Pattern.compile(lookupPattern, Pattern.MULTILINE + Pattern.CASE_INSENSITIVE); Matcher findPatternMatch = findPattern.matcher(html); while (findPatternMatch.find()) { requestItemLocationValue = findPatternMatch.group(2).trim(); }/* w w w . jav a2 s . com*/ return requestItemLocationValue; }
From source file:org.etudes.jforum.view.admin.ImportExportAction.java
/** * parse export content resource reference urls * @param message//w w w . ja v a 2 s . com * - messge * @param ref * - reference * @param parentPath * - parent path * @return * - modified content */ private String parseExportContentResourceUrls(String message, String ref, String parentPath) { ref = Validator.escapeUrl(ref); // file name with spaces doesn't have %20 for spaces // get file name /*This may not be needed as spaces have %20 String fileName = ref.substring(ref.lastIndexOf("/") + 1); try { fileName = URLDecoder.decode(fileName, "UTF-8"); } catch (UnsupportedEncodingException e) { if (logger.isWarnEnabled()) logger.warn("parseExportContentResourceUrls: " + e); }*/ //ref = ref.substring(0, ref.lastIndexOf("/") + 1) + fileName; parentPath = Validator.escapeUrl(parentPath); StringBuffer sb = new StringBuffer(); Pattern p = Pattern.compile("(src|href)[\\s]*=[\\s]*[\\\"'](/access" + ref + ")[\\\"']", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.UNICODE_CASE); Matcher m = p.matcher(message); while (m.find()) { if (m.groupCount() == 2) { String refMatch = m.group(2); if (parentPath == null || parentPath.trim().length() == 0) { String siteId = ToolManager.getCurrentPlacement().getContext(); refMatch = refMatch.substring(("/access/content/group/" + siteId).length() + 1); } else { if (refMatch.indexOf(parentPath) == -1) { String siteId = ToolManager.getCurrentPlacement().getContext(); refMatch = refMatch.substring(("/access/content/group/" + siteId).length() + 1); String pathRef[] = parentPath.split("/"); StringBuilder refPath = new StringBuilder(); for (int i = 0; i < (pathRef.length - 1); i++) { refPath.append("../"); } refMatch = refPath.toString() + refMatch; } else { int index = refMatch.indexOf(parentPath); refMatch = refMatch.substring(index + parentPath.length() + 1); } } /*String fileName1 = null; boolean escapeFilePath = false; try { if (logger.isDebugEnabled()) logger.debug("parseExportContentResourceUrls: refMatch :"+ refMatch); if (refMatch.lastIndexOf("/") != -1) { fileName1 = refMatch.substring(refMatch.lastIndexOf("/")+1); refMatch = refMatch.substring(0, refMatch.lastIndexOf("/")+1); if (logger.isDebugEnabled()) logger.debug("parseExportContentResourceUrls: refMatch sub string :"+ refMatch); fileName1 = URLDecoder.decode(fileName1, "UTF-8"); escapeFilePath = true; } } catch (UnsupportedEncodingException e) { if (logger.isWarnEnabled()) logger.warn("parseExportContentResourceUrls: " + e); } if (escapeFilePath) { m.appendReplacement(sb, Matcher.quoteReplacement(m.group(1)+ "=\""+ refMatch + fileName1 +"\"")); } else m.appendReplacement(sb, Matcher.quoteReplacement(m.group(1)+ "=\""+ refMatch + "\""));*/ m.appendReplacement(sb, Matcher.quoteReplacement(m.group(1) + "=\"" + refMatch + "\"")); } } m.appendTail(sb); return sb.toString(); }
From source file:carnero.cgeo.original.libs.Base.java
public int postLog(App app, String geocode, String cacheid, String viewstate, String viewstate1, int logType, int year, int month, int day, String log, ArrayList<TrackableLog> trackables) { if (viewstate == null || viewstate.length() == 0) { Log.e(Settings.tag, "cgeoBase.postLog: No viewstate given"); return 1000; }//w ww . j av a 2 s . c o m if (logTypes2.containsKey(logType) == false) { Log.e(Settings.tag, "cgeoBase.postLog: Unknown logtype"); return 1000; } if (log == null || log.length() == 0) { Log.e(Settings.tag, "cgeoBase.postLog: No log text given"); return 1001; } // fix log (non-Latin characters converted to HTML entities) final int logLen = log.length(); final StringBuilder logUpdated = new StringBuilder(); for (int i = 0; i < logLen; i++) { char c = log.charAt(i); if (c > 300) { logUpdated.append("&#"); logUpdated.append(Integer.toString((int) c)); logUpdated.append(";"); } else { logUpdated.append(c); } } log = logUpdated.toString(); log = log.replace("\n", "\r\n"); // windows' eol if (trackables != null) { Log.i(Settings.tag, "Trying to post log for cache #" + cacheid + " - action: " + logType + "; date: " + year + "." + month + "." + day + ", log: " + log + "; trackables: " + trackables.size()); } else { Log.i(Settings.tag, "Trying to post log for cache #" + cacheid + " - action: " + logType + "; date: " + year + "." + month + "." + day + ", log: " + log + "; trackables: 0"); } final String host = "www.geocaching.com"; final String path = "/seek/log.aspx?ID=" + cacheid; final String method = "POST"; final HashMap<String, String> params = new HashMap<String, String>(); params.put("__VIEWSTATE", viewstate); if (viewstate1 != null) { params.put("__VIEWSTATE1", viewstate1); params.put("__VIEWSTATEFIELDCOUNT", "2"); } params.put("__EVENTTARGET", ""); params.put("__EVENTARGUMENT", ""); params.put("__LASTFOCUS", ""); params.put("ctl00$ContentBody$LogBookPanel1$ddLogType", Integer.toString(logType)); params.put("ctl00$ContentBody$LogBookPanel1$DateTimeLogged", String.format("%02d", month) + "/" + String.format("%02d", day) + "/" + String.format("%04d", year)); params.put("ctl00$ContentBody$LogBookPanel1$DateTimeLogged$Month", Integer.toString(month)); params.put("ctl00$ContentBody$LogBookPanel1$DateTimeLogged$Day", Integer.toString(day)); params.put("ctl00$ContentBody$LogBookPanel1$DateTimeLogged$Year", Integer.toString(year)); params.put("ctl00$ContentBody$LogBookPanel1$uxLogInfo", log); params.put("ctl00$ContentBody$LogBookPanel1$LogButton", "Submit Log Entry"); params.put("ctl00$ContentBody$uxVistOtherListingGC", ""); if (trackables != null && trackables.isEmpty() == false) { // we have some trackables to proceed final StringBuilder hdnSelected = new StringBuilder(); for (TrackableLog tb : trackables) { final String action = Integer.toString(tb.id) + logTypesTrackableAction.get(tb.action); if (tb.action > 0) { hdnSelected.append(action); hdnSelected.append(","); } } params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$hdnSelectedActions", hdnSelected.toString()); // selected trackables params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$hdnCurrentFilter", ""); } String page = request(false, host, path, method, params, false, false, false).getData(); if (checkLogin(page) == false) { int loginState = login(); if (loginState == 1) { page = request(false, host, path, method, params, false, false, false).getData(); } else { Log.e(Settings.tag, "cgeoBase.postLog: Can not log in geocaching (error: " + loginState + ")"); return loginState; } } if (page == null || page.length() == 0) { Log.e(Settings.tag, "cgeoBase.postLog: No data from server"); return 1002; } // maintenance, archived needs to be confirmed final Pattern pattern = Pattern.compile( "<span id=\"ctl00_ContentBody_LogBookPanel1_lbConfirm\"[^>]*>([^<]*<font[^>]*>)?([^<]+)(</font>[^<]*)?</span>", Pattern.CASE_INSENSITIVE); final Matcher matcher = pattern.matcher(page); try { if (matcher.find() == true && matcher.groupCount() > 0) { final String viewstateConfirm = findViewstate(page, 0); final String viewstate1Confirm = findViewstate(page, 1); if (viewstateConfirm == null || viewstateConfirm.length() == 0) { Log.e(Settings.tag, "cgeoBase.postLog: No viewstate for confirm log"); return 1000; } params.clear(); params.put("__VIEWSTATE", viewstateConfirm); if (viewstate1 != null) { params.put("__VIEWSTATE1", viewstate1Confirm); params.put("__VIEWSTATEFIELDCOUNT", "2"); } params.put("__EVENTTARGET", ""); params.put("__EVENTARGUMENT", ""); params.put("__LASTFOCUS", ""); params.put("ctl00$ContentBody$LogBookPanel1$btnConfirm", "Yes"); params.put("ctl00$ContentBody$LogBookPanel1$uxLogInfo", log); params.put("ctl00$ContentBody$uxVistOtherListingGC", ""); if (trackables != null && trackables.isEmpty() == false) { // we have some trackables to proceed final StringBuilder hdnSelected = new StringBuilder(); for (TrackableLog tb : trackables) { String ctl = null; final String action = Integer.toString(tb.id) + logTypesTrackableAction.get(tb.action); if (tb.ctl < 10) { ctl = "0" + Integer.toString(tb.ctl); } else { ctl = Integer.toString(tb.ctl); } params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$repTravelBugs$ctl" + ctl + "$ddlAction", action); if (tb.action > 0) { hdnSelected.append(action); hdnSelected.append(","); } } params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$hdnSelectedActions", hdnSelected.toString()); // selected trackables params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$hdnCurrentFilter", ""); } page = request(false, host, path, method, params, false, false, false).getData(); } } catch (Exception e) { Log.e(Settings.tag, "cgeoBase.postLog.confim: " + e.toString()); } try { final Pattern patternOk = Pattern.compile( "<h2[^>]*>[^<]*<span id=\"ctl00_ContentBody_lbHeading\"[^>]*>[^<]*</span>[^<]*</h2>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); final Matcher matcherOk = patternOk.matcher(page); if (matcherOk.find() == true) { Log.i(Settings.tag, "Log successfully posted to cache #" + cacheid); if (app != null && geocode != null) { app.saveVisitDate(geocode); } return 1; } } catch (Exception e) { Log.e(Settings.tag, "cgeoBase.postLog.check: " + e.toString()); } Log.e(Settings.tag, "cgeoBase.postLog: Failed to post log because of unknown error"); return 1000; }
From source file:carnero.cgeo.cgBase.java
public int postLog(cgeoapplication app, String geocode, String cacheid, String viewstate, String viewstate1, int logType, int year, int month, int day, String log, ArrayList<cgTrackableLog> trackables) { if (viewstate == null || viewstate.length() == 0) { Log.e(cgSettings.tag, "cgeoBase.postLog: No viewstate given"); return 1000; }//from w w w .j a v a2s .com if (logTypes2.containsKey(logType) == false) { Log.e(cgSettings.tag, "cgeoBase.postLog: Unknown logtype"); return 1000; } if (log == null || log.length() == 0) { Log.e(cgSettings.tag, "cgeoBase.postLog: No log text given"); return 1001; } // fix log (non-Latin characters converted to HTML entities) final int logLen = log.length(); final StringBuilder logUpdated = new StringBuilder(); for (int i = 0; i < logLen; i++) { char c = log.charAt(i); if (c > 300) { logUpdated.append("&#"); logUpdated.append(Integer.toString((int) c)); logUpdated.append(";"); } else { logUpdated.append(c); } } log = logUpdated.toString(); log = log.replace("\n", "\r\n"); // windows' eol if (trackables != null) { Log.i(cgSettings.tag, "Trying to post log for cache #" + cacheid + " - action: " + logType + "; date: " + year + "." + month + "." + day + ", log: " + log + "; trackables: " + trackables.size()); } else { Log.i(cgSettings.tag, "Trying to post log for cache #" + cacheid + " - action: " + logType + "; date: " + year + "." + month + "." + day + ", log: " + log + "; trackables: 0"); } final String host = "www.geocaching.com"; final String path = "/seek/log.aspx?ID=" + cacheid; final String method = "POST"; final HashMap<String, String> params = new HashMap<String, String>(); params.put("__VIEWSTATE", viewstate); if (viewstate1 != null) { params.put("__VIEWSTATE1", viewstate1); params.put("__VIEWSTATEFIELDCOUNT", "2"); } params.put("__EVENTTARGET", ""); params.put("__EVENTARGUMENT", ""); params.put("__LASTFOCUS", ""); params.put("ctl00$ContentBody$LogBookPanel1$ddLogType", Integer.toString(logType)); params.put("ctl00$ContentBody$LogBookPanel1$DateTimeLogged", String.format("%02d", month) + "/" + String.format("%02d", day) + "/" + String.format("%04d", year)); params.put("ctl00$ContentBody$LogBookPanel1$DateTimeLogged$Month", Integer.toString(month)); params.put("ctl00$ContentBody$LogBookPanel1$DateTimeLogged$Day", Integer.toString(day)); params.put("ctl00$ContentBody$LogBookPanel1$DateTimeLogged$Year", Integer.toString(year)); params.put("ctl00$ContentBody$LogBookPanel1$uxLogInfo", log); params.put("ctl00$ContentBody$LogBookPanel1$LogButton", "Submit Log Entry"); params.put("ctl00$ContentBody$uxVistOtherListingGC", ""); if (trackables != null && trackables.isEmpty() == false) { // we have some trackables to proceed final StringBuilder hdnSelected = new StringBuilder(); for (cgTrackableLog tb : trackables) { final String action = Integer.toString(tb.id) + logTypesTrackableAction.get(tb.action); if (tb.action > 0) { hdnSelected.append(action); hdnSelected.append(","); } } params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$hdnSelectedActions", hdnSelected.toString()); // selected trackables params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$hdnCurrentFilter", ""); } String page = request(false, host, path, method, params, false, false, false).getData(); if (checkLogin(page) == false) { int loginState = login(); if (loginState == 1) { page = request(false, host, path, method, params, false, false, false).getData(); } else { Log.e(cgSettings.tag, "cgeoBase.postLog: Can not log in geocaching (error: " + loginState + ")"); return loginState; } } if (page == null || page.length() == 0) { Log.e(cgSettings.tag, "cgeoBase.postLog: No data from server"); return 1002; } // maintenance, archived needs to be confirmed final Pattern pattern = Pattern.compile( "<span id=\"ctl00_ContentBody_LogBookPanel1_lbConfirm\"[^>]*>([^<]*<font[^>]*>)?([^<]+)(</font>[^<]*)?</span>", Pattern.CASE_INSENSITIVE); final Matcher matcher = pattern.matcher(page); try { if (matcher.find() == true && matcher.groupCount() > 0) { final String viewstateConfirm = findViewstate(page, 0); final String viewstate1Confirm = findViewstate(page, 1); if (viewstateConfirm == null || viewstateConfirm.length() == 0) { Log.e(cgSettings.tag, "cgeoBase.postLog: No viewstate for confirm log"); return 1000; } params.clear(); params.put("__VIEWSTATE", viewstateConfirm); if (viewstate1 != null) { params.put("__VIEWSTATE1", viewstate1Confirm); params.put("__VIEWSTATEFIELDCOUNT", "2"); } params.put("__EVENTTARGET", ""); params.put("__EVENTARGUMENT", ""); params.put("__LASTFOCUS", ""); params.put("ctl00$ContentBody$LogBookPanel1$btnConfirm", "Yes"); params.put("ctl00$ContentBody$LogBookPanel1$uxLogInfo", log); params.put("ctl00$ContentBody$uxVistOtherListingGC", ""); if (trackables != null && trackables.isEmpty() == false) { // we have some trackables to proceed final StringBuilder hdnSelected = new StringBuilder(); for (cgTrackableLog tb : trackables) { String ctl = null; final String action = Integer.toString(tb.id) + logTypesTrackableAction.get(tb.action); if (tb.ctl < 10) { ctl = "0" + Integer.toString(tb.ctl); } else { ctl = Integer.toString(tb.ctl); } params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$repTravelBugs$ctl" + ctl + "$ddlAction", action); if (tb.action > 0) { hdnSelected.append(action); hdnSelected.append(","); } } params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$hdnSelectedActions", hdnSelected.toString()); // selected trackables params.put("ctl00$ContentBody$LogBookPanel1$uxTrackables$hdnCurrentFilter", ""); } page = request(false, host, path, method, params, false, false, false).getData(); } } catch (Exception e) { Log.e(cgSettings.tag, "cgeoBase.postLog.confim: " + e.toString()); } try { final Pattern patternOk = Pattern.compile( "<h2[^>]*>[^<]*<span id=\"ctl00_ContentBody_lbHeading\"[^>]*>[^<]*</span>[^<]*</h2>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); final Matcher matcherOk = patternOk.matcher(page); if (matcherOk.find() == true) { Log.i(cgSettings.tag, "Log successfully posted to cache #" + cacheid); if (app != null && geocode != null) { app.saveVisitDate(geocode); } return 1; } } catch (Exception e) { Log.e(cgSettings.tag, "cgeoBase.postLog.check: " + e.toString()); } Log.e(cgSettings.tag, "cgeoBase.postLog: Failed to post log because of unknown error"); return 1000; }
From source file:processing.core.PApplet.java
static Pattern matchPattern(String regexp) { Pattern p = null;//from w w w. j av a 2 s. c o m if (matchPatterns == null) { matchPatterns = new HashMap<String, Pattern>(); } else { p = matchPatterns.get(regexp); } if (p == null) { if (matchPatterns.size() == 10) { // Just clear out the match patterns here if more than 10 are // being // used. It's not terribly efficient, but changes that you have // >10 // different match patterns are very slim, unless you're doing // something really tricky (like custom match() methods), in // which // case match() won't be efficient anyway. (And you should just // be // using your own Java code.) The alternative is using a queue // here, // but that's a silly amount of work for negligible benefit. matchPatterns.clear(); } p = Pattern.compile(regexp, Pattern.MULTILINE | Pattern.DOTALL); matchPatterns.put(regexp, p); } return p; }
From source file:cgeo.geocaching.cgBase.java
public String getMapUserToken(Handler noTokenHandler) { final cgResponse response = request(false, "www.geocaching.com", "/map/default.aspx", "GET", "", 0, false); final String data = response.getData(); String usertoken = null;// w w w. java 2 s . c om if (StringUtils.isNotBlank(data)) { final Pattern pattern = Pattern.compile("var userToken[^=]*=[^']*'([^']+)';", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE); final Matcher matcher = pattern.matcher(data); while (matcher.find()) { if (matcher.groupCount() > 0) { usertoken = matcher.group(1); } } } if (noTokenHandler != null && StringUtils.isBlank(usertoken)) { noTokenHandler.sendEmptyMessage(0); } return usertoken; }