List of usage examples for java.util.regex Matcher appendTail
public StringBuilder appendTail(StringBuilder sb)
From source file:com.mobile.system.db.abatis.AbatisService.java
/** *//from w w w. j a v a 2 s . c o m */ private String chgDataName(String targetStr) { Pattern p = Pattern.compile("_([a-z])"); Matcher m = p.matcher(targetStr.toLowerCase()); StringBuffer sb = new StringBuffer(targetStr.length()); while (m.find()) { m.appendReplacement(sb, m.group(1).toUpperCase()); } m.appendTail(sb); return sb.toString(); }
From source file:org.kite9.diagram.server.AbstractKite9Controller.java
protected String sanitizeFilePath(String badFileName) { StringBuffer cleanFileName = new StringBuffer(); Matcher fileMatcher = filePattern.matcher(badFileName); boolean match = fileMatcher.find(); while (match) { fileMatcher.appendReplacement(cleanFileName, ""); match = fileMatcher.find();//from www . ja va2 s .c om } fileMatcher.appendTail(cleanFileName); return cleanFileName.substring(0, cleanFileName.length() > 250 ? 250 : cleanFileName.length()); }
From source file:ru.xxlabaza.popa.pack.PackingService.java
private String correctURLs(Path path, String content) { Matcher matcher = CSS_URL_PATTERN.matcher(content); StringBuffer buffer = new StringBuffer(content.length()); while (matcher.find()) { String url = matcher.group(1); String[] tokens = url.split("[\\?#]", 2); Path pathToUrlFile = path.getParent().resolve(tokens[0]); Path urlPath = build.relativize(pathToUrlFile); if (Files.exists(pathToUrlFile)) { FileSystemUtils.copy(pathToUrlFile, compressed.resolve(urlPath)); }// w w w. j av a2s.c o m StringBuilder sb = new StringBuilder('/'); sb.append(urlPath); if (tokens.length > 1) { sb.append(url.contains("?") ? '?' : '#').append(tokens[1]); } matcher.appendReplacement(buffer, sb.toString()); } matcher.appendTail(buffer); return buffer.toString(); }
From source file:org.obm.push.protocol.data.HTMLBodyFormatter.java
public StringBuffer parseUrl(Matcher m) { StringBuffer result = new StringBuffer(); Pattern pEmail = Pattern.compile(PATTERN_EMAIL); Pattern pUrl = Pattern.compile(PATTERN_URL); while (m.find()) { String href = m.group();//from w w w .ja v a 2 s . c o m Matcher mEmail = pEmail.matcher(href); Matcher mUrl = pUrl.matcher(href); if (mUrl.find()) { if (href.startsWith("http")) { m.appendReplacement(result, "<a href=\"" + href + "\" target=\"_blank\">" + href + "</a>"); } else { m.appendReplacement(result, "<a href=\"http://" + href + "\" target=\"_blank\">" + href + "</a>"); } } else if (mEmail.find()) { m.appendReplacement(result, "<a href=mailto:" + href + ">" + href + "</a>"); } } m.appendTail(result); return result; }
From source file:org.obm.push.data.formatter.HTMLBodyFormatter.java
public StringBuffer parseUrl(Matcher m, StringBuilder input) { StringBuffer result = new StringBuffer(); Pattern pEmail = Pattern.compile(PATTERN_EMAIL); Pattern pUrl = Pattern.compile(PATTERN_URL); while (m.find()) { String href = m.group();// ww w . j a va 2 s . c o m Matcher mEmail = pEmail.matcher(href); Matcher mUrl = pUrl.matcher(href); if (mUrl.find()) { if (href.startsWith("http")) { m.appendReplacement(result, "<a href=\"" + href + "\" target=\"_blank\">" + href + "</a>"); } else { m.appendReplacement(result, "<a href=\"http://" + href + "\" target=\"_blank\">" + href + "</a>"); } } else if (mEmail.find()) { m.appendReplacement(result, "<a href=mailto:" + href + ">" + href + "</a>"); } } m.appendTail(result); return result; }
From source file:jp.go.nict.langrid.wrapper.ws_1_2.translation.AbstractTranslationService.java
/** * ??<br/>/*from www .ja v a 2 s . c o m*/ * ????divideByDelimiterAndTranslation ???<br/> * @author Hitoshi Sugihara * @param source ? * @param deli ?? Pattern * @param delis ????????? * @return ??????? */ private String[] divideSourceByDelimiter(String source, java.util.regex.Pattern deli, java.util.List<String> delis) { java.util.List<String> sources = new java.util.ArrayList<String>(); // ???????????? java.util.regex.Matcher mth = deli.matcher(source); // ??? Matcher StringBuffer hoge; // ???????? while (mth.find()) { delis.add(mth.group()); hoge = new StringBuffer(); mth.appendReplacement(hoge, ""); sources.add(hoge.toString()); } hoge = new StringBuffer(); mth.appendTail(hoge); if (hoge.length() > 0) { sources.add(hoge.toString()); } return sources.toArray(new String[] {}); }
From source file:by.heap.remark.convert.TextCleaner.java
/** * Handles running the regex-based replacements in the input * @param input String to process/*from w ww . j a v a 2 s . c o m*/ * @param regex Pattern to use * @return cleaned up input string */ private StringBuffer doReplacements(CharSequence input, Pattern regex) { StringBuffer output = new StringBuffer(); Matcher m = regex.matcher(input); while (m.find()) { String repString; // if we have a hard match, do a simple replacement. String replacementKey = m.group().toLowerCase(Locale.ENGLISH); if (replacements.containsKey(replacementKey)) { repString = replacements.get(replacementKey); } else { // special case for escaped HTML entities. repString = "\\\\&$1"; } m.appendReplacement(output, repString); } m.appendTail(output); return output; }
From source file:it.wingstech.csslesser.LessifyMojo.java
private String inline(File f, String prefix) throws MojoExecutionException { if (f.isFile()) { getLog().info("Inlining file: " + f.getAbsolutePath() + " ..."); try {/*from w w w . j a va 2s . co m*/ String content = FileUtils.readFileToString(f); Pattern p = Pattern.compile("(" + Pattern.quote("@import url(") + "[\\'\\\"]?)(.*?)([\\'\\\"]?" + Pattern.quote(");") + ")"); Matcher m = p.matcher(content); StringBuffer sb = new StringBuffer(); while (m.find() == true) { String url = m.group(2); getLog().info(" importing file: " + url + " ..."); String cPrefix = "."; int ix = url.lastIndexOf("/"); if (ix > 0) { cPrefix = url.substring(0, ix); } String inputReplacement = inline( new File(f.getParentFile().getAbsolutePath() + File.separator + m.group(2)), cPrefix); m.appendReplacement(sb, inputReplacement); } m.appendTail(sb); String result = sb.toString(); FileUtils.writeStringToFile(f, result); StringBuffer sbIncludeImages = new StringBuffer(); Pattern pImgReplacement = Pattern.compile( "(" + Pattern.quote("url(") + "[\\'\\\"]?)(.*?)([\\'\\\"]?" + Pattern.quote(")") + ")"); Matcher mImgReplacement = pImgReplacement.matcher(result); while (mImgReplacement.find() == true) { String urlImage = mImgReplacement.group(2); if (!urlImage.startsWith("/")) { urlImage = prefix + "/" + urlImage; } mImgReplacement.appendReplacement(sbIncludeImages, "url('" + urlImage + "')"); } mImgReplacement.appendTail(sbIncludeImages); return sbIncludeImages.toString(); } catch (Exception ex) { throw new MojoExecutionException(ex.getMessage() + " on file " + f.getAbsolutePath(), ex); } } return ""; }
From source file:org.rhq.plugins.jbossas5.script.ScriptComponent.java
private String replacePropertyPatterns(String envVars) { Pattern pattern = Pattern.compile("(%([^%]*)%)"); Matcher matcher = pattern.matcher(envVars); Configuration parentPluginConfig = this.resourceContext.getParentResourceComponent().getResourceContext() .getPluginConfiguration();/*from w w w . j a v a 2 s . c o m*/ StringBuffer buffer = new StringBuffer(); while (matcher.find()) { String propName = matcher.group(2); PropertySimple prop = parentPluginConfig.getSimple(propName); String propPattern = matcher.group(1); String replacement = (prop != null) ? prop.getStringValue() : propPattern; matcher.appendReplacement(buffer, Matcher.quoteReplacement(replacement)); } matcher.appendTail(buffer); return buffer.toString(); }
From source file:fr.aliasource.webmail.formatting.HTMLBodyFormatter.java
private StringBuffer parseUrl(Matcher m, StringBuilder input) { StringBuffer result = new StringBuffer(); Pattern pEmail = Pattern.compile(PATTERN_EMAIL); Pattern pUrl = Pattern.compile(PATTERN_URL); while (m.find()) { String href = m.group();/* ww w . j a v a 2s. co m*/ Matcher mEmail = pEmail.matcher(href); Matcher mUrl = pUrl.matcher(href); if (mUrl.find()) { if (href.startsWith("http")) { m.appendReplacement(result, "<a href=\"" + href + "\" target=\"_blank\">" + href + "</a>"); } else { m.appendReplacement(result, "<a href=\"http://" + href + "\" target=\"_blank\">" + href + "</a>"); } } else if (mEmail.find()) { m.appendReplacement(result, "<a href=mailto:" + href + ">" + href + "</a>"); } } m.appendTail(result); return result; }