List of usage examples for java.util.regex Matcher appendTail
public StringBuilder appendTail(StringBuilder sb)
From source file:com.gs.obevo.db.impl.platforms.db2.Db2lookReveng.java
public static AbstractDdlReveng.LineParseOutput substituteTablespace(String input) { Pattern compile = Pattern.compile("(\\s+IN\\s+)\"(\\w+)\"(\\s*)", Pattern.DOTALL); StringBuffer sb = new StringBuffer(input.length()); String addedToken = null;// ww w. j av a2s. c o m String addedValue = null; Matcher matcher = compile.matcher(input); if (matcher.find()) { addedToken = matcher.group(2) + "_token"; addedValue = matcher.group(2); matcher.appendReplacement(sb, matcher.group(1) + "\"\\${" + addedToken + "}\"" + matcher.group(3)); } matcher.appendTail(sb); return new AbstractDdlReveng.LineParseOutput(sb.toString()).withToken(addedToken, addedValue); }
From source file:org.onehippo.cms7.essentials.components.utils.SiteUtils.java
/** * Replaces <strong>{@code ${variableName}}</strong> variable in a template with the replacement value provided. * * @param variableName variable name * @param replacementValue replacement value * @param template string which contains variable e.g * <p /><strong>{@code My name is ${username} and my login is ${login}}</strong> * @return string (template with string replacements) *///from ww w . ja va 2 s .c om public static String replacePlaceHolders(final String variableName, final String replacementValue, final CharSequence template) { Pattern pattern = Pattern.compile("(\\$\\{" + variableName + "*\\})"); Matcher matcher = pattern.matcher(template); StringBuffer buffer = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(buffer, replacementValue); } matcher.appendTail(buffer); return buffer.toString(); }
From source file:org.neo4j.browser.CannedCypherExecutionTest.java
private static String replaceAngularExpressions(String statement) { Pattern angularExpressionPattern = Pattern.compile("\\{\\{(.*?)}}"); Matcher matcher = angularExpressionPattern.matcher(statement); StringBuffer buffer = new StringBuffer(); while (matcher.find()) { String expression = matcher.group(1); matcher.appendReplacement(buffer, chooseSuitableExpressionValue(expression)); }/*from w ww. ja v a 2 s .co m*/ matcher.appendTail(buffer); return buffer.toString(); }
From source file:org.codehaus.mojo.hibernate3.processor.ProcessorUtil.java
public static String insertImportIntoClassDefinition(String importCode, String body) { StringBuffer buffer = new StringBuffer(); Matcher matcher = pkgImportPattern.matcher(body); String importStmt = "import " + importCode + ";"; if (body.contains(importStmt)) { return body; }//w ww. jav a 2s .c o m while (matcher.find()) { String replacement = matcher.group(0) + " " + importStmt + "\n"; matcher.appendReplacement(buffer, replacement); } matcher.appendTail(buffer); return buffer.toString(); }
From source file:org.apache.fop.events.EventFormatter.java
private static int processIncludesInner(CharSequence template, StringBuffer sb, ResourceBundle bundle) { int replacements = 0; if (bundle != null) { Matcher m = INCLUDES_PATTERN.matcher(template); while (m.find()) { String include = m.group(); include = include.substring(2, include.length() - 2); m.appendReplacement(sb, bundle.getString(include)); replacements++;/*from w ww. ja v a 2 s . c o m*/ } m.appendTail(sb); } return replacements; }
From source file:org.bibsonomy.util.tex.TexDecode.java
/** * Decodes a String which contains TeX macros into it's Unicode * representation./*from w w w . ja v a2 s .c o m*/ * * @param s * @return Unicode representation of the String */ public static String decode(String s) { if (s != null) { final Matcher texRegexpMatcher = texRegexpPattern.matcher(s.trim().replaceAll(CURLY_BRACKETS, "")); final StringBuffer sb = new StringBuffer(); int i = 0; while (texRegexpMatcher.find()) { i++; texRegexpMatcher.appendReplacement(sb, texMap.get(texRegexpMatcher.group())); } texRegexpMatcher.appendTail(sb); return sb.toString().trim().replaceAll(BRACKETS, ""); } return ""; }
From source file:com.beyondjservlet.gateway.servlet.support.ProxySupport.java
/** * Returns the contents of a {@code Set-Cookie} header with it's optional {@code path} and * {@code domain} attributes replaced by the passed in values. * * @param header the {@code Set-Cookie} header for which {@code path} and {@code domain} should be replaced. * @param path the new path for the cookie. If null the original value of for path is used. * @param domain the domain for the cookie. If null the original value of for domain is used. * @return {@code String} the contents of the {@code Set-Cookie} header. The reason for not returning the complete * header including the headers name (Set-Cookie) is make this method useful with the * Java Servlet API and {@link HttpServletResponse#setHeader(String, String)}. *//* ww w . j a va 2s .c om*/ public static String replaceCookieAttributes(final String header, final String path, final String domain) { final Matcher m = PATH_AND_DOMAIN_PATTERN.matcher(header); final StringBuffer sb = new StringBuffer(); while (m.find()) { final String name = m.group(1); if ("domain".equalsIgnoreCase(name)) { appendReplacement(m, sb, name, domain); } else if ("path".equalsIgnoreCase(name)) { appendReplacement(m, sb, name, path); } } m.appendTail(sb); return sb.toString(); }
From source file:de.egore911.versioning.deployer.performer.PerformExtraction.java
/** * Returns the matching part of the entry's name. * //from w w w. j av a 2 s .c o m * FIXME assumes that the '*' is only used for matching files, not * directories! */ private static String getSourcePatternMatch(String entryName, String sourcePattern) { // Create a regular expression pattern for the given sourcePattern Pattern pattern = patternCache.get(sourcePattern); if (pattern == null) { // Pattern compilation is expensive, so cache it pattern = Pattern.compile(transformSourcePatternToRegularExpression(sourcePattern)); patternCache.put(sourcePattern, pattern); } // Perform the actual replacement Matcher matcher = pattern.matcher(entryName); StringBuffer buffer = new StringBuffer(); if (matcher.matches()) { if (matcher.groupCount() == 1) { matcher.appendReplacement(buffer, matcher.group(1)); } } matcher.appendTail(buffer); return buffer.toString(); }
From source file:koubachi.internal.json.JSONFactory.java
private static String cleanDateFormat(String json) { // takes in a string of JSON Pattern regex = Pattern.compile("\\d\\d:\\d\\d:\\d\\d[-\\+]\\d\\d:\\d\\d"); Matcher regexMatcher = regex.matcher(json); StringBuffer buff = new StringBuffer(); while (regexMatcher.find()) { regexMatcher.appendReplacement(buff, getSubOfMatch(regexMatcher)); }//from w ww . ja v a 2s. com regexMatcher.appendTail(buff); return buff.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; }// www . j av a2s.c om 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(); }