Example usage for java.util.regex Matcher appendTail

List of usage examples for java.util.regex Matcher appendTail

Introduction

In this page you can find the example usage for java.util.regex Matcher appendTail.

Prototype

public StringBuilder appendTail(StringBuilder sb) 

Source Link

Document

Implements a terminal append-and-replace step.

Usage

From source file:org.openmrs.module.databasebackup.util.DbDump.java

private static String escape(String s) {
    Matcher matcher = sqlTokenPattern.matcher(s);
    StringBuffer sb = new StringBuffer();
    while (matcher.find()) {
        matcher.appendReplacement(sb, sqlTokens.get(matcher.group(1)));
    }/*  www .j  a  v  a2  s.c o  m*/
    matcher.appendTail(sb);
    return sb.toString();
}

From source file:org.apache.ode.axis2.httpbinding.HttpClientHelper.java

/**
 * This method ensures that a header value containing CRLF does not mess up the HTTP request.
 * Actually CRLF is the end-of-line marker for headers.
 * <p/>/*from w ww  . j a  va  2s. c  o m*/
 * To do so, all CRLF followed by a non-whitespace character are replaced by CRLF HT.
 * <p/>
 * This is possible because the
 * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2">Section 2.2</a> of HTTP standard (RFC2626) states that:
 * <p/>
 * <quote>
 * HTTP/1.1 header field values can be folded onto multiple lines if the
 * continuation line begins with a space or horizontal tab. All linear
 * white space, including folding, has the same semantics as SP. A
 * recipient MAY replace any linear white space with a single SP before
 * interpreting the field value or forwarding the message downstream.
 * <p/>
 * LWS            = [CRLF] 1*( SP | HT )
 * <p/>
 * </quote>
 * <p/>
 * FYI, HttpClient 3.x.x does not check this.
 *
 * @param header
 * @return the string properly ready to be used as an HTTP header field-content
 */
public static String replaceCRLFwithLWS(String header) {
    Matcher m = NON_LWS_PATTERN.matcher(header);
    StringBuffer sb = new StringBuffer(header.length());
    while (m.find()) {
        m.appendReplacement(sb, "\r\n\t");
        sb.append(m.group(1));
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:com.datumbox.common.utilities.PHPfunctions.java

public static String preg_replace(Pattern pattern, String replacement, String subject) {
    Matcher m = pattern.matcher(subject);
    StringBuffer sb = new StringBuffer(subject.length());
    while (m.find()) {
        m.appendReplacement(sb, replacement);
    }/*from w  w  w . j  a  v a  2s.co  m*/
    m.appendTail(sb);
    return sb.toString();
}

From source file:com.hexidec.ekit.component.HTMLTableUtilities.java

private static String adicionaBRnoFimDosTD(String str) {

    Matcher m = pFimDeTDnaoPrecedidoDeBR.matcher(str);
    if (!m.find()) {
        return str;
    }//  ww w  .  j ava2 s.c  om

    StringBuffer sb = new StringBuffer();
    do {
        m.appendReplacement(sb, "<br/>" + Matcher.quoteReplacement(m.group()));
    } while (m.find());

    m.appendTail(sb);

    return sb.toString();
}

From source file:Main.java

private static String makeEmailHerf(String content) {
    if (content.trim().length() == 0) {
        return content;
    }// w w w .  j a  v a2 s . c o  m
    StringBuffer emailStringBuffer = new StringBuffer();

    Matcher matcherEmail = patternEmail.matcher(content);
    while (matcherEmail.find()) {

        String email = matcherEmail.group();
        //            System.out.println("email:" + email);
        String emailToHref = "<a href=\"" + MailTo.MAILTO_SCHEME + email + "\">" + email + "</a>";
        matcherEmail.appendReplacement(emailStringBuffer, emailToHref);

    }
    matcherEmail.appendTail(emailStringBuffer);
    return emailStringBuffer.toString();
}

From source file:org.dllearner.confparser.PostProcessor.java

private static String replaceAllMap(String pre, Map<String, String> repMap, String post, String in) {
    List<String> keys = new ArrayList<>(repMap.keySet());
    Collections.sort(keys, (o1, o2) -> o1.length() - o2.length());
    CollectionUtils.transform(keys, input -> Pattern.quote(input));
    Matcher m = Pattern.compile(pre + "(" + Strings.join(keys, "|") + ")" + post).matcher(in);
    m.reset();//w  w w .j  a  v a 2s  . co  m
    if (m.find()) {
        StringBuffer sb = new StringBuffer();
        do {
            m.appendReplacement(sb, repMap.get(m.group(1)));
        } while (m.find());
        return m.appendTail(sb).toString();
    }
    return in;
}

From source file:org.nuxeo.ecm.rating.operations.MostLiked.java

protected static String replaceURLsByLinks(String message) {
    String escapedMessage = StringEscapeUtils.escapeHtml(message);
    Matcher m = HTTP_URL_PATTERN.matcher(escapedMessage);
    StringBuffer sb = new StringBuffer(escapedMessage.length());
    while (m.find()) {
        String url = m.group(1);//from  ww w.ja  va 2 s . c  o  m
        m.appendReplacement(sb, computeLinkFor(url));
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:com.eu.evaluation.server.dao.AbstractDAO.java

/**
 * jpqlorder By??// w w  w .j ava2s.co m
 *
 * @param jpql
 * @return
 */
private static String removeOrders(String jpql) {
    Pattern p = Pattern.compile("order\\s*by[\\w|\\W|\\s|\\S]*", Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(jpql);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        m.appendReplacement(sb, "");
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:io.wcm.handler.url.impl.Externalizer.java

/**
 * Mangle the namespaces in the given path for usage in sling-based URLs.
 * <p>//from w  w w  . j a v a2s .  c  o  m
 * Example: /path/jcr:content to /path/_jcr_content
 * </p>
 * @param path Path to mangle
 * @return Mangled path
 */
public static String mangleNamespaces(String path) {
    if (!StringUtils.contains(path, NAMESPACE_SEPARATOR)) {
        return path;
    }
    Matcher matcher = NAMESPACE_PATTERN.matcher(path);
    StringBuffer sb = new StringBuffer();
    while (matcher.find()) {
        String replacement = MANGLED_NAMESPACE_PREFIX + matcher.group(1) + MANGLED_NAMESPACE_SUFFIX;
        matcher.appendReplacement(sb, replacement);
    }
    matcher.appendTail(sb);
    return sb.toString();
}

From source file:org.b3log.symphony.util.VideoPlayers.java

/**
 * Renders the specified content with video player if need.
 *
 * @param content the specified content//from  w  w w  .j av a 2s . c  om
 * @return rendered content
 */
public static final String render(final String content) {
    final LatkeBeanManager beanManager = Lifecycle.getBeanManager();
    final LangPropsService langPropsService = beanManager.getReference(LangPropsServiceImpl.class);

    final StringBuffer contentBuilder = new StringBuffer();
    final Matcher m = PATTERN.matcher(content);

    while (m.find()) {
        String videoURL = m.group();
        videoURL = StringUtils.substringBetween(videoURL, "href=\"", "\" rel=");

        m.appendReplacement(contentBuilder, "<video src=\"" + videoURL + "\" controls=\"controls\">"
                + langPropsService.get("notSupportPlayLabel") + "</video>\n");
    }
    m.appendTail(contentBuilder);

    return contentBuilder.toString();
}