Java Code Examples for org.apache.commons.lang3.StringEscapeUtils.escapeJava()

The following are Jave code examples for showing how to use escapeJava() of the org.apache.commons.lang3.StringEscapeUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: state-channels   File: CallUtil.java   View Source Code Vote up 6 votes
private static String json(Type<?> p) {
    if (p == null) return "null";
    if (p instanceof NumericType || p instanceof Bool) {
        return p.getValue().toString();
    } 
    if (p instanceof Array) {
        return "[" + json(((Array<?>) p).getValue()) + "]";
    }
    Object value = p.getValue();
    String str;
    if (value instanceof byte[]) {
        str = Numeric.toHexStringNoPrefix((byte[]) value);
    } else {
        str = value.toString();
    }
    return "\"" + StringEscapeUtils.escapeJava(str) + "\"";
}
 
Example 2
Project: WebPLP   File: CodeEditor.java   View Source Code Vote up 6 votes
public void setText(String text)
{
	// TODO: update StringEscapeUtils and use escapeJavaScript() instead
	text = StringEscapeUtils.escapeJava(text);
	codeBodyProperty.set(text);
	System.out.println("Setting value");
	webView.getEngine().executeScript(
			"window.onload = function() {"
			+ "editor.on(\"change\", function(){});"
			+ "editor.setValue(\"" + text + "\","
					+ text.length() + ");"
			+ "editor.on(\"change\", function() {"
			+ "javaContentModel.updateTextFromJavascript(editor.getValue());"
			+ "});"
			+ "javaContentModel.println(\"Value Set\");"
			+ "};"
			);
}
 
Example 3
Project: SWET   File: WriteScriptFile.java   View Source Code Vote up 5 votes
private String buildActionStep(TestStepDTO testStepDTO) {
	String actionString = "";
	actionString = "\t\tseleniumKeywords."
			+ ActionsMapping.getAction(testStepDTO.getAction().toLowerCase());
	actionString += "(\"" + testStepDTO.getLocateElement().getBy() + "\"";
	String locatorValue = testStepDTO.getLocateElement().getValue();
	actionString += ", \"" + StringEscapeUtils.escapeJava(locatorValue) + "\"";

	if (testStepDTO.getThirdPara() != null) {
		actionString += ", \"" + testStepDTO.getThirdPara() + "\");";
	} else {
		actionString += ");";
	}
	return actionString;
}
 
Example 4
Project: stvs   File: SpecificationTable.java   View Source Code Vote up 5 votes
protected void onRowAdded(List<? extends SpecificationRow<C>> added) {
  for (SpecificationRow<C> addedRow : added) {
    // Check correctness of added row
    if (addedRow.getCells().size() != columnHeaders.size()) {
      throw new IllegalArgumentException(
          "Illegal width for row " + StringEscapeUtils.escapeJava(addedRow.toString())
              + ", expected width: " + columnHeaders.size());
    }
    if (!addedRow.getCells().keySet().stream()
        .allMatch(columnId -> getOptionalColumnHeaderByName(columnId).isPresent())) {
      throw new IllegalArgumentException("Added row contains unknown IoVariable: "
          + StringEscapeUtils.escapeJava(addedRow.toString()));
    }
  }
}
 
Example 5
Project: stvs   File: InvalidFreeVariableProblem.java   View Source Code Vote up 5 votes
private static String tryToGetValidName(FreeVariable freeVariable)
        throws InvalidFreeVariableProblem {
    String varName = freeVariable.getName();
    if (VariableExpr.IDENTIFIER_PATTERN.matcher(varName).matches()) {
        return varName;
    }
    else {
        throw new InvalidFreeVariableProblem(
                "Variable has illegal characters in name: "
                        + StringEscapeUtils.escapeJava(varName));
    }
}
 
Example 6
Project: stvs   File: InvalidFreeVariableProblem.java   View Source Code Vote up 5 votes
private static Type tryToGetValidType(FreeVariable freeVariable,
        Map<String, Type> typesByName) throws InvalidFreeVariableProblem {
    Type foundType = typesByName.get(freeVariable.getType());
    if (foundType == null) {
        throw new InvalidFreeVariableProblem(
                "Variable has unknown type: " + StringEscapeUtils
                        .escapeJava(freeVariable.getType()));
    }
    return foundType;
}
 
Example 7
Project: vind   File: FulltextSearch.java   View Source Code Vote up 2 votes
/**
 * Gets the text of the search query.
 * @return String containing the query target.
 */
public String getEscapedSearchString() {
    return StringEscapeUtils.escapeJava(searchString);
}
 
Example 8
Project: QDrill   File: DrillStringUtils.java   View Source Code Vote up 2 votes
/**
 * Escapes the characters in a {@code String} using Java String rules.
 *
 * Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)
 *
 * So a tab becomes the characters {@code '\\'} and
 * {@code 't'}.
 *
 * Example:
 * <pre>
 * input string: He didn't say, "Stop!"
 * output string: He didn't say, \"Stop!\"
 * </pre>
 *
 * @param input  String to escape values in, may be null
 * @return String with escaped values, {@code null} if null string input
 */
public static final String escapeJava(String input) {
  return StringEscapeUtils.escapeJava(input);
}
 
Example 9
Project: dremio-oss   File: DremioStringUtils.java   View Source Code Vote up 2 votes
/**
 * Escapes the characters in a {@code String} according to Java string literal
 * rules.
 *
 * Deals correctly with quotes and control-chars (tab, backslash, cr, ff,
 * etc.) so, for example, a tab becomes the characters {@code '\\'} and
 * {@code 't'}.
 *
 * Example:
 * <pre>
 * input string: He didn't say, "Stop!"
 * output string: He didn't say, \"Stop!\"
 * </pre>
 *
 * @param input  String to escape values in, may be null
 * @return String with escaped values, {@code null} if null string input
 */
public static final String escapeJava(String input) {
  return StringEscapeUtils.escapeJava(input);
}
 
Example 10
Project: stvs   File: CellOperationProvider.java   View Source Code Vote up 2 votes
/**
 * <p>
 * Prints a minimal string including the string representation and optionally adds the comment, if
 * not null.
 * </p>
 *
 * <p>
 * (should only used for debugging purposes, i.e. in toString methods)
 * </p>
 *
 * @return a minimal string
 */
default String debuggingString() {
  return getAsString() + (getComment() == null ? ""
      : " (comment: \"" + StringEscapeUtils.escapeJava(getComment()) + "\")");
}
 
Example 11
Project: stvs   File: DuplicateFreeVariableProblem.java   View Source Code Vote up 2 votes
/**
 * Private constructor: DuplicateFreeVariableProblems can only be created from the static
 * method {@link DuplicateFreeVariableProblem#checkForDuplicates}.
 * @param freeVariableName the name of the duplicate variable
 */
private DuplicateFreeVariableProblem(String freeVariableName) {
  super(
      "More than one free variable with name " + StringEscapeUtils.escapeJava(freeVariableName));
}