List of usage examples for java.util.regex Pattern quote
public static String quote(String s)
From source file:com.amazonaws.services.dynamodbv2.xspec.Path.java
private List<PathElement> parse(String path) { if (path == null) { throw new NullPointerException("path"); }//from w w w . j a v a2s . co m final String[] split = path.split(Pattern.quote(".")); final List<PathElement> elements = new ArrayList<PathElement>(); for (String element : split) { int index = element.indexOf('['); if (index == -1) { elements.add(new NamedElement(element)); continue; } if (index == 0) { throw new IllegalArgumentException("Bogus path: " + path); } elements.add(new NamedElement(element.substring(0, index))); do { element = element.substring(index + 1); index = element.indexOf(']'); if (index == -1) { throw new IllegalArgumentException("Bogus path: " + path); } int arrayIndex = Integer.parseInt(element.substring(0, index)); elements.add(new ArrayIndexElement(arrayIndex)); element = element.substring(index + 1); index = element.indexOf('['); if (index > 0) throw new IllegalArgumentException("Bogus path: " + path); } while (index != -1); if (!element.isEmpty()) { throw new IllegalArgumentException("Bogus path: " + path); } } return elements; }
From source file:com.amazonaws.util.AwsHostNameUtils.java
/** * Attempts to parse the region name from an endpoint based on conventions * about the endpoint format./* w w w . j ava 2 s. c o m*/ * * @param host the hostname to parse * @param serviceHint an optional hint about the service for the endpoint * @return the region parsed from the hostname, or * "us-east-1" if no region information * could be found */ public static String parseRegionName(final String host, final String serviceHint) { if (host.endsWith(".amazonaws.com")) { int index = host.length() - ".amazonaws.com".length(); return parseStandardRegionName(host.substring(0, index)); } if (serviceHint != null) { // If we have a service hint, look for 'service.[region]' or // 'service-[region]' in the endpoint's hostname. Pattern pattern = Pattern.compile("^(?:.+\\.)?" + Pattern.quote(serviceHint) + "[.-]([a-z0-9-]+)\\."); Matcher matcher = pattern.matcher(host); if (matcher.find()) { return matcher.group(1); } } // Endpoint is totally non-standard; guess us-east-1 for lack of a // better option. return "us-east-1"; }
From source file:airbrake.Backtrace.java
public Backtrace(final Throwable throwable) { toBacktrace(throwable);// www . ja va 2 s . co m ignore(".*" + Pattern.quote(messageIn(throwable)) + ".*"); ignore(); filter(); }
From source file:com.haulmont.yarg.formatters.impl.doc.connector.LinuxProcessManager.java
@Override public List<Long> findPid(String host, int port) { try {/*from w ww . j a va 2 s . c om*/ String regex = Pattern.quote(host) + ".*" + port; Pattern commandPattern = Pattern.compile(regex); List<String> lines = execute(psCommand()); List<Long> result = new ArrayList<Long>(); for (String line : lines) { Matcher lineMatcher = PS_OUTPUT_LINE.matcher(line); if (lineMatcher.matches()) { String command = lineMatcher.group(2); Matcher commandMatcher = commandPattern.matcher(command); if (commandMatcher.find()) { result.add(Long.parseLong(lineMatcher.group(1))); } } } return result; } catch (IOException e) { log.error("An error occured while searching for soffice PID in linux system", e); } return Collections.singletonList(PID_UNKNOWN); }
From source file:io.github.jeddict.jpa.spec.extend.QueryMapping.java
public boolean refractorQuery(String prevQuery, String newQuery) { if (ClassDiagramSettings.isRefractorQuery() && StringUtils.containsIgnoreCase(this.getQuery(), prevQuery)) { this.setQuery(this.getQuery().replaceAll("\\b(?i)" + Pattern.quote(prevQuery) + "\\b", newQuery)); return true; } else {/*from w w w . j av a 2 s.com*/ return false; } }
From source file:ch.oakmountain.tpa.web.TpaWebPersistor.java
public static void createGraph(String name, String outputDir, IGraph graph, String htmlData) throws IOException { LOGGER.info("Creating graph " + name + "...."); String content = IOUtils.toString(TpaWebPersistor.class.getResourceAsStream("/graph-curved.html")); content = content.replaceAll(Pattern.quote("$CSVNAME$"), Matcher.quoteReplacement(name)) .replaceAll(Pattern.quote("$HTML$"), Matcher.quoteReplacement(htmlData)); FileUtils.writeStringToFile(Paths.get(outputDir + File.separator + name + ".html").toFile(), content); File file = new File(outputDir + File.separator + name + ".csv"); writeGraph(file, graph);/*from w w w.ja va 2 s . c o m*/ TpaPersistorUtils.copyFromResourceToDir("d3.v3.js", outputDir); LOGGER.info("... created graph " + name + "."); }
From source file:com.wavemaker.app.build.pages.PageMinFileUpdator.java
private static String replacePageContent(String fileContent, String startElement, String endElement, String pageContent) {/*from w ww . j a v a 2 s .co m*/ String pageRegex = RegexConstants.MULTILINE_FLAG + Pattern.quote(startElement) + RegexConstants.FIRST_OCCURENCE_OF_ANY_CHARSEQUENCE + Pattern.quote(endElement); Pattern pageContentPattern = Pattern.compile(pageRegex); String newPageMinFileContent = pageContentPattern.matcher(fileContent) .replaceFirst(Matcher.quoteReplacement(pageContent)); return newPageMinFileContent; }
From source file:edu.kit.dama.staging.util.StagingUtils.java
/** * Prepare the provided path for acess. The path should be obtained from a * configuration file or some other configuration source. It may or may not * contain variables to replace. Currently, only $tmp is supported and will be * replaced by the user temp directory. In addition, the resulting folder will * be created if it does not exist./*from w ww .jav a 2s .c o m*/ * * @param pPath The path to prepare. * * @return The prepared path with replaced variables. * * @throws ConfigurationException If pPath is null or if the resulting path * could not be created. */ public static String preparePath(String pPath) throws ConfigurationException { if (pPath == null) { throw new ConfigurationException("Argument pPath must not be null."); } //replace tmp-dir String tmp = System.getProperty("java.io.tmpdir"); if (!tmp.startsWith("/")) { tmp = "/" + tmp; } String result = pPath.replaceAll(Pattern.quote("$tmp"), Matcher.quoteReplacement(tmp)); if (!new File(result).exists()) { LOGGER.debug("Creating path at {}", result); if (new File(result).mkdirs()) { LOGGER.debug("Path successfully created at {}", result); } else { throw new ConfigurationException("Failed to create path at " + result); } } else { LOGGER.debug("Path at {} already exists.", result); } return result; }
From source file:org.neo4j.bench.chart.JFreeStackedBarChart.java
@Override protected void addValue(ChartData dataset, Map<String, String> header, double value, int numberOfIterations, String benchCase, String timer) { String[] subTokens = timer.split(Pattern.quote(".")); dataset.add(benchCase, header.get(RunUtil.KEY_NEO_VERSION), subTokens[0], value); }
From source file:com.threewks.thundr.route.rewrite.Rewrite.java
public String getRewriteTo(Map<String, String> pathVars) { String finalRewrite = rewriteTo; Matcher matcher = Route.PathParameterPattern.matcher(rewriteTo); while (matcher.find()) { String token = matcher.group(1); finalRewrite = finalRewrite.replaceAll(Pattern.quote("{" + token + "}"), Matcher.quoteReplacement(StringUtils.trimToEmpty(pathVars.get(token)))); }//w ww.ja va 2 s . c o m return finalRewrite; }