Example usage for java.util.regex Matcher appendReplacement

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

Introduction

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

Prototype

public Matcher appendReplacement(StringBuilder sb, String replacement) 

Source Link

Document

Implements a non-terminal append-and-replace step.

Usage

From source file:iox.refused.jhp.JHP_Parser.java

private static void compile(StringBuffer sb, String src) {
    Matcher m = TEXTLET.matcher(src);
    while (m.find()) {
        String name = BSLASHES.matcher(StringEscapeUtils.escapeJava(m.group(2))).replaceAll("\\\\\\\\");
        m.appendReplacement(sb, "echo(\"" + name + "\");\n");
    }/*from   www  .j  a v  a 2 s  . co m*/
    m.appendTail(sb);
}

From source file:org.apache.ode.tools.sendsoap.cline.HttpSoapSender.java

public static String doSend(URL u, InputStream is, String proxyServer, int proxyPort, String username,
        String password, String soapAction) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream(8192);
    StreamUtils.copy(bos, is);//from  w w w  .  jav a2s. c om
    String now = Long.toString(System.currentTimeMillis());
    int c = 1;
    String data = new String(bos.toByteArray());
    Matcher m = SEQ.matcher(data);
    StringBuffer sb = new StringBuffer(8192);
    while (m.find()) {
        m.appendReplacement(sb, now + "-" + c++);
    }
    m.appendTail(sb);
    SimpleHttpConnectionManager mgr = new SimpleHttpConnectionManager();
    try {
        mgr.getParams().setConnectionTimeout(60000);
        mgr.getParams().setSoTimeout(60000);
        HttpClient httpClient = new HttpClient(mgr);
        PostMethod httpPostMethod = new PostMethod(u.toExternalForm());
        if (proxyServer != null && proxyServer.length() > 0) {
            httpClient.getState().setCredentials(new AuthScope(proxyServer, proxyPort),
                    new UsernamePasswordCredentials(username, password));
            httpPostMethod.setDoAuthentication(true);
        }
        if (soapAction == null)
            soapAction = "";
        httpPostMethod.setRequestHeader("SOAPAction", "\"" + soapAction + "\"");
        httpPostMethod.setRequestHeader("Content-Type", "text/xml");
        httpPostMethod.setRequestEntity(new StringRequestEntity(sb.toString()));
        httpClient.executeMethod(httpPostMethod);
        return httpPostMethod.getResponseBodyAsString() + "\n";
    } finally {
        mgr.shutdown();
    }
}

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

/**
 * Renders the specified content with video player if need.
 *
 * @param content the specified content/* w ww .j a  v  a2s.  c o  m*/
 * @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();
}

From source file:com.mmj.app.web.controller.search.SearchController.java

public static String ignoreCaseReplace(String source, String pattern) {
    Pattern p = Pattern.compile(pattern, Pattern.CASE_INSENSITIVE);
    Matcher mc = p.matcher(source);
    StringBuffer sb = new StringBuffer();
    while (mc.find()) {
        mc.appendReplacement(sb, "<em class='highlight'>" + mc.group() + "</em>");
    }/* w  w  w.j av  a 2  s .c om*/
    mc.appendTail(sb);
    return sb.toString();
}

From source file:net.gcolin.simplerepo.maven.Resolver.java

public static String resolve(String value, Properties props, Model model) {
    if (value == null) {
        return null;
    }/*w  ww . ja  v a2s .  com*/
    Matcher matcher = VAR_PATTERN.matcher(value);
    StringBuffer result = new StringBuffer();
    while (matcher.find()) {
        String expr = matcher.group(1);
        if (props.containsKey(expr)) {
            matcher.appendReplacement(result, props.getProperty(expr));
        } else {
            if (expr.startsWith("project.")) {
                expr = expr.substring(8);
            }
            try {
                matcher.appendReplacement(result, String.valueOf(BeanUtils.getProperty(model, expr)));
            } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
                throw new IllegalArgumentException(e);
            }
        }
    }
    matcher.appendTail(result);
    return result.toString();
}

From source file:Main.java

private static String makeUrlHerf(String content) {
    if (content.trim().length() == 0) {
        return content;
    }// ww  w. java 2s  .  co  m
    StringBuffer urlStringBuffer = new StringBuffer();

    Matcher matcherUrl = patternURL.matcher(content);
    while (matcherUrl.find()) {

        String url = matcherUrl.group();
        //            System.out.println("URL:" + url);
        String urlToHref = "<a href=\"" + url + "\">" + url + "</a>";
        matcherUrl.appendReplacement(urlStringBuffer, urlToHref);

    }
    matcherUrl.appendTail(urlStringBuffer);
    return urlStringBuffer.toString();
}

From source file:Main.java

private static String makeTelNoHerf(String telContent) {
    if (telContent.trim().length() == 0) {
        return telContent;
    }//w ww  .j a  v  a  2s.  c o m
    StringBuffer telNoStringBuffer = new StringBuffer();

    Matcher matcherTelNo = patternTelNo.matcher(telContent);
    while (matcherTelNo.find()) {

        String telNo = matcherTelNo.group();
        String telNoToHerf = "<a href=\"" + ProtocolKey_ACTION_DIAL + telNo + "\">" + telNo + "</a>";
        matcherTelNo.appendReplacement(telNoStringBuffer, telNoToHerf);

    }
    matcherTelNo.appendTail(telNoStringBuffer);
    return telNoStringBuffer.toString();
}

From source file:org.nuxeo.ecm.activity.ActivityMessageHelper.java

public 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   w ww . ja  v  a2s  .  co m*/
        m.appendReplacement(sb, computeLinkFor(url));
    }
    m.appendTail(sb);
    return sb.toString();
}

From source file:com.amazon.android.utils.JsonHelper.java

/**
 * This method removes comments from JSON string.
 *
 * @param jsonString JSON string with comments.
 * @return JSON string without comments.
 *///from www.  j  av a2  s.  c  om
public static String escapeComments(String jsonString) {

    if (jsonString == null) {
        return null;
    }

    String regex = COMMENT_START_SEQUENCE_ESCAPED + "(.*?|\n)" + // Match all type of cases including new line.
            COMMENT_STOP_SEQUENCE_ESCAPED;

    StringBuffer stringBuffer = new StringBuffer(jsonString.length());
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(jsonString);
    while (matcher.find()) {
        matcher.appendReplacement(stringBuffer, "");
    }
    matcher.appendTail(stringBuffer);

    return stringBuffer.toString();
}

From source file:com.github.ibole.infrastructure.persistence.db.mybatis.pagination.SqlHelper.java

/**
 * orderby ??/*w w w  .j a  v a  2  s .  c o m*/
 *
 * @param sql sql
 * @return order by sql
 */
public static String removeOrders(String sql) {
    Preconditions.checkNotNull(sql);
    Pattern p = Pattern.compile(ORDER_BY_REGEX, Pattern.CASE_INSENSITIVE);
    Matcher m = p.matcher(sql);
    StringBuffer sb = new StringBuffer(sql.length());
    while (m.find()) {
        m.appendReplacement(sb, "");
    }
    m.appendTail(sb);
    return sb.toString();
}