List of usage examples for java.util.regex Matcher quoteReplacement
public static String quoteReplacement(String s)
From source file:org.etudes.util.XrefHelper.java
/** * For email notifications, revise embedded media relative url to full url. * //from www.jav a 2s . com * @param data * The message data with relative urls. * @return data with full urls. */ public static String fullUrls(String data) { if (data == null) return data; Pattern p = getPattern(); Matcher m = p.matcher(data); StringBuffer sb = new StringBuffer(); String serverUrl = ServerConfigurationService.getServerUrl(); // for the relative access check: matches /access/ Pattern relAccessPattern = Pattern.compile("/access/.*"); // process each "harvested" string (avoiding like strings that are not in src= or href= patterns) while (m.find()) { if (m.groupCount() == 3) { String ref = m.group(2); String terminator = m.group(3); // if this is an access to our own server, make it full URL (i.e. starting with "/access") Matcher relAccessMatcher = relAccessPattern.matcher(ref); if (relAccessMatcher.matches()) { m.appendReplacement(sb, Matcher.quoteReplacement(m.group(1) + "=\"" + serverUrl + ref + terminator)); } } } m.appendTail(sb); return sb.toString(); }
From source file:com.gh4a.utils.HtmlUtils.java
/** * Rewrite relative URLs in HTML fetched e.g. from markdown files. * * @param html//w ww . j a v a 2 s. c om * @param repoUser * @param repoName * @param branch * @return */ public static String rewriteRelativeUrls(final String html, final String repoUser, final String repoName, final String branch) { final String baseUrl = "https://raw.github.com/" + repoUser + "/" + repoName + "/" + branch; final StringBuffer sb = new StringBuffer(); final Pattern p = Pattern.compile("(href|src)=\"(\\S+)\""); final Matcher m = p.matcher(html); while (m.find()) { String url = m.group(2); if (!url.contains("://") && !url.startsWith("#")) { if (url.startsWith("/")) { url = baseUrl + url; } else { url = baseUrl + "/" + url; } } m.appendReplacement(sb, Matcher.quoteReplacement(m.group(1) + "=\"" + url + "\"")); } m.appendTail(sb); return sb.toString(); }
From source file:org.omnaest.utils.table.impl.serializer.CsvMarshallerImpl.java
/** * Encodes a single cell element into its csv string form * /*from w w w . j a v a2 s .com*/ * @param element * @return */ private String encodeIntoCellString(final E element) { // String retval = null; // if (element != null) { // retval = String.valueOf(element); // final boolean containsDelimiter = retval.contains(this.configuration.getDelimiter()); final boolean containsQuotationCharacter = StringUtils .isNotEmpty(this.configuration.getQuotationCharacter()) && retval.contains(this.configuration.getQuotationCharacter()); if (containsQuotationCharacter) { retval = retval.replaceAll(Pattern.quote(this.configuration.getQuotationCharacter()), Matcher.quoteReplacement(this.configuration.getQuotationCharacter() + this.configuration.getQuotationCharacter())); } if (containsDelimiter) { retval = this.configuration.getQuotationCharacter() + retval + this.configuration.getQuotationCharacter(); } } // return retval; }
From source file:org.entando.edo.builder.TestBuilderNoPlugin.java
@Test public void test_Service_Xml() throws IOException { String commonPath = "src/main/resources/spring/sandbox/aps".replaceAll("/", Matcher.quoteReplacement(File.separator)); String actualPath = ACTUAL_BASE_FOLDER + commonPath; File actualDir = new File(actualPath); Assert.assertTrue(actualDir.exists()); List<File> actualFiles = this.searchFiles(actualDir, null); Assert.assertEquals(1, actualFiles.size()); this.compareFiles(actualFiles); }
From source file:org.nuxeo.launcher.commons.text.TextTemplate.java
public Properties preprocessVars(Properties unprocessedVars) { Properties newVars = new Properties(unprocessedVars); boolean doneProcessing = false; int recursionLevel = 0; while (!doneProcessing) { doneProcessing = true;/*from w w w . ja va 2s . c om*/ @SuppressWarnings("rawtypes") Enumeration newVarsEnum = newVars.propertyNames(); while (newVarsEnum.hasMoreElements()) { String newVarsKey = (String) newVarsEnum.nextElement(); String newVarsValue = newVars.getProperty(newVarsKey); Matcher m = PATTERN.matcher(newVarsValue); StringBuffer sb = new StringBuffer(); while (m.find()) { String embeddedVar = m.group(1); String value = newVars.getProperty(embeddedVar); if (value != null) { if (trim) { value = value.trim(); } String escapedValue = Matcher.quoteReplacement(value); m.appendReplacement(sb, escapedValue); } } m.appendTail(sb); String replacementValue = sb.toString(); if (!replacementValue.equals(newVarsValue)) { doneProcessing = false; newVars.put(newVarsKey, replacementValue); } } recursionLevel++; // Avoid infinite replacement loops if ((!doneProcessing) && (recursionLevel > MAX_RECURSION_LEVEL)) { break; } } return unescape(newVars); }
From source file:org.entando.edo.builder.TestBuilder.java
@Test public void test_Service_Xml() throws IOException { String commonPath = "src/main/resources/spring/plugins/jppet/aps".replaceAll("/", Matcher.quoteReplacement(File.separator)); String actualPath = ACTUAL_BASE_FOLDER + commonPath; File actualDir = new File(actualPath); Assert.assertTrue(actualDir.exists()); List<File> actualFiles = this.searchFiles(actualDir, null); Assert.assertEquals(1, actualFiles.size()); this.compareFiles(actualFiles); }
From source file:org.omnaest.utils.codec.EncoderAndDecoderEscaping.java
@Override public String decode(String source) { String retval = source;//from w w w. ja v a 2s . com { if (retval != null) { for (String escapeSequence : ListUtils.reverse(this.escapeSequenceToEncodedCharacterMap.keySet())) { final String encodedCharacter = this.escapeSequenceToEncodedCharacterMap.get(escapeSequence); retval = retval.replaceAll(Pattern.quote(escapeSequence), Matcher.quoteReplacement(encodedCharacter)); } } } return retval; }
From source file:annis.administration.AbstractAdminstrationDao.java
@SuppressWarnings("unchecked") private String readSqlFromResource(Resource resource, MapSqlParameterSource args) { // XXX: uses raw type, what are the parameters to Map in MapSqlParameterSource? Map<String, Object> parameters = args != null ? args.getValues() : new HashMap(); try (BufferedReader reader = new BufferedReader( new InputStreamReader(new FileInputStream(resource.getFile()), "UTF-8"));) { StringBuilder sqlBuf = new StringBuilder(); for (String line = reader.readLine(); line != null; line = reader.readLine()) { sqlBuf.append(line).append("\n"); }/*from w ww .j a v a 2 s .c om*/ String sql = sqlBuf.toString(); for (Map.Entry<String, Object> placeHolderEntry : parameters.entrySet()) { String key = placeHolderEntry.getKey(); String value = placeHolderEntry.getValue().toString(); log.debug("substitution for parameter '" + key + "' in SQL script: " + value); sql = sql.replaceAll(key, Matcher.quoteReplacement(value)); } return sql; } catch (IOException e) { log.error("Couldn't read SQL script from resource file.", e); throw new FileAccessException("Couldn't read SQL script from resource file.", e); } }
From source file:org.slc.sli.ingestion.tenant.TenantPopulator.java
/** * * Process TenantRecord, Replacing hostname and lzPath placeholder fields with * the actual values.//w w w .j a va 2s. com * * @param tenant * record to be processed * @param hostname * the hostname to be used in placeholder replacement */ private void replaceTenantPlaceholderFields(TenantRecord tenant, String hostname) { List<LandingZoneRecord> landingZones = tenant.getLandingZone(); for (LandingZoneRecord lz : landingZones) { // replace hostname field String serverVal = lz.getIngestionServer(); serverVal = serverVal.replaceFirst(HOSTNAME_PLACEHOLDER, hostname); lz.setIngestionServer(serverVal); String pathVal = lz.getPath(); pathVal = pathVal.replaceFirst(PARENT_LZ_PATH_PLACEHOLDER, Matcher.quoteReplacement(parentLandingZoneDir)); lz.setPath(new File(pathVal).getAbsolutePath()); } }
From source file:net.ymate.framework.core.taglib.ui.BaseUITag.java
public void writerToBodyPart(String content) { __tmplBodyPart.append(Matcher.quoteReplacement(content)); }