List of usage examples for java.util.regex Matcher replaceAll
public String replaceAll(Function<MatchResult, String> replacer)
From source file:io.netty.verify.osgi.DependencyIT.java
@Test public void verifyKarafFeatureHasNoWrapProtocol() throws Exception { String text = FileUtils.readFileToString(new File(FEATURE)); // Ignore wrap:mvn:io.netty - it occurs when Maven didn't give the Netty modules to karaf-maven-plugin // as class directories. Matcher matcher = WRAPPED_MODULE_PATTERN.matcher(text); if (matcher.find()) { text = matcher.replaceAll("mvn:io.netty/"); logger.info("Ignored wrap:mvn:io.netty"); }/* w ww .j a v a 2 s . c o m*/ if (text.contains("wrap:")) { fail("feature.xml generated by karaf-maven-plugin contains 'wrap:' protocol; " + "some transitive dependencies are not OSGi bundles: " + StringUtil.NEWLINE + text); } else { logger.info("All transitive dependencies are OSGi bundles."); } }
From source file:com.adaptris.core.metadata.MappedKeyMetadataFilter.java
private String renameKey(String orig) { if (prefixPattern == null) { prefixPattern = Pattern.compile(prefix); }//from ww w.jav a 2s . com Matcher prefixMatcher = prefixPattern.matcher(orig); return prefixMatcher.replaceAll(replacementValue()); }
From source file:edu.emory.mathcs.nlp.zzz.CSVRadiology.java
void print(PrintStream fout, List<Token> tokens) { String s = Joiner.join(tokens, " "); for (Pair<Pattern, String> p : P_BEFORE) { Matcher m = p.o1.matcher(s); if (m.find()) s = m.replaceAll(p.o2); }/* w w w . j a va 2s . c om*/ for (Pair<Pattern, String> p : P_AFTER) { Matcher m = p.o1.matcher(s); if (m.find()) s = m.replaceAll(p.o2); } for (String t : NEW_LINE.split(s)) { t = t.trim(); if (!t.isEmpty()) fout.println(t.trim()); } }
From source file:com.esri.geoevent.solutions.adapter.regexText.RegexTextInboundAdapter.java
@Override public void receive(ByteBuffer buf, String str) { ByteBuffer bb = buf;//from w w w . j a va 2 s .c o m // Check first whether we need to do anything different from the out-of-the-box TextAdapter if (StringUtils.isNotBlank(separatorToBeReplaced)) { // Decode the buffer CharSequence charseq = decode(buf); // Replace the attribute separator with a simple one log.debug("Replacing separator '" + separatorToBeReplaced + "' with '" + attributeSeparator + "'"); Pattern p = Pattern.compile(separatorToBeReplaced); Matcher m = p.matcher(charseq); String newString = m.replaceAll(attributeSeparator); // Put up some debugging info if (newString.length() >= 300) log.debug( newString.substring(0, 300) + "...---..." + newString.substring(newString.length() - 300)); else log.debug(newString); // Re-encode the string into a byte buffer bb = encode(newString); } // Let the base class now handle the input as normal super.receive(bb, str); }
From source file:net.sf.j2ep.servers.ClusterResponseWrapper.java
/** * Rewrites the header Set-Cookie so that path and domain * is correct./*w w w.j av a2s . c o m*/ * * @param value The original header * @return The rewritten header */ private String rewriteSetCookie(String value) { Matcher matcher = sessionPattern.matcher(value); String rewritten = matcher.replaceAll("$1$2" + serverId); if (log.isDebugEnabled() && !rewritten.equals(value)) { log.debug("Session found and rewritten \"" + value + "\" >> " + rewritten); } return rewritten; }
From source file:org.jnap.core.persistence.jpa.QueryPagingSetup.java
public long countTotal() { // build the count query String countHql = getQueryString(query); int indexOfFromClause = countHql.toLowerCase().indexOf("from"); countHql = countHql.substring(indexOfFromClause, countHql.length()); countHql = "select count(*) " + countHql; countHql = countHql.replaceAll("(?i)fetch", StringUtils.EMPTY); // remove 'order by' clauses if present - for performance reasons Matcher orderByMatcher = ORDER_BY_REMOVE_REGEXP.matcher(countHql); countHql = orderByMatcher.replaceAll(StringUtils.EMPTY); Query countQuery = this.entityManager.createQuery(countHql); QueryUtils.setParameters(countQuery, this.queryParams); return ((Number) countQuery.getSingleResult()).intValue(); }
From source file:org.eclipse.birt.report.model.parser.Base64PropertyState.java
/** * Sets the image data value as base 64 string. * /*from ww w.j ava 2 s .co m*/ * @param value * the value to set */ private String getDecodedBase64Value(String value) { String encodedValue = StringUtil.trimString(value); if (encodedValue == null) return null; // replace whitespace with the empty string. Pattern p = Pattern.compile("\\s"); //$NON-NLS-1$ Matcher m = p.matcher(encodedValue); encodedValue = m.replaceAll(""); //$NON-NLS-1$ byte[] data = null; try { data = base.decode(encodedValue.getBytes(charSet)); if (data == null) return null; return new String(data, charSet); } catch (UnsupportedEncodingException e) { assert false; return null; } }
From source file:org.obiba.mica.core.upgrade.AttachmentsPathUpgrade.java
@Override public void execute(Version version) { log.info("Executing attachments path property upgrade"); Pattern pattern = Pattern.compile("[\\$%/#]"); attachmentRepository.findAll().forEach(a -> { boolean isModified = false; if (a.getPath() != null && a.getPath().contains("/attachment/")) { a.setPath(a.getPath().replaceAll("/attachment/[0-9a-f\\-]+$", "")); isModified = true;/*from w ww . ja v a 2s . c o m*/ } Matcher matcher = pattern.matcher(a.getName()); if (matcher.find()) { a.setName(matcher.replaceAll("_")); isModified = true; } if (isModified) fileSystemService.save(a); }); }
From source file:de.mpg.escidoc.services.aa.web.AaStart.java
/** * This servlet is expecting 2 parameters: * /*from w w w.j a v a 2s . c o m*/ * - tan: A random string generated by the client system to check whether the result is valid or not. * - target: The URL the user should be redirected to after authentication. * */ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { request.setCharacterEncoding(DEFAULT_ENCODING); response.setCharacterEncoding(DEFAULT_ENCODING); String from = request.getParameter("from"); String tan = request.getParameter("tan"); // TODO: Make this generic String handle = request.getParameter("eSciDocUserHandle"); Matcher matcher = authPattern.matcher(from); from = matcher.replaceAll(""); String target = request.getParameter("target"); if (target == null) { target = Config.getProperty("escidoc.aa.default.target"); } String separator = "?"; if (target.contains("?")) { separator = "&"; } target += separator + "target=" + URLEncoder.encode(from, "ISO-8859-1") + "&tan=" + URLEncoder.encode(tan, "ISO-8859-1"); if (handle != null) { target += "&eSciDocUserHandle=" + URLEncoder.encode(handle, "ISO-8859-1"); } response.sendRedirect(target); }
From source file:org.apache.flume.interceptor.SearchAndReplaceInterceptor.java
@Override public Event intercept(Event event) { String origBody = new String(event.getBody(), charset); Matcher matcher = searchPattern.matcher(origBody); String newBody = matcher.replaceAll(replaceString); event.setBody(newBody.getBytes(charset)); return event; }