List of usage examples for java.util.regex Matcher end
public int end()
From source file:it.drwolf.ridire.session.async.JobDBDataUpdater.java
private String getJobStatus(String encodedJobName) throws HttpException, IOException, DocumentException { // back compatibility Heritrix 2 if (encodedJobName.startsWith("completed-")) { return CrawlStatus.FINISHED.toString(); }/*from ww w.ja v a 2 s. c o m*/ File jobDir = new File(this.jobsDir + CrawlerManager.FILE_SEPARATOR + encodedJobName); String[] files = jobDir.list(); if (files == null || files.length < 2) { return CrawlStatus.CREATED.toString(); } String ret = CrawlStatus.CREATED.toString(); RandomAccessFile progressStatistics = null; Calendar now = new GregorianCalendar(); Date comparingDate = DateUtils.addDays(now.getTime(), -3); try { progressStatistics = new RandomAccessFile( this.jobsDir + CrawlerManager.FILE_SEPARATOR + encodedJobName + CrawlerManager.FILE_SEPARATOR + "logs" + CrawlerManager.FILE_SEPARATOR + "progress-statistics.log", "r"); if (progressStatistics != null) { progressStatistics.seek(Math.max(0, progressStatistics.length() - 3000)); String line = progressStatistics.readLine(); StringBuffer buffer = new StringBuffer(); while (line != null) { buffer.append(line + "\n"); line = progressStatistics.readLine(); } String progressStatisticsContent = buffer.toString(); Matcher m = this.progressStatisticsDatePattern.matcher(progressStatisticsContent); int start = 0; String lastDateString = ""; while (m.find(start)) { start = m.end(); lastDateString = m.group(); } Date lastDate = this.progressStatisticsDateFormat.parse(lastDateString); if (!progressStatisticsContent.contains("CRAWL ENDED - Finished") && lastDate.after(comparingDate)) { ret = CrawlStatus.RUNNING.toString(); } else { ret = CrawlStatus.FINISHED.toString(); } } } catch (FileNotFoundException e) { // TODO: handle exception } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } finally { if (progressStatistics != null) { progressStatistics.close(); } } // File crawlReport = new File(this.jobsDir + FILE_SEPARATOR // + encodedJobName + FILE_SEPARATOR + "reports" + FILE_SEPARATOR // + "crawl-report.txt"); // if (crawlReport != null && crawlReport.canRead()) { // String crawlReportContent = FileUtils.readFileToString(crawlReport); // if (crawlReportContent.contains("crawl status: Finished")) { // ret = CrawlStatus.FINISHED.toString(); // } // } return ret; }
From source file:de.pixida.logtest.designer.testrun.TestRunEditor.java
private Map<String, String> parseParameters() { final Pattern variable = Pattern.compile(AutomatonParameters.PARAMETER_PREG); final Map<String, String> params = new HashMap<>(); final String[] lines = StringUtils.split(TestRunEditor.this.parametersProperty.get(), "\r\n"); for (final String line : lines) { if (StringUtils.isNotBlank(line)) { final Matcher m = variable.matcher(line); if (m.find()) { final String key = m.group(1); if (line.charAt(m.end()) == '=') { final String value = line.substring(m.end() + 1); params.put(key, value); }/* w w w. j a v a 2s . com*/ } } } return params; }
From source file:at.ac.tuwien.inso.subcat.utility.commentparser.Parser.java
License:asdf
private void parseGLibMessages(List<ContentNode<T>> ast, String commentFragment) { Matcher gm = pGLibMessages.matcher(commentFragment); int lastEnd = 0; while (gm.find()) { if (lastEnd != gm.start()) { parseParagraphs(ast, commentFragment.substring(lastEnd, gm.start())); }// w w w . j a v a 2s . c om ast.add(new ArtefactNode<T>(gm.group(1))); lastEnd = gm.end(); } if (lastEnd != commentFragment.length()) { String frag = commentFragment.substring(lastEnd, commentFragment.length()); if (frag.trim().length() > 0) { parseParagraphs(ast, frag); } } }
From source file:com.adgear.data.plugin.IDLSchemaMojo.java
/** * Inspect the source for dependency requirement statements * * @param source IDL source code/* w ww . ja va 2s . c o m*/ * @return Collection of dependency names */ protected Collection<String> collectDependencies(String source) { HashSet<String> found = new HashSet<String>(); Matcher start = Pattern.compile("/\\*\\*", Pattern.MULTILINE).matcher(source); Matcher end = Pattern.compile("\\*/", Pattern.MULTILINE).matcher(source); if (start.find() && end.find()) { String doc = source.substring(start.start() + 3, end.end() - 2); Matcher dep = docstringPattern.matcher(doc); if (dep.find()) { Matcher required = Pattern.compile("([a-zA-Z0-9$_\\.]+)", Pattern.MULTILINE).matcher(dep.group(1)); while (required.find()) { String name = required.group(1); found.add(name); getLog().debug("Registering dependency '" + name + "'"); } } } return found; }
From source file:net.sf.jabref.importer.fetcher.GoogleScholarFetcher.java
private String getCitationsFromUrl(String urlQuery, Map<String, JLabel> ids) throws IOException { String cont = new URLDownload(urlQuery).downloadToString(Globals.prefs.getDefaultEncoding()); Matcher m = GoogleScholarFetcher.BIBTEX_LINK_PATTERN.matcher(cont); int lastRegionStart = 0; while (m.find()) { String link = m.group(1).replace("&", "&"); String pText;/*from www . j a v a2 s . c om*/ String part = cont.substring(lastRegionStart, m.start()); Matcher titleS = GoogleScholarFetcher.TITLE_START_PATTERN.matcher(part); Matcher titleE = GoogleScholarFetcher.TITLE_END_PATTERN.matcher(part); boolean fS = titleS.find(); boolean fE = titleE.find(); if (fS && fE) { if (titleS.end() < titleE.start()) { pText = part.substring(titleS.end(), titleE.start()); } else { pText = part; } } else { pText = link; } pText = pText.replace("[PDF]", ""); JLabel preview = new JLabel("<html>" + pText + "</html>"); ids.put(link, preview); // See if we can extract the link Google Scholar puts on the entry's title. // That will be set as "url" for the entry if downloaded: Matcher linkMatcher = GoogleScholarFetcher.LINK_PATTERN.matcher(pText); if (linkMatcher.find()) { entryLinks.put(link, linkMatcher.group(1)); } lastRegionStart = m.end(); } /*m = NEXT_PAGE_PATTERN.matcher(cont); if (m.find()) { System.out.println("NEXT: "+URL_START+m.group(1).replace("&", "&")); return URL_START+m.group(1).replace("&", "&"); } else*/ return null; }
From source file:com.puppycrawl.tools.checkstyle.checks.imports.ImportOrderCheck.java
/** * Finds out what group the specified import belongs to. * * @param name the import name to find.//from w w w . j av a2 s . com * @return group number for given import name. */ private int getGroupNumber(String name) { int bestIndex = groups.length; int bestLength = -1; int bestPos = 0; // find out what group this belongs in // loop over groups and get index for (int i = 0; i < groups.length; i++) { final Matcher matcher = groups[i].matcher(name); while (matcher.find()) { final int length = matcher.end() - matcher.start(); if (length > bestLength || length == bestLength && matcher.start() < bestPos) { bestIndex = i; bestLength = length; bestPos = matcher.start(); } } } return bestIndex; }
From source file:jp.go.nict.langrid.wrapper.ws_1_2.translation.AbstractTranslationService.java
private String toUpperCaseCharacterBehindDelimiter(String source) { StringBuilder sb = new StringBuilder(source); Pattern p = Pattern.compile("(\\Q*$%*\\E|\\Q*%$*\\E)\\. *[a-z]"); Matcher m = p.matcher(sb); while (m.find()) { String sub = sb.substring(m.start(), m.end()); sb.replace(m.start(), m.end(), sub.toUpperCase()); }//ww w . ja v a2 s . c om return sb.toString(); }
From source file:com.google.flightmap.parsing.faa.afd.AfdCommParser.java
private void addCommData() throws SQLException { Pattern commSectionRegex = Pattern .compile("\\((\\S+?)\\)\\s+?\\d+\\s*(?:N|E|W|S|NE|NW|SE|SW).+?UTC\\s+.+?COMMUNICATIONS\\:"); // "\\((\\S+?)\\)\\s+?\\d+.+?UTC\\s+.+?COMMUNICATIONS\\:"); Pattern freqRegex = Pattern.compile("([A-Z]+(?:[A-Z]| |/)+?)(\\d+\\.\\d+)\\s+(?:\\((.+?)\\))?"); int start = 0; Matcher commSectionMatcher = commSectionRegex.matcher(afd); Matcher freqMatcher = freqRegex.matcher(afd); while (commSectionMatcher.find(start)) { start = commSectionMatcher.start(); final String iata = commSectionMatcher.group(1); System.out.println(iata); // Determine potential end of this COMMUNICATIONS end int nextColon = afd.indexOf(":", commSectionMatcher.end()); if (nextColon == -1) { nextColon = afd.length();//from ww w . j a v a 2 s. co m } int nextMatch; if (commSectionMatcher.find(commSectionMatcher.end())) { nextMatch = commSectionMatcher.start(); } else { nextMatch = afd.length(); } final int stop = Math.min(nextColon, nextMatch); while (freqMatcher.find(start)) { if (freqMatcher.start() > stop) { start = stop; break; } System.out.println(" -> " + freqMatcher.group(0)); final String identifier = freqMatcher.group(1).trim(); final String frequency = freqMatcher.group(2).trim(); String remarks = freqMatcher.group(3); if (remarks != null) { remarks = remarks.trim(); } addAirportCommToDb(iata, identifier, frequency, remarks); start = freqMatcher.end(); } } }
From source file:at.ac.tuwien.inso.subcat.utility.commentparser.Parser.java
License:asdf
private void parseParagraphs(List<ContentNode<T>> ast, String commentFragment) { Matcher pm = pPara.matcher(commentFragment); int lastEnd = 0; while (pm.find()) { if (lastEnd != pm.start()) { int count = StringUtils.countMatches(pm.group(0), "\n") - 1; parseParagraph(ast, commentFragment.substring(lastEnd, pm.start()), count); }//from ww w .ja v a 2 s . c om lastEnd = pm.end(); } if (lastEnd != commentFragment.length()) { String frag = commentFragment.substring(lastEnd, commentFragment.length()); if (frag.trim().length() > 0) { parseParagraph(ast, frag, 0); } } }
From source file:mobi.jenkinsci.server.core.net.ProxyUtil.java
private String resolveJs(final String userAgent, final String pluginName, final String url, final String resultString) throws IOException { log.debug("Resolving JavaScript for URL " + url); final StringBuilder outString = new StringBuilder(); int currPos = 0; final Pattern linkPattern = Pattern.compile( "<script>?[^>]*src=[\"\\']([^>\"\\']*)[\"\\']([^>]*/>|[^>]*>[ \r\n]*</script>)", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); final Matcher matcher = linkPattern.matcher(resultString); while (matcher.find(currPos)) { final int start = matcher.start(); final int end = matcher.end(); outString.append(resultString.substring(currPos, start)); final String cssUrl = matcher.group(1); final String jsText = retrieveJs(userAgent, pluginName, url, cssUrl); outString.append(jsText);//from w ww .j a v a2 s . c o m currPos = end; } outString.append(resultString.substring(currPos)); log.debug(outString.length() + " JavaScript chars included for URL " + url); return outString.toString(); }