List of usage examples for java.util.regex Matcher quoteReplacement
public static String quoteReplacement(String s)
From source file:net.bitnine.agensgraph.graph.property.Jsonb.java
@Override public String getValue() { if (JsonType.STRING == getJsonType()) return "\"" + jsonValue.toString().replaceAll("\"", Matcher.quoteReplacement("\\\"")) + "\""; else/*w w w .jav a 2s. co m*/ return jsonValue.toString(); }
From source file:io.wcm.devops.conga.plugins.aem.validator.AnyValidator.java
/** * Replace ticks (') for properties with quotes (") because the old java ANY file parser implementation * does not support them./* w ww .jav a2s . c om*/ * @param anyFileContent Any file content * @return Content with ticks replaces */ static String replaceTicks(String anyFileContent) { StringBuffer result = new StringBuffer(); Matcher matcher = TICK_PROPERTY.matcher(anyFileContent); while (matcher.find()) { matcher.appendReplacement(result, "/" + Matcher.quoteReplacement(matcher.group(1)) + " \"" + Matcher.quoteReplacement(matcher.group(2)) + "\""); } matcher.appendTail(result); return result.toString(); }
From source file:org.sventon.util.HTMLCreator.java
/** * Creates a string containing the details for a given revision. * * @param bodyTemplate Body template string. * @param logEntry log entry revision. * @param baseURL Application base URL. * @param repositoryName Repository name. * @param response Response, null if n/a. * @param dateFormat Date formatter instance. * @return Result//w w w .j av a 2 s .com */ public static String createRevisionDetailBody(final String bodyTemplate, final LogEntry logEntry, final String baseURL, final RepositoryName repositoryName, final DateFormat dateFormat, final HttpServletResponse response) { final Map<String, String> valueMap = new HashMap<String, String>(); int added = 0; int modified = 0; int replaced = 0; int deleted = 0; //noinspection unchecked final SortedSet<ChangedPath> latestChangedPaths = logEntry.getChangedPaths(); for (final ChangedPath entryPath : latestChangedPaths) { final ChangeType type = entryPath.getType(); switch (type) { case ADDED: added++; break; case MODIFIED: modified++; break; case REPLACED: replaced++; break; case DELETED: deleted++; break; default: throw new IllegalArgumentException("Unsupported type: " + type); } } final String logMessage = WebUtils.nl2br(StringEscapeUtils.escapeHtml(logEntry.getMessage())); //TODO: Parse to apply Bugtraq link final String author = logEntry.getAuthor(); valueMap.put(ADDED_COUNT_KEY, Matcher.quoteReplacement(String.valueOf(added))); valueMap.put(MODIFIED_COUNT_KEY, Matcher.quoteReplacement(String.valueOf(modified))); valueMap.put(REPLACED_COUNT_KEY, Matcher.quoteReplacement(String.valueOf(replaced))); valueMap.put(DELETED_COUNT_KEY, Matcher.quoteReplacement(String.valueOf(deleted))); valueMap.put(LOG_MESSAGE_KEY, Matcher.quoteReplacement(StringUtils.trimToEmpty(logMessage))); valueMap.put(AUTHOR_KEY, Matcher.quoteReplacement(StringUtils.trimToEmpty(author))); valueMap.put(DATE_KEY, dateFormat.format(logEntry.getDate())); valueMap.put(CHANGED_PATHS_KEY, Matcher.quoteReplacement(HTMLCreator.createChangedPathsTable(logEntry.getChangedPaths(), logEntry.getRevision(), null, baseURL, repositoryName, false, false, response))); return new StrSubstitutor(valueMap).replace(bodyTemplate); }
From source file:org.entando.edo.model.EdoBuilder.java
public String getJavaTestFolder() { String pojoPath = this.getBaseDir() + FolderConstants.getJavaTestFolder() + this.getPackageName().replaceAll("\\.", Matcher.quoteReplacement(File.separator)) + File.separator;/* ww w . j a va 2 s.co m*/ return pojoPath; }
From source file:com.yukthitech.utils.MessageFormatter.java
/** * Replaces the args values in "message" using patterns mentioned below and same will be returned. * //from ww w. j av a 2 s . c o m * {} will match with the current index argument. If index is greater than provided values then <undefined> string will be used. * {<idx>} can be used to refer to argument at particular index. Helpful in building messages which uses same argument multiple times. * * @param message Message string with expressions * @param args Values for expression * @return Formatted string */ public static String format(String message, Object... args) { //when message is null, return null if (message == null) { return null; } //when args is null, assume empty values if (args == null) { args = new Object[0]; } Matcher matcher = PARAM_PATTERN.matcher(message); StringBuffer buffer = new StringBuffer(); int loopIndex = 0; int argIndex = 0; Object arg = null; //loop through pattern matches while (matcher.find()) { //if index is mentioned in pattern if (org.apache.commons.lang3.StringUtils.isNotBlank(matcher.group(1))) { argIndex = Integer.parseInt(matcher.group(1)); } //if index is not specified, use current loop index else { argIndex = loopIndex; } //if the index is within provided arguments length if (argIndex < args.length) { arg = args[argIndex]; } //if the index is greater than available values else { arg = UNDEFINED; } //if argument value is null if (arg == null) { arg = "null"; } arg = Matcher.quoteReplacement(arg.toString()); matcher.appendReplacement(buffer, arg.toString()); loopIndex++; } matcher.appendTail(buffer); return buffer.toString(); }
From source file:de.uzk.hki.da.format.PublishCLIConversionStrategy.java
@Override public List<Event> convertFile(ConversionInstruction ci) throws FileNotFoundException { if (pkg == null) throw new IllegalStateException("Package not set"); List<Event> results = new ArrayList<Event>(); for (String audience : audiences) { String audience_lc = audience.toLowerCase(); String repName = "dip/" + audience_lc; Path.make(object.getDataPath(), repName, ci.getTarget_folder()).toFile().mkdirs(); String[] commandAsArray = assemble(ci, repName); 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, repName, 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);/*w ww . j av a 2s .co m*/ e.setDate(new Date()); results.add(e); } return results; }
From source file:io.wcm.devops.conga.generator.util.VariableStringResolver.java
private static String resolve(String value, Map<String, Object> variables, int iterationCount) { if (iterationCount >= REPLACEMENT_MAX_ITERATIONS) { throw new IllegalArgumentException("Cyclic dependencies in variable string detected: " + value); }// w w w . j a v a2 s . c o m Matcher matcher = VARIABLE_PATTERN.matcher(value); StringBuffer sb = new StringBuffer(); boolean replacedAny = false; while (matcher.find()) { boolean escapedVariable = StringUtils.equals(matcher.group(1), "\\$"); String variable = matcher.group(2); if (escapedVariable) { // keep escaped variables intact matcher.appendReplacement(sb, Matcher.quoteReplacement("\\${" + variable + "}")); } else { Object valueObject = MapExpander.getDeep(variables, variable); if (valueObject != null) { String variableValue = valueToString(valueObject); matcher.appendReplacement(sb, Matcher.quoteReplacement(variableValue.toString())); replacedAny = true; } else { throw new IllegalArgumentException("Unknown variable: " + variable); } } } matcher.appendTail(sb); if (replacedAny) { // try again until all nested references are resolved return resolve(sb.toString(), variables, iterationCount + 1); } else { return sb.toString(); } }
From source file:pt.webdetails.cdf.dd.model.inst.writer.cdfrunjs.dashboard.CdfRunJsDashboardWriteResult.java
public String render(String dashboardContext, String contextConfiguration) { return this._template .replaceAll(CdeConstants.DASHBOARD_HEADER_TAG, Matcher.quoteReplacement(dashboardContext)) .replaceFirst(CdeConstants.DASHBOARD_CONTEXT_CONFIGURATION_TAG, StringUtils.defaultIfEmpty(Matcher.quoteReplacement(contextConfiguration), "{}")); }
From source file:org.infoscoop.widgetconf.I18NConverter.java
public String replace(String str) { if (this.replaceMap == null) return str; for (Iterator it = this.replaceMap.keySet().iterator(); it.hasNext();) { String key = (String) it.next(); String value = (String) this.replaceMap.get(key); str = str.replaceAll("__MSG_" + key + "__", Matcher.quoteReplacement(value)); }//w w w .j av a 2 s. co m for (BidiKey key : bidiReplaceMap.keySet()) str = str.replaceAll("__BIDI_" + key + "__", bidiReplaceMap.get(key)); return str; }