List of usage examples for java.util.regex Pattern quote
public static String quote(String s)
From source file:io.fabric8.tooling.archetype.generator.ArchetypeHelper.java
protected String replaceAllVariable(String text, String name, String value) { String answer;//from ww w . jav a 2 s .co m answer = text.replaceAll(Pattern.quote("${" + name + "}"), value); answer = answer.replaceAll(Pattern.quote("$" + name), value); return answer; }
From source file:de.tbuchloh.kiskis.persistence.PersistenceManager.java
/** * @param documentFile//from w w w . j a v a 2s . co m * the document backup file * @return the extension incl. BAK_ID */ static String getBackupExtension(File documentFile) { final Pattern pattern = Pattern.compile("(.*?)(" + Pattern.quote(BAK_ID) + "[0-9]{14})$"); final Matcher m = pattern.matcher(documentFile.getName()); if (!m.matches()) { throw new IllegalArgumentException(// String.format("The backup file %1$s has an invalid extension!", documentFile.getName())); } return m.group(2); }
From source file:dk.deck.resolver.ArtifactResolverRemote.java
private Metadata getSnapshptMetaData(String repo, Artifact artifact) throws IOException, DownloadException, SAXException { String artifactPath = artifact.getGroupId().replaceAll(Pattern.quote("."), Matcher.quoteReplacement("/")) + "/" + artifact.getArtifactId(); String artifactMetaData = artifactPath + "/" + artifact.getVersion() + "/maven-metadata.xml"; String getUrl = repo + "/" + artifactMetaData; return getMetadata(repo, artifact, getUrl); }
From source file:tr.edu.gsu.nerwip.recognition.internal.modelless.subee.Subee.java
/** * Handles the name of the person described in the processed article. For this matter, * we consider the article title and name, as well as the first sentence, which generally * starts with the full name of the person. * //ww w .j a v a 2 s . c om * @param article * Article to process. * @return * List of possible entities based on the analysis of the article title and name. * * @throws ClientProtocolException * Problem while accessing Freebase. * @throws ParseException * Problem while accessing Freebase. * @throws IOException * Problem while accessing Freebase. * @throws org.json.simple.parser.ParseException * Problem while accessing Freebase. */ private List<AbstractEntity<?>> processMainName(Article article) throws ClientProtocolException, ParseException, IOException, org.json.simple.parser.ParseException { logger.increaseOffset(); List<AbstractEntity<?>> result = new ArrayList<AbstractEntity<?>>(); String rawText = article.getRawText(); // init candidate strings with article name and title Set<String> candidateStrings = new TreeSet<String>(); String articleTitle = article.getTitle(); //debug //if(articleTitle.equals("Alfred Lothar Wegener")) // System.out.print(""); logger.log("Article title: " + articleTitle); candidateStrings.add(articleTitle); String articleName = article.getName(); logger.log("Article name: " + articleName); articleName = articleName.replace('_', ' ').trim(); candidateStrings.add(articleName); // process the beginning of the first sentence // we look for the string before the first parenthesis (usually containing birth info) // if there's none, we just ignore this potential information source Pattern p = Pattern.compile("^[^\\.]+?\\("); Matcher m = p.matcher(rawText); if (m.find()) { int startPos = m.start(); if (startPos == 0) { int endPos = m.end(); String persName = rawText.substring(0, endPos - 1); persName = persName.trim(); int wordCount = persName.length() - persName.replaceAll(" ", "").length(); if (wordCount > 6) logger.log( "Not able to extract person name from first sentence (too many words before the parenthesis): \"" + rawText.substring(0, 75) + "\""); else { logger.log("Person name: " + persName); candidateStrings.add(persName); } } } else logger.log("Not able to extract person name from first sentence (can't find the parenthesis): \"" + rawText.substring(0, 75) + "\""); // possibly remove double quotes (especially for the nicknames) List<String> nickFull = new ArrayList<String>(); Set<String> copy = new TreeSet<String>(candidateStrings); candidateStrings.clear(); for (String candidateString : copy) { if (candidateString.contains("\"")) { nickFull.add(candidateString); candidateString = candidateString.replaceAll("\"", ""); } candidateStrings.add(candidateString); } // possibly remove an indication in parenthesis at the end (especially for the titles) copy = new TreeSet<String>(candidateStrings); candidateStrings.clear(); for (String candidateString : copy) { if (candidateString.endsWith(")")) { String temp[] = candidateString.split("\\("); candidateString = temp[0].trim(); } candidateStrings.add(candidateString); } // add the lastname alone; only with the preceeding word; only with the 2 preeceding words, etc. copy = new TreeSet<String>(candidateStrings); for (String candidateString : copy) { String split[] = candidateString.split(" "); for (int i = split.length - 1; i >= 0; i--) { String temp = ""; for (int j = i; j < split.length; j++) temp = temp + split[j] + " "; temp = temp.trim(); candidateStrings.add(temp); } } // add very first and very last names (for more than 2 words) copy = new TreeSet<String>(candidateStrings); for (String candidateString : copy) { String split[] = candidateString.split(" "); if (split.length > 2) { String temp = split[0] + " " + split[split.length - 1]; candidateStrings.add(temp); } } // add variants with initials instead of firstnames copy = new TreeSet<String>(candidateStrings); for (String candidateString : copy) { String split[] = candidateString.split(" "); if (split.length > 1) { String initials1 = ""; String initials2 = ""; for (int i = 0; i < split.length - 1; i++) { initials1 = initials1 + split[i].substring(0, 1).toUpperCase(Locale.ENGLISH) + ". "; initials2 = initials2 + split[i].substring(0, 1).toUpperCase(Locale.ENGLISH) + "."; } initials1 = initials1 + split[split.length - 1]; initials2 = initials2 + " " + split[split.length - 1]; candidateStrings.add(initials1); candidateStrings.add(initials2); } } // add the original version of the nicknames candidateStrings.addAll(nickFull); // look for similar strings in the text for (String expr : candidateStrings) { String escapedStr = Pattern.quote(expr); p = Pattern.compile("\\b" + escapedStr + "\\b"); m = p.matcher(rawText); while (m.find()) { int startPos = m.start(); int endPos = m.end(); String valueStr = m.group(); AbstractEntity<?> ent = AbstractEntity.build(EntityType.PERSON, startPos, endPos, RecognizerName.SUBEE, valueStr); result.add(ent); } } if (result.isEmpty()) logger.log("WARNING: title not found at all in the text, which is unusual"); logger.decreaseOffset(); return result; }
From source file:com.all.facebook.impl.FacebookServiceImpl.java
private String[] validateAccessTokenFormat(String accessToken) throws FacebookServiceException { String[] keyArray = accessToken.split(Pattern.quote(PIPE)); ;/*from w ww .j a v a2 s. co m*/ if (keyArray.length != 3) { throw new FacebookServiceException("Invalid access token format"); } return keyArray; }
From source file:gate.util.reporting.DocTimeReporter.java
/** * Stores GATE processing elements and the time taken by them in an in-memory * data structure for report generation. * * @param inputFile//from w w w . j av a 2 s .c o m * A handle to the input benchmark file. * * @return An Object of type LinkedHashMap<String, Object> containing the * processing elements (with time in milliseconds) in hierarchical * structure. Null if there was an error. * * @throws BenchmarkReportInputFileFormatException * if the input file provided is not a valid benchmark file. */ @Override public Object store(File inputFile) throws BenchmarkReportInputFileFormatException { String[] temp = inputFile.getAbsolutePath().split("\\" + File.separator); pipelineName = temp[temp.length - 1].replace("_benchmark.txt", ""); LinkedHashMap<String, Object> globalStore = new LinkedHashMap<String, Object>(); BufferedReader in = null; try { in = new BufferedReader(new FileReader(inputFile)); String str; String docName = null; String matchedPR = null; String startToken = null; // Reading the benchmark.txt one line at a time Pattern pattern = Pattern.compile("(\\d+) (\\d+) (.*) (.*) \\{(.*)\\}"); // Pattern matching for extracting document name Pattern patternDocName = Pattern.compile(".*documentName=(.*?)[,|}].*"); while ((str = in.readLine()) != null) { if (str.matches(".*START.*")) { String[] splittedStartEntry = str.split("\\s"); if (splittedStartEntry.length > 2) { startToken = splittedStartEntry[2]; } else { throw new BenchmarkReportInputFileFormatException(getBenchmarkFile() + " is invalid."); } } Matcher matcher = pattern.matcher(str); Matcher matcherDocName = patternDocName.matcher(str); Pattern patternDocEnd = Pattern .compile("(\\d+) (\\d+) " + Pattern.quote(startToken) + " (.*) \\{(.*)\\}.*"); Matcher matcherDocEnd = patternDocEnd.matcher(str); if (matcherDocName != null) { if (matcherDocName.matches()) { docName = matcherDocName.group(1); } } if (matcherDocEnd != null) { if (matcherDocEnd.matches()) { globalTotal = globalTotal + Integer.parseInt(matcherDocEnd.group(2)); } } if (matcher != null && matcher.matches()) { String benchmarkIDs = matcher.group(3).replaceFirst(Pattern.quote(startToken) + ".", "") .replaceFirst("doc_" + Pattern.quote(docName) + ".", ""); String[] splittedBenchmarkIDs = benchmarkIDs.split("\\."); // Getting the exact PR name and storing only entries matching PR name if (PRMatchingRegex.equals(MATCH_ALL_PR_REGEX)) { if (splittedBenchmarkIDs.length > 0) { matchedPR = splittedBenchmarkIDs[0]; } if (!matchedPR.equalsIgnoreCase(startToken)) { organizeEntries(globalStore, matchedPR, matcher.group(2), docName); } } else if (isPRMatched(benchmarkIDs, PRMatchingRegex)) { if (splittedBenchmarkIDs.length > 0) { matchedPR = splittedBenchmarkIDs[0]; } if (matchedPR != null) matchingPRs.add(matchedPR); organizeEntries(globalStore, matchedPR, matcher.group(2), docName); } } } } catch (IOException e) { e.printStackTrace(); globalStore = null; } finally { try { if (in != null) { in.close(); } } catch (IOException e) { e.printStackTrace(); globalStore = null; } } return globalStore; }
From source file:dk.deck.resolver.ArtifactResolverRemote.java
private Metadata getArtifactMetaData(String repo, Artifact artifact) throws IOException, DownloadException, SAXException { String artifactPath = artifact.getGroupId().replaceAll(Pattern.quote("."), Matcher.quoteReplacement("/")) + "/" + artifact.getArtifactId(); String artifactMetaData = artifactPath + "/maven-metadata.xml"; String getUrl = repo + "/" + artifactMetaData; return getMetadata(repo, artifact, getUrl); }
From source file:com.temenos.interaction.core.hypermedia.LinkToFieldAssociationImpl.java
private void addEntriesToLinkProperties(LinkProperties linkProps, List<String> keys) { Map<String, Object> linkPropertiesMap = linkProps.getTransitionProperties(); Set<String> unindexedKeys = new HashSet<String>(); for (String key : keys) { Object value = this.normalisedTransitionProperties.get(key); String unindexedKey = key.replaceAll(PARAM_REPLACEMENT_REGEX, ""); unindexedKeys.add(unindexedKey); if (value != null && value instanceof String) { linkPropertiesMap.put(unindexedKey, value); } else {//from w ww . ja v a 2 s .c om linkPropertiesMap.put(unindexedKey, ""); } } // Replace Id={A.B.C} with Id={VAL} if A.B.C=VAL is in the linkPropertiesMap for (String key : linkPropertiesMap.keySet()) { Object value = linkPropertiesMap.get(key); if (value instanceof String) { String replacementKey = ((String) value).replaceAll("\\{", "").replaceAll("\\}", ""); if (unindexedKeys.contains(replacementKey)) { String replacementValue = ((String) value).replaceAll( "\\{" + Pattern.quote(replacementKey) + "\\}", linkPropertiesMap.get(replacementKey).toString()); linkPropertiesMap.put(key, replacementValue); } } } }
From source file:com.adobe.acs.commons.mcp.impl.processes.FolderRelocator.java
private String convertSourceToDestination(String path) throws RepositoryException { return sourceToDestination.entrySet().stream().filter(entry -> path.startsWith(entry.getKey())).findFirst() .map(entry -> path.replaceAll(Pattern.quote(entry.getKey()), entry.getValue())) .orElseThrow(() -> new RepositoryException("Cannot determine destination for " + path)); }
From source file:net.kamhon.ieagle.dao.Jpa2Dao.java
/** * convert hibernate positional parameter to JPA positional parameter notation.</br> For example: convert * <code>select a from A a where a.id=? and a.status=?</code> to * <code>select a from A a where a.id=?1 and a.status=?2</code> * /*from ww w .j a v a 2 s . com*/ * @param query * @return */ public String convertJpaPositionParams(String query) { if (StringUtils.isBlank(query)) return query; // bypass if the query is using JPA positional parameter notation if (query.indexOf("?1") >= 0) { return query; } else if (query.indexOf("?") >= 0) { StringBuffer sb = new StringBuffer(); Pattern p = Pattern.compile(Pattern.quote("?"), Pattern.CASE_INSENSITIVE); Matcher matcher = p.matcher(query); boolean result = matcher.find(); int count = 0; while (result) { String g = matcher.group(); matcher.appendReplacement(sb, g + (++count)); result = matcher.find(); } matcher.appendTail(sb); log.debug("sb.toString() = " + sb.toString()); return sb.toString(); } return query; }