List of usage examples for java.util.regex Matcher toMatchResult
public MatchResult toMatchResult()
From source file:org.jenkinsci.plugins.SemanticVersioning.parsing.BuildScalaParser.java
public AppVersion extractAppVersion(FilePath workspace, PrintStream logger) throws InvalidBuildFileFormatException, IOException { String filename = workspace + BUILD_DEFINITION_FILENAME; File file = new File(filename); if (file.exists()) { Pattern extendsBuild = Pattern.compile(".*extends\\s+Build.*"); String content = FileUtils.readFileToString(file); if (extendsBuild.matcher(content).find()) { String version;/*from ww w.jav a 2s.c o m*/ Pattern pattern = Pattern.compile("val\\s*appVersion\\s*=\\s*\"([^\"]*)\"", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(content); boolean found = matcher.find(); if (found) { version = matcher.toMatchResult().group(1); } else { throw new InvalidBuildFileFormatException( "No version information found in " + BUILD_DEFINITION_FILENAME); } return AppVersion.parse(version); } else { throw new InvalidBuildFileFormatException( "'" + BUILD_DEFINITION_FILENAME + "' is not a valid build definition file."); } } else { throw new FileNotFoundException("'" + BUILD_DEFINITION_FILENAME + "' was not found."); } }
From source file:org.springframework.social.twitter.api.impl.TweetDeserializer.java
private void extractTickerSymbolEntitiesFromText(String text, Entities entities) { Pattern pattern = Pattern.compile("\\$[A-Za-z]+"); Matcher matcher = pattern.matcher(text); while (matcher.find()) { MatchResult matchResult = matcher.toMatchResult(); String tickerSymbol = matchResult.group().substring(1); String url = "https://twitter.com/search?q=%24" + tickerSymbol + "&src=ctag"; entities.getTickerSymbols().add(new TickerSymbolEntity(tickerSymbol, url, new int[] { matchResult.start(), matchResult.end() })); }// ww w . ja va 2 s . com }
From source file:ch.ifocusit.livingdoc.plugin.publish.HtmlPostProcessor.java
private String replaceAll(String content, Pattern pattern, Function<MatchResult, String> replacer) { StringBuffer replacedContent = new StringBuffer(); Matcher matcher = pattern.matcher(content); while (matcher.find()) { matcher.appendReplacement(replacedContent, replacer.apply(matcher.toMatchResult())); }/* w w w . j a v a 2s .co m*/ matcher.appendTail(replacedContent); return replacedContent.toString(); }
From source file:org.mule.modules.quickbooks.online.api.QuickBooksOnlinePaginatedIterable.java
/** * Performs the count query to QuickBooks to calculate the total number of results (all pages) for the original paginated query. * /* w w w . j a v a2 s . co m*/ * @return number of total results */ public Integer getTotalResultsCount() { String cQuery = query.trim(); Matcher queryMatcher = QuickBooksOnlineQueryEvaluator.matchSelectFieldsPattern(cQuery); Validate.isTrue(queryMatcher.matches(), "The query - " + cQuery + " - received is not valid."); MatchResult queryMatchResult = queryMatcher.toMatchResult(); String countQuery = StringUtils.replaceOnce(cQuery, queryMatchResult.group(1), COUNT_QUERY_SELECT_FIELDS); try { DataService dataService = dataServiceHelper.createIntuitDataService(credentials); QueryResult queryResult = dataService.executeQuery(countQuery); return queryResult.getTotalCount(); } catch (FMSException e) { throw new QuickBooksRuntimeException(dataServiceHelper.adaptFMSExceptionToExceptionInfo(e), e); } }
From source file:uk.ac.kcl.at.ElasticGazetteerAcceptanceTest.java
private int getTruePositiveTokenCount(Mutant mutant) { int count = 0; Pattern mask = Pattern.compile("X+"); List<MatchResult> results = new ArrayList<>(); Matcher matcher = mask.matcher(mutant.getDeidentifiedString()); while (matcher.find()) { results.add(matcher.toMatchResult()); }/*w ww.j a va 2s .c o m*/ for (MatchResult result : results) { StringTokenizer tokenizer = new StringTokenizer( mutant.getFinalText().substring(result.start(), result.end())); ArrayList<String> arHits = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { arHits.add(tokenizer.nextToken()); } count = getHitCount(mutant, count, arHits); } return count; }
From source file:magicware.scm.redmine.tools.RedmineClient.java
public String createNewIssue(String newIssue) throws ClientProtocolException, IOException { HttpPost httpPost = null;/*w w w . j a va2 s.co m*/ String newIssueId = null; try { log.trace(newIssue); httpPost = new HttpPost(this.context + "/issues.json"); httpPost.setEntity(new StringEntity(newIssue, "application/json", HTTP.UTF_8)); log.debug("executing post request " + httpPost.getURI()); // ??? RdeminResponse rdeminResponse = getRdeminResponse(httpPost); if (rdeminResponse.isResponseOK()) { Matcher m = Pattern.compile(Constants.ISSUE_ID_VALUE_EXP).matcher(rdeminResponse.getContent()); while (m.find()) { MatchResult mr = m.toMatchResult(); newIssueId = mr.group(1).trim(); } } return newIssueId; } finally { if (httpPost != null) httpPost.abort(); } }
From source file:uk.ac.kcl.at.ElasticGazetteerAcceptanceTest.java
private int getFalsePositiveTokenCount(Mutant mutant) { int count = 0; Pattern mask = Pattern.compile("X+"); List<MatchResult> results = new ArrayList<>(); Matcher matcher = mask.matcher(mutant.getDeidentifiedString()); while (matcher.find()) { results.add(matcher.toMatchResult()); }//from www. j av a 2s. c om for (MatchResult result : results) { StringTokenizer tokenizer = new StringTokenizer( mutant.getFinalText().substring(result.start(), result.end())); ArrayList<String> arHits = new ArrayList<>(); while (tokenizer.hasMoreTokens()) { arHits.add(tokenizer.nextToken()); } for (String hit : arHits) { boolean isAnIdentifier = false; for (String token : mutant.getOutputTokens()) { if (hit.matches(Pattern.quote(token))) { isAnIdentifier = true; } } if (!isAnIdentifier && !hit.equalsIgnoreCase("") && !hit.equalsIgnoreCase("-")) { count++; } } } return count; }
From source file:org.wso2.carbon.ui.valve.XSSValve.java
private void validateParameters(Request request) throws ServletException { Enumeration<String> parameterNames = request.getParameterNames(); while (parameterNames.hasMoreElements()) { String paramName = parameterNames.nextElement(); String paramValue = request.getParameter(paramName); if (paramValue != null) { paramValue = paramValue.replaceAll("\0", ""); for (Pattern scriptPattern : patternList) { Matcher matcher = scriptPattern.matcher(paramValue); if (matcher.find()) { throw new ServletException( "Possible XSS Attack. Suspicious code : " + matcher.toMatchResult().group()); }/*from ww w.j a va 2 s. c o m*/ } } } }
From source file:magicware.scm.redmine.tools.RedmineClient.java
public int queryIssue(String projectId, String fieldId, String keyNo) throws ClientProtocolException, IOException { HttpGet httpGet = null;/*from w ww . j ava 2 s . c o m*/ try { int count = 0; StringBuilder uri = new StringBuilder(); uri.append(this.context).append("/issues.json?").append("project_id=").append(projectId) .append("&status_id=*&").append(fieldId).append("=").append(keyNo); httpGet = new HttpGet(uri.toString()); log.debug("executing get request " + httpGet.getURI()); // ??? RdeminResponse rdeminResponse = getRdeminResponse(httpGet); if (rdeminResponse.isResponseOK()) { Matcher m = Pattern.compile(Constants.ISSUE_COUNT_VALUE_EXP).matcher(rdeminResponse.getContent()); while (m.find()) { MatchResult mr = m.toMatchResult(); count = Integer.valueOf(mr.group(1).trim()); } log.debug("count of issue[" + keyNo + "] -> " + count); } else { throw new RuntimeException( "??????????" + rdeminResponse.getContent()); } return count; } finally { if (httpGet != null) httpGet.abort(); } }
From source file:magicware.scm.redmine.tools.IssueSyncApp.java
public void execute(SyncItem syncItem) throws IOException, InvalidFormatException { FileInputStream in = null;/* w w w. j a v a 2 s. com*/ try { // ?JSON?? String issueTemplate = FileUtils.readFileAsString(syncItem.getJsonTemplate()); // ??? Matcher m = Pattern.compile(Constants.ISSUE_FIELD_VALUE_EXP).matcher(issueTemplate); List<MatchResult> mrList = new ArrayList<MatchResult>(); while (m.find()) { MatchResult mr = m.toMatchResult(); mrList.add(mr); } // ???? in = new FileInputStream(syncItem.getFilePath()); Workbook wb = WorkbookFactory.create(in); FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator(); Sheet sheet = wb.getSheet(syncItem.getSheetName()); Row row = null; Cell cell = null; List<String> issues = new ArrayList<String>(); // ????? for (int i = sheet.getLastRowNum(); i >= (syncItem.getKeyRowBeginIdx() > 0 ? (syncItem.getKeyRowBeginIdx() - 1) : 0); i--) { // ???? row = sheet.getRow(i); if (row != null) { String keyNo = ExcelUtils.getCellContent(row.getCell(syncItem.getKeyColumnIdx() - 1), evaluator); // ?????????? if (StringUtils.isBlank(keyNo)) { break; } // ???? if (redmineClient.queryIssue(syncItem.getProjectId(), syncItem.getKeyFiledId(), keyNo) == 0) { StringBuilder newIssue = new StringBuilder(); int eolIdx = 0; for (MatchResult matchResult : mrList) { newIssue.append(issueTemplate.substring(eolIdx, matchResult.start())); int cellIndex = Integer.valueOf(matchResult.group(1)) - 1; cell = row.getCell(cellIndex); String cellvalue = ExcelUtils.getCellContent(cell, evaluator); // ? String valueMapStr = matchResult.group(3); Map<String, String> valueMap = null; if (valueMapStr != null) { valueMap = JSON.decode(valueMapStr); if (StringUtils.isNotEmpty(cellvalue) && valueMap.containsKey(cellvalue)) { cellvalue = valueMap.get(cellvalue); } else { cellvalue = valueMap.get("default"); } } if (StringUtils.isNotEmpty(cellvalue)) { cellvalue = StringEscapeUtils.escapeJavaScript(cellvalue); newIssue.append(cellvalue); } eolIdx = matchResult.end(); } newIssue.append(issueTemplate.substring(eolIdx)); issues.add(newIssue.toString()); } else { // ??? break; } } } for (int i = issues.size() - 1; i >= 0; i--) { Map<String, Issue> issueMap = JSON.decode(issues.get(i)); log.debug("create new issue >>>"); log.debug(JSON.encode(issueMap, true)); redmineClient.createNewIssue(issues.get(i)); } } finally { if (in != null) { in.close(); in = null; } } }