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

The following examples show how to use org.apache.commons.lang3.StringEscapeUtils#escapeJava() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TextEditActivity.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String toString() {
  String newText = StringEscapeUtils.escapeJava(StringUtils.abbreviate(this.newText, 150));
  String oldText = StringEscapeUtils.escapeJava(StringUtils.abbreviate(replacedText, 150));
  return "TextEditActivity(start: "
      + startPosition
      + ", new text line delta: "
      + newTextLineDelta
      + ", new text offset delta: "
      + newTextOffsetDelta
      + ", new: '"
      + newText
      + "', replaced text line delta: "
      + replacedTextLineDelta
      + ", replaced text offset delta: "
      + replacedTextOffsetDelta
      + ", old: '"
      + oldText
      + "', file: "
      + getResource()
      + ", src: "
      + getSource()
      + ")";
}
 
Example 2
Source File: TaggingServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Gets the node reference for a given tag.
 * <p>
 * Returns null if tag is not present and not created.
 * 
 * @param storeRef      store reference
 * @param tag           tag
 * @param create        create a node if one doesn't exist?
 * @return NodeRef      tag node reference or null not exist
 */
private NodeRef getTagNodeRef(StoreRef storeRef, String tag, boolean create)
{
    for (String forbiddenSequence : FORBIDDEN_TAGS_SEQUENCES)
    {
        if (create && tag.contains(forbiddenSequence))
        {
            throw new IllegalArgumentException("Tag name must not contain " + StringEscapeUtils.escapeJava(forbiddenSequence) + " char sequence");
        }
    }
    
    NodeRef tagNodeRef = null;
    Collection<ChildAssociationRef> results = this.categoryService.getRootCategories(storeRef, ContentModel.ASPECT_TAGGABLE, tag, create);
    if (!results.isEmpty())
    {
        tagNodeRef = results.iterator().next().getChildRef();
    }
    return tagNodeRef;
}
 
Example 3
Source File: InsertOperation.java    From saros with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String toString() {
  return "Insert(start line: "
      + startLine
      + ", offset: "
      + startInLineOffset
      + ", line delta: "
      + lineDelta
      + ", offset delta: "
      + offsetDelta
      + ", text: '"
      + StringEscapeUtils.escapeJava(StringUtils.abbreviate(text, 150))
      + "', origin start line: "
      + originStartLine
      + ", offset: "
      + originStartInLineOffset
      + ")";
}
 
Example 4
Source File: MapFormat.java    From template-compiler with Apache License 2.0 5 votes vote down vote up
public String apply(Map<String, Object> params) {
  List<Object> values = new ArrayList<>(params.size());
  for (String key : keys) {
    Object obj = params.get(key);
    if (obj == null) {
      obj = nullPlaceholder;
    }
    values.add(obj);
  }
  return StringEscapeUtils.escapeJava(String.format(format, values.toArray()));
}
 
Example 5
Source File: InstructionPrinter.java    From bytecode-viewer with GNU General Public License v3.0 5 votes vote down vote up
protected String printLdcInsnNode(LdcInsnNode ldc, ListIterator<?> it) {
    if (ldc.cst instanceof String)
        return nameOpcode(ldc.getOpcode()) + " \""
                + StringEscapeUtils.escapeJava(ldc.cst.toString()) + "\" ("
                + ldc.cst.getClass().getCanonicalName() + ")";

    return nameOpcode(ldc.getOpcode()) + " "
            + StringEscapeUtils.escapeJava(ldc.cst.toString()) + " ("
            + ldc.cst.getClass().getCanonicalName() + ")";
}
 
Example 6
Source File: CucumberITGeneratorByScenario.java    From cucumber-jvm-parallel-plugin with Apache License 2.0 5 votes vote down vote up
public Object referenceInsert(final String reference, final Object value) {
    if (value == null) {
        return null;
    } else {
        return StringEscapeUtils.escapeJava(value.toString());
    }
}
 
Example 7
Source File: CucumberITGeneratorByFeature.java    From cucumber-jvm-parallel-plugin with Apache License 2.0 5 votes vote down vote up
public Object referenceInsert(final String reference, final Object value) {
    if (value == null) {
        return null;
    } else {
        return StringEscapeUtils.escapeJava(value.toString());
    }
}
 
Example 8
Source File: HTTPSamlAuthenticator.java    From deprecated-security-advanced-modules with Apache License 2.0 5 votes vote down vote up
private String getWwwAuthenticateHeader(Saml2Settings saml2Settings) throws Exception {
    AuthnRequest authnRequest = this.buildAuthnRequest(saml2Settings);

    return "X-Security-IdP realm=\"Open Distro Security\" location=\""
            + StringEscapeUtils.escapeJava(getSamlRequestRedirectBindingLocation(IdpEndpointType.SSO, saml2Settings,
                    authnRequest.getEncodedAuthnRequest(true)))
            + "\" requestId=\"" + StringEscapeUtils.escapeJava(authnRequest.getId()) + "\"";
}
 
Example 9
Source File: LocalFileSystemOperations.java    From ats-framework with Apache License 2.0 5 votes vote down vote up
private void extractTar( String tarFilePath, String outputDirPath ) {

        TarArchiveEntry entry = null;
        try (TarArchiveInputStream tis = new TarArchiveInputStream(new FileInputStream(tarFilePath))) {
            while ((entry = (TarArchiveEntry) tis.getNextEntry()) != null) {
                if (log.isDebugEnabled()) {
                    log.debug("Extracting " + entry.getName());
                }
                File entryDestination = new File(outputDirPath, entry.getName());
                if (entry.isDirectory()) {
                    entryDestination.mkdirs();
                } else {
                    entryDestination.getParentFile().mkdirs();
                    OutputStream out = new BufferedOutputStream(new FileOutputStream(entryDestination));
                    IoUtils.copyStream(tis, out, false, true);
                }
                if (OperatingSystemType.getCurrentOsType() != OperatingSystemType.WINDOWS) {//check if the OS is UNIX
                    // set file/dir permissions, after it is created
                    Files.setPosixFilePermissions(entryDestination.getCanonicalFile().toPath(),
                                                  getPosixFilePermission(entry.getMode()));
                }
            }
        } catch (Exception e) {
            String errorMsg = null;
            if (entry != null) {
                errorMsg = "Unable to untar " + StringEscapeUtils.escapeJava(entry.getName()) + " from " + tarFilePath
                           + ".Target directory '" + outputDirPath + "' is in inconsistent state.";
            } else {
                errorMsg = "Could not read data from " + tarFilePath;
            }
            throw new FileSystemOperationException(errorMsg, e);
        }

    }
 
Example 10
Source File: SparkCsvGenerator.java    From Quicksql with MIT License 5 votes vote down vote up
@Override
protected void executeQuery() {

    String invoked = "spark.read()\n"
        + "            .option(\"header\", \"true\")\n"
        + "            .option(\"inferSchema\", \"true\")\n"
        + "            .option(\"timestampFormat\", \"yyyy/MM/dd HH:mm:ss ZZ\")\n"
        + "            .option(\"delimiter\", \",\")\n"
        + "            .csv(\"" + StringEscapeUtils.escapeJava(properties.getProperty("directory")) + "\")\n"
        + "            .toDF()\n"
        + "            .createOrReplaceTempView(\"" + properties.getProperty("tableName") + "\");\n"
        + "        \n"
        + "      tmp = spark.sql(\"" + query.replaceAll("\\.", "_") + "\");";
    composer.handleComposition(ClassBodyComposer.CodeCategory.SENTENCE, invoked);
}
 
Example 11
Source File: DesignerUtil.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static String attrToXpathString(Attribute attr) {
    String stringValue = attr.getStringValue();
    Object v = attr.getValue();
    if (v instanceof String || v instanceof Enum) {
        stringValue = "\"" + StringEscapeUtils.escapeJava(stringValue) + "\"";
    } else if (v instanceof Boolean) {
        stringValue = v + "()";
    }
    return String.valueOf(stringValue);
}
 
Example 12
Source File: InstructionPrinter.java    From java-disassembler with GNU General Public License v3.0 4 votes vote down vote up
protected String printLdcInsnNode(LdcInsnNode ldc, ListIterator<?> it) {
    if (ldc.cst instanceof String)
        return nameOpcode(ldc.getOpcode()) + " \"" + StringEscapeUtils.escapeJava(ldc.cst.toString()) + "\" (" + ldc.cst.getClass().getCanonicalName() + ")";

    return nameOpcode(ldc.getOpcode()) + " " + StringEscapeUtils.escapeJava(ldc.cst.toString()) + " (" + ldc.cst.getClass().getCanonicalName() + ")";
}
 
Example 13
Source File: GprString.java    From BigDataScript with Apache License 2.0 4 votes vote down vote up
public static String escape(String str) {
	return StringEscapeUtils.escapeJava(str);
}
 
Example 14
Source File: SQLMan.java    From tuffylite with Apache License 2.0 4 votes vote down vote up
public static String quoteSqlString(String s){
	return "\"" + StringEscapeUtils.escapeJava(s) + "\"";
}
 
Example 15
Source File: StringMan.java    From tuffylite with Apache License 2.0 4 votes vote down vote up
public static String escapeJavaString(String s){
	return StringEscapeUtils.escapeJava(s);
}
 
Example 16
Source File: StringUtil.java    From gocd with Apache License 2.0 4 votes vote down vote up
public static String quoteJavascriptString(String s) {
    return "\"" + StringEscapeUtils.escapeJava(s) + "\"";
}
 
Example 17
Source File: EscapeTool.java    From velocity-tools with Apache License 2.0 3 votes vote down vote up
/**
 * <p>Escapes the characters in a <code>String</code> using Java String rules.</p>
 * <p>Delegates the process to {@link StringEscapeUtils#escapeJava(String)}.</p>
 *
 * @param string the string to escape values, may be null
 * @return String with escaped values, <code>null</code> if null string input
 *
 * @see StringEscapeUtils#escapeJava(String)
 */
public String java(Object string)
{
    if (string == null)
    {
        return null;
    }
    return StringEscapeUtils.escapeJava(String.valueOf(string));
}
 
Example 18
Source File: DremioStringUtils.java    From dremio-oss with Apache License 2.0 2 votes vote down vote up
/**
 * 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 19
Source File: FulltextSearch.java    From vind with Apache License 2.0 2 votes vote down vote up
/**
 * Gets the text of the search query.
 * @return String containing the query target.
 */
public String getEscapedSearchString() {
    return StringEscapeUtils.escapeJava(searchString);
}
 
Example 20
Source File: DrillStringUtils.java    From Bats with Apache License 2.0 2 votes vote down vote up
/**
 * 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);
}