List of usage examples for java.util.regex Matcher quoteReplacement
public static String quoteReplacement(String s)
From source file:org.springframework.data.search.core.QueryBuilder.java
/** * Builds a query dynamically using a tokenized string query and dynamic * query parameters.//w w w . j a va 2 s. com * * @param query The tokenized query. * @param params Query parameters. * @return A valid query that can be executed on a search engine. */ public static String resolveParams(final String query, final Object[] params) { final StringBuffer buffer = new StringBuffer(query.length()); if (!ArrayUtils.isEmpty(params)) { Iterator<Object> iterator = Arrays.asList(params).iterator(); Matcher matcher = NAMES_PATTERN.matcher(query); int i = 0; while (matcher.find()) { i++; if (params.length < i) { throw new InvalidParamsException("Some parameters are missing:" + Arrays.toString(params)); } Object variableValue = iterator.next(); String variableValueString = getVariableValueAsString(variableValue); String replacement = Matcher.quoteReplacement(variableValueString); matcher.appendReplacement(buffer, replacement); } matcher.appendTail(buffer); if (params.length > i) { throw new InvalidParamsException("Too much parameters for this query!" + Arrays.toString(params)); } } else { buffer.append(query); } return buffer.toString(); }
From source file:com.hexidec.ekit.component.HTMLTableUtilities.java
private static String converteTHemTD(String str) { Matcher m = pTH.matcher(str); if (!m.find()) { return str; }// w w w .j a v a2s .c o m StringBuffer sb = new StringBuffer(); String antes, depois; do { antes = m.group(1); depois = m.group(2); m.appendReplacement(sb, Matcher.quoteReplacement(antes + "td" + depois)); } while (m.find()); m.appendTail(sb); return sb.toString(); }
From source file:io.viewserver.core.Utils.java
public static String replaceSystemTokens(String inputString) { String result = inputString;//from www.j av a 2 s. co m Pattern pattern = Pattern.compile("%([^%]+)%"); Matcher matcher = pattern.matcher(inputString); while (true) { boolean found = false; while (matcher.find()) { found = true; String token = matcher.group(1); String value = Configuration.getString(token); if (value != null) { boolean encrypted = Configuration.getBoolean(String.format("%s[@%s]", token, PARSE_KEY), false); if (encrypted) { value = parse(value); } result = result.replace(matcher.group(0), value); } } if (!found) { break; } matcher.reset(result); } //only replace single backslashes with double backslashes return result.replaceAll(Matcher.quoteReplacement("(?<!\\)\\(?![\\\"\'])"), Matcher.quoteReplacement("\\\\")); }
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);/* w w w. ja v a2 s. com*/ TpaPersistorUtils.copyFromResourceToDir("d3.v3.js", outputDir); LOGGER.info("... created graph " + name + "."); }
From source file:org.entando.edo.builder.InternalServletFileBuilder.java
public static String getInternalServletJspFilePath(EdoBean bean, String suffix) { String folder = bean.getEdoBuilder().getWebinfApsFolder(); String subfolder = "jsp/internalservlet/".replaceAll("/", Matcher.quoteReplacement(File.separator)); folder = folder + subfolder;/*from w w w . ja v a2 s.c o m*/ folder = folder + bean.getName().toLowerCase() + File.separator; String filename = "frontend-" + StringUtils.uncapitalize(bean.getName()) + suffix; String finalfile = folder + filename; return finalfile; }
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./* www . j a v a2 s . 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: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)))); }/*from w w w. j a v a 2s .c om*/ return finalRewrite; }
From source file:com.threewks.thundr.route.redirect.Redirect.java
public String getRedirectTo(Map<String, String> pathVars) { String finalRedirect = redirectTo; Matcher matcher = Route.PathParameterPattern.matcher(redirectTo); while (matcher.find()) { String token = matcher.group(1); finalRedirect = finalRedirect.replaceAll(Pattern.quote("{" + token + "}"), Matcher.quoteReplacement(StringUtils.trimToEmpty(pathVars.get(token)))); }/*from www.j av a 2 s. c o m*/ return finalRedirect; }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.processEdit.EditN3Generator.java
public static String subInUris(String var, String value, String target) { //empty URIs get skipped if (var == null || var.length() == 0 || value == null) return target; /* var followed by dot some whitespace or var followed by whitespace*/ String varRegex = "\\?" + var + "(?=\\.\\p{Space}|\\p{Space})"; String out = null;/*w ww. j a v a 2 s. c o m*/ if ("".equals(value)) out = target.replaceAll(varRegex, ">::" + var + " was BLANK::< "); else out = target.replaceAll(varRegex, "<" + Matcher.quoteReplacement(value) + "> "); if (out != null && out.length() > 0) return out; else return target; }
From source file:com.wavemaker.app.build.pages.PageMinFileUpdator.java
private static String replacePageContent(String fileContent, String startElement, String endElement, String pageContent) {//from w w w . j ava 2 s.c om 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; }