Example usage for org.apache.commons.text StringEscapeUtils unescapeJava

List of usage examples for org.apache.commons.text StringEscapeUtils unescapeJava

Introduction

In this page you can find the example usage for org.apache.commons.text StringEscapeUtils unescapeJava.

Prototype

public static final String unescapeJava(final String input) 

Source Link

Document

Unescapes any Java literals found in the String .

Usage

From source file:de.learnlib.alex.data.entities.actions.web.PressKeyAction.java

@Override
protected ExecuteResult execute(WebSiteConnector connector) {
    final String unescapedKey = StringEscapeUtils.unescapeJava(this.key);
    final Keys keyToPress = Keys.getKeyFromUnicode(unescapedKey.toCharArray()[0]);

    final WebElementLocator nodeWithVariables = new WebElementLocator(insertVariableValues(node.getSelector()),
            node.getType());//from w ww . j av a2  s  .  c  om

    try {
        final WebElement element = connector.getElement(nodeWithVariables);
        element.sendKeys(keyToPress);
        LOGGER.info(LoggerMarkers.LEARNER, "Pressed the key '{}' on the element '{}'.", keyToPress.toString(),
                nodeWithVariables);
        return getSuccessOutput();
    } catch (Exception e) {
        LOGGER.info(LoggerMarkers.LEARNER, "Could not press key '{}' on element '{}'.", keyToPress.toString(),
                nodeWithVariables, e);
        return getFailedOutput();
    }
}

From source file:it.greenvulcano.util.txt.TextUtils.java

/**
 * @param input//from www. j  a v  a 2 s  .  c om
 * @param phPrefix
 * @param phSuffix
 * @param phValues
 * @return the string with placeholders replaced
 * 
 */
public static String replacePlaceholder(String input, String phPrefix, String phSuffix,
        Hashtable<String, String> phValues) {
    if (input == null) {
        return null;
    }
    if (input.equals("")) {
        return "";
    }
    if (phValues == null) {
        return input;
    }
    if (phValues.isEmpty()) {
        return input;
    }
    if ((phPrefix == null) || (phSuffix == null)) {
        return input;
    }
    if ((phPrefix.equals("")) || (phSuffix.equals(""))) {
        return input;
    }

    int phPlen = phPrefix.length();
    int phSlen = phSuffix.length();
    int startNextToken = 0;
    int endNextToken = 0;
    int maxPosition = input.length();

    StringBuilder buf = new StringBuilder("");
    while (startNextToken < maxPosition) {
        endNextToken = input.indexOf(phPrefix, startNextToken);
        if (endNextToken != -1) {
            String currToken = input.substring(startNextToken, endNextToken);
            int endPH = input.indexOf(phSuffix, endNextToken + phPlen);
            String phName = input.substring(endNextToken + phPlen, endPH);
            String replacement = phPrefix + phName + phSuffix;
            Object phValue = phValues.get(phName);
            if (phValue != null) {
                replacement = StringEscapeUtils.unescapeJava(phValue.toString());
            }
            if (currToken.length() > 0) {
                buf.append(currToken).append(replacement);
            } else {
                buf.append(replacement);
            }
            startNextToken = endPH + phSlen;
        } else {
            String currToken = input.substring(startNextToken);
            buf.append(currToken);
            startNextToken = maxPosition;
        }
    }
    return buf.toString();
}

From source file:org.apache.nifi.csv.TestJacksonCSVRecordReader.java

@Test
public void testMultipleRecordsEscapedWithSpecialChar() throws IOException, MalformedRecordException {

    char delimiter = StringEscapeUtils.unescapeJava("\u0001").charAt(0);

    final CSVFormat format = CSVFormat.DEFAULT.withFirstRecordAsHeader().withTrim().withQuote('"')
            .withDelimiter(delimiter);/*  ww w.j  av a 2s . co m*/
    final List<RecordField> fields = getDefaultFields();
    fields.replaceAll(f -> f.getFieldName().equals("balance") ? new RecordField("balance", doubleDataType) : f);

    final RecordSchema schema = new SimpleRecordSchema(fields);

    try (final InputStream fis = new FileInputStream(
            new File("src/test/resources/csv/multi-bank-account_escapedchar.csv"));
            final JacksonCSVRecordReader reader = createReader(fis, schema, format)) {

        final Object[] firstRecord = reader.nextRecord().getValues();
        final Object[] firstExpectedValues = new Object[] { "1", "John Doe", 4750.89D, "123 My Street",
                "My City", "MS", "11111", "USA" };
        Assert.assertArrayEquals(firstExpectedValues, firstRecord);

        final Object[] secondRecord = reader.nextRecord().getValues();
        final Object[] secondExpectedValues = new Object[] { "2", "Jane Doe", 4820.09D, "321 Your Street",
                "Your City", "NY", "33333", "USA" };
        Assert.assertArrayEquals(secondExpectedValues, secondRecord);

        assertNull(reader.nextRecord());
    }
}