List of usage examples for java.util.regex Matcher quoteReplacement
public static String quoteReplacement(String s)
From source file:com.hexidec.ekit.component.HTMLTableUtilities.java
private static String adicionaBRnoFimDosTD(String str) { Matcher m = pFimDeTDnaoPrecedidoDeBR.matcher(str); if (!m.find()) { return str; }// w w w .j av a 2s . c om StringBuffer sb = new StringBuffer(); do { m.appendReplacement(sb, "<br/>" + Matcher.quoteReplacement(m.group())); } while (m.find()); m.appendTail(sb); return sb.toString(); }
From source file:com.wavemaker.app.build.pages.Page.java
private String getTemplateContent(String pageName, String originalContent) { String lineBreak = SystemUtils.getLineBreak(); String startElement = this.getStartElement(pageName); startElement = startElement + lineBreak; String manipulatedContent = PAGE_NAME_PATTERN.matcher(contentTemplate).replaceAll(pageName); manipulatedContent = CONTENT_PATTERN.matcher(manipulatedContent) .replaceFirst(Matcher.quoteReplacement(originalContent)); manipulatedContent = StringUtils.isNotBlank(manipulatedContent) ? manipulatedContent + lineBreak : manipulatedContent;/*from www.ja va2 s . c om*/ String endElement = this.getEndElement(); endElement = endElement + lineBreak; String templateContent = startElement + manipulatedContent + endElement; return templateContent; }
From source file:dk.dma.msiproxy.common.settings.Settings.java
/** * Returns the value associated with the setting. * If it does not exist, it is created//from w ww .j a v a 2 s. c o m * * @param setting the source * @return the associated value */ public String get(Setting setting) { Objects.requireNonNull(setting, "Must specify valid setting"); String result; // If a corresponding system property is set, it takes precedence result = System.getProperty(setting.getSettingName()); // Check if it has been defined in the properties file if (result == null) { result = properties.getProperty(setting.getSettingName(), setting.defaultValue()); } if (result != null && setting.substituteSystemProperties()) { for (Object key : System.getProperties().keySet()) { result = result.replaceAll("\\$\\{" + key + "\\}", Matcher.quoteReplacement(System.getProperty("" + key))); } } return result; }
From source file:org.lilyproject.solrtestfw.TempSolrHome.java
private void copyResourceFiltered(String path, File destination, String autoCommitSetting) throws IOException { InputStream is = getClass().getClassLoader().getResourceAsStream(path); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); FileWriter writer = new FileWriter(destination); String placeholder = Pattern.quote("<!--AUTOCOMMIT_PLACEHOLDER-->"); String replacement = Matcher.quoteReplacement(autoCommitSetting); String line;//from w w w .j a v a2 s .c om while ((line = reader.readLine()) != null) { line = line.replaceAll(placeholder, replacement); writer.write(line); writer.write('\n'); } reader.close(); writer.close(); }
From source file:de.uzk.hki.da.format.CLIConversionStrategy.java
/** * Convert file./*from w ww . j av a 2 s.c o m*/ * * @param ci the ci * @return the list * @throws FileNotFoundException the file not found exception */ @Override public List<Event> convertFile(ConversionInstruction ci) throws FileNotFoundException { if (pkg == null) throw new IllegalStateException("Package not set"); Path.make(object.getDataPath(), object.getPath("newest").getLastElement(), ci.getTarget_folder()).toFile() .mkdirs(); String[] commandAsArray = assemble(ci, object.getPath("newest").getLastElement()); if (!cliConnector.execute(commandAsArray)) throw new RuntimeException("convert did not succeed"); String targetSuffix = ci.getConversion_routine().getTarget_suffix(); if (targetSuffix.equals("*")) targetSuffix = FilenameUtils.getExtension(ci.getSource_file().toRegularFile().getAbsolutePath()); DAFile result = new DAFile(pkg, object.getPath("newest").getLastElement(), ci.getTarget_folder() + "/" + FilenameUtils.removeExtension(Matcher.quoteReplacement( FilenameUtils.getName(ci.getSource_file().toRegularFile().getAbsolutePath()))) + "." + targetSuffix); Event e = new Event(); e.setType("CONVERT"); e.setDetail(Utilities.createString(commandAsArray)); e.setSource_file(ci.getSource_file()); e.setTarget_file(result); e.setDate(new Date()); List<Event> results = new ArrayList<Event>(); results.add(e); return results; }
From source file:de.fau.osr.util.VisibleFilesTraverser.java
protected void handleFile(File file, int depth, Collection results) throws IOException { // Using unix-style file paths. String filename = file.toString().replaceAll(Matcher.quoteReplacement("\\"), "/"); for (String eachIgnore : ignoreList) if (filename.contains(eachIgnore)) return; results.add(startDirectory.relativize(file.toPath())); }
From source file:org.pentaho.cdf.context.autoinclude.DashboardMatchRule.java
private Pattern replaceTokens(Matcher cdaMatcher, String regex) { // replace $1 for group 1 in regex etc Matcher token = REPLACE_TOKEN.matcher(regex); StringBuffer sb = new StringBuffer(); while (token.find()) { int group = Integer.parseInt(token.group(1)); if (group < cdaMatcher.groupCount()) { token.appendReplacement(sb, Matcher.quoteReplacement(Pattern.quote(cdaMatcher.group(group)))); } else {/*from w ww . ja v a 2s .c om*/ log.error(String.format("Error processing rule '%s', group %d does not exist.", regex, group)); } } token.appendTail(sb); return Pattern.compile(sb.toString()); }
From source file:com.tunyk.mvn.plugins.htmlcompressor.FileTool.java
public void writeToJsonFile(Map<String, String> map, String targetFile, String integrationCode) throws IOException, JSONException { String replacePattern = "%s"; File file = new File(targetFile); JSONObject json = new JSONObject(); for (String key : map.keySet()) { json.put(key, map.get(key));//from w w w. j a v a 2 s . co m } if (integrationCode == null) { integrationCode = replacePattern; } if (integrationCode.indexOf(replacePattern) == -1) { integrationCode += replacePattern; } String contents = integrationCode.replaceFirst(replacePattern, Matcher.quoteReplacement(json.toString())); FileUtils.writeStringToFile(file, contents, fileEncoding); }
From source file:com.dianping.lion.service.impl.DefaultConfigValueResolver.java
@Override public String resolve(String configval, int envId) { if (configval == null) { return null; }/*from ww w .jav a 2 s .c o m*/ if (configval.contains(ServiceConstants.REF_CONFIG_PREFIX)) { try { Matcher matcher = ServiceConstants.REF_EXPR_PATTERN.matcher(configval); boolean referenceFound = false; StringBuffer buffer = new StringBuffer(configval.length() * 2); while (matcher.find()) { referenceFound = true; String refkey = matcher.group(1); Config refconfig = configService.findConfigByKey(refkey); if (refconfig == null) { logger.warn("Referenced config[" + refkey + "] not found."); return null; } ConfigInstance refinstance = configService.findInstance(refconfig.getId(), envId, ConfigInstance.NO_CONTEXT); if (refinstance == null) { logger.warn("Referenced config[" + refkey + "] with env[" + envId + "] not found."); return null; } String refval = refinstance.getValue(); if (refval == null) { logger.warn("Reference null-valued config[" + refkey + "] with env[" + envId + "]."); return null; } String refparams = matcher.group(3); if (StringUtils.isNotBlank(refparams)) { String[] paramList = StringUtils.split(refparams, "&"); for (String paramstr : paramList) { String[] paramentry = StringUtils.split(paramstr, "="); refval = StringUtils.replace(refval, "${" + paramentry[0] + "}", paramentry[1]); } } matcher.appendReplacement(buffer, Matcher.quoteReplacement(refval)); } if (referenceFound) { matcher.appendTail(buffer); return buffer.toString(); } } catch (RuntimeException e) { logger.error("Resolve referenced config expression[" + configval + "] failed.", e); throw e; } } return configval; }
From source file:py.una.pol.karaku.menu.client.MenuHelper.java
private String replace(String src, String toReplace, String replacement) { return src.replaceAll(Pattern.quote(toReplace), Matcher.quoteReplacement(replacement)); }