Example usage for java.util.regex Matcher quoteReplacement

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

Introduction

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

Prototype

public static String quoteReplacement(String s) 

Source Link

Document

Returns a literal replacement String for the specified String .

Usage

From source file:com.ibm.watson.catalyst.jumpqa.replacer.VarReplacer.java

@Override
public String replace(String input, String... args) {
    return _pattern.matcher(input).replaceAll(Matcher.quoteReplacement(args[0]));
}

From source file:org.aludratest.impl.log4testing.output.util.OutputUtil.java

/**
 * Determines the proper target directory path for the provided test situation.
 * @param testName/*from   w w  w.j  a  v a2  s .  c o m*/
 * @param ignoreableRoot
 * @param abbreviating
 * @param baseDir
 * @return the path of the related target directory
 */
public static String targetDirPath(String testName, String ignoreableRoot, boolean abbreviating, File baseDir) {
    String result = OutputUtil.displayName(testName, ignoreableRoot, abbreviating);
    String packagePath = result.replaceAll("\\.", Matcher.quoteReplacement(File.separator));
    return FilenameUtils.concat(baseDir.getAbsolutePath(), packagePath);
}

From source file:com.trackplus.track.util.html.Html2LaTeX.java

/**
 * Get LaTeX text translated from HTML.//  www  . ja v a 2s  .  co  m
 *
 * @param bodyHtml
 * @return the LaTeX representation of the bodyHtml
 */
public static String getLaTeX(String bodyHtml) {

    // Make sure verbatim is properly transformed, protect spaces and line
    // breaks
    Pattern patt = Pattern.compile("(?s)(.?)<div\\s*class=\\\"code\\-text\\\".+?>(.+?)</div>");
    Matcher m = patt.matcher(bodyHtml);
    StringBuffer sb = new StringBuffer();
    while (m.find()) {
        String verbatim = m.group(2);
        verbatim = verbatim.replace("\n", "<br>").replace(" ", "&nbsp;");
        String text = m.group(1) + "<div class=\"code-text\">" + verbatim + "</div>"; // +
        // m.group(3);
        m.appendReplacement(sb, Matcher.quoteReplacement(text));
    }
    m.appendTail(sb);
    bodyHtml = sb.toString();

    // System.err.println(bodyHtml);

    Document doc = Jsoup.parse(bodyHtml);

    String latex = getLatexText(doc);
    sb = new StringBuffer();
    String[] lines = latex.split("\n");
    for (int i = 0; i < lines.length; ++i) {
        if ("\\\\".equals(lines[i].trim())) {
            lines[i] = "";
        }
        sb.append(lines[i] + "\n");
    }

    return sb.toString();
}

From source file:com.hp.autonomy.aci.content.ranges.Range.java

@Override
public String toString() {
    if (ArrayUtils.isNotEmpty(ranges)) {
        final StringBuilder stringBuilder = new StringBuilder("FIXED{");
        if (noMin) {
            stringBuilder.append(".,");
        }/* www.  j  a  va2  s  .  c  om*/
        for (final double range : ranges) {
            stringBuilder.append(range).append(',');
        }
        stringBuilder.deleteCharAt(stringBuilder.length() - 1);
        if (noMax) {
            stringBuilder.append(",.");
        }
        stringBuilder.append("}:")
                .append(FIELD_SEPARATOR.matcher(field).replaceAll(Matcher.quoteReplacement("%3A")));
        return stringBuilder.toString();
    } else {
        return "";
    }
}

From source file:com.ibm.watson.catalyst.jumpqa.replacer.VarReplacer.java

/**
 * TODO: Method description/*from www .j a  va2  s .  com*/
 * 
 * @param input the input string
 * @param arg the argument
 * @return the replacement
 */
public String replace(String input, String arg) {
    return _pattern.matcher(input).replaceAll(Matcher.quoteReplacement(arg));
}

From source file:Main.java

/**
 * Identify variables in the given string and replace with their values as
 * defined in the variableDefs map.  Variables without definitions are left
 * alone./*from  w  w  w . j ava 2  s  .c o  m*/
 *
 * @param string String to do variable replacement in.
 * @param variableDefs Map from variable names to values.
 * @return modified string
 */
public static String replaceVariablesInString(String string, Map<String, String> variableDefs) {

    StringBuffer replacementStringBuffer = new StringBuffer();

    Matcher variableMatcher = variablePattern.matcher(string);
    while (variableMatcher.find()) {
        String varString = variableMatcher.group(1).trim();
        int eqIdx = varString.indexOf("=");

        String varName;
        if (eqIdx > -1)
            varName = varString.substring(0, eqIdx).trim();
        else
            varName = varString;

        String replacementString = variableDefs.containsKey(varName) ? variableDefs.get(varName)
                : variableMatcher.group(0);

        variableMatcher.appendReplacement(replacementStringBuffer, Matcher.quoteReplacement(replacementString));
    }
    variableMatcher.appendTail(replacementStringBuffer);

    return replacementStringBuffer.toString();
}

From source file:org.wso2.carbon.integration.test.client.FilePublisherClient.java

/**
 * File path will be created for the file to be read with respect to the artifact folder and file name
 *
 * @param testCaseFolderName Artifact folder name
 * @param dataFileName       Text file to be read
 *//* w  w  w .ja  v  a2s. co  m*/
public static String getTestDataFileLocation(String testCaseFolderName, String dataFileName) {
    String relativeFilePath = FrameworkPathUtil.getSystemResourceLocation() + File.separator + "artifacts"
            + File.separator + "CEP" + File.separator + testCaseFolderName + File.separator + dataFileName;
    relativeFilePath = relativeFilePath.replaceAll("[\\\\/]", Matcher.quoteReplacement(File.separator));
    return relativeFilePath;
}

From source file:com.kwoksys.framework.util.StringUtils.java

/**
 * Matcher class can reference a group with a leading dollar sign. Not encoding the dollar sign could cause
 * illegal group reference exception./*from w w  w.j  a  v a2s  .c  om*/
 * @return
 */
public static String encodeMatcherReplacement(String input) {
    return Matcher.quoteReplacement(input);
}

From source file:com.arrow.acn.client.api.NodeApi.java

/**
 * Sends GET request to obtain parameters of node specified by its
 * {@code hid}/*from  www.j  a v a  2  s.co  m*/
 *
 * @param hid
 *            {@link String} representing specific node
 *
 * @return {@link NodeModel} containing node parameters
 *
 * @throws AcnClientException
 *             if request failed
 */
public NodeModel findByHid(String hid) {
    String method = "findByHid";
    try {
        URI uri = buildUri(PATTERN.matcher(FIND_BY_HID_URL).replaceAll(Matcher.quoteReplacement(hid)));
        NodeModel result = execute(new HttpGet(uri), NodeModel.class);
        log(method, result);
        return result;
    } catch (Throwable e) {
        logError(method, e);
        throw new AcnClientException(method, e);
    }
}

From source file:ch.oakmountain.tpa.web.TpaWebPersistor.java

public static void createMatrix(String name, String outputDir, IMatrix matrix, String htmlData)
        throws Exception {
    LOGGER.info("Creating matrix " + name + "....");

    String content = IOUtils.toString(TpaWebPersistor.class.getResourceAsStream("/matrix.html"));
    content = content.replaceAll(Pattern.quote("$JSONNAME$"), Matcher.quoteReplacement(name))
            .replaceAll(Pattern.quote("$HTML$"), Matcher.quoteReplacement(htmlData));

    FileUtils.writeStringToFile(Paths.get(outputDir + File.separator + name + ".html").toFile(), content);
    File file = new File(outputDir + File.separator + name + ".json");
    writeMatrix(file, matrix);/* ww  w .j  ava2s.  c  om*/
    TpaPersistorUtils.copyFromResourceToDir("d3.v2.min.js", outputDir);
    TpaPersistorUtils.copyFromResourceToDir("miserables.css", outputDir);

    LOGGER.info("... created matrix " + name + ".");
}