Example usage for org.apache.commons.lang3 StringEscapeUtils escapeJava

List of usage examples for org.apache.commons.lang3 StringEscapeUtils escapeJava

Introduction

In this page you can find the example usage for org.apache.commons.lang3 StringEscapeUtils escapeJava.

Prototype

public static final String escapeJava(final String input) 

Source Link

Document

Escapes the characters in a String using Java String rules.

Deals correctly with quotes and control-chars (tab, backslash, cr, ff, etc.)

So a tab becomes the characters '\\' and 't' .

The only difference between Java strings and JavaScript strings is that in JavaScript, a single quote and forward-slash (/) are escaped.

Example:

 input string: He didn't say, "Stop!" 

Usage

From source file:com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.java

protected String escape(Object value) {
    return "\"" + StringEscapeUtils.escapeJava(String.valueOf(value)) + "\"";
}

From source file:com.squarespace.less.core.MapFormat.java

/**
 * Applies the {@code params} to producing the formatted message.
 *//*  w ww. j  av a 2s .com*/
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()));
}

From source file:Helper.Helper.java

public static ArrayList<String> getCommandsDump(FakeFile cur, String path) {
    FakeFile[] files = cur.listFiles();//from  w  w w  . j  a  v  a  2s . c  o m
    if (cur.isDirectory()) {
        if (!cur.isHidden() && !path.equals("./")) {
            Helper.cmds.add("mkdir " + path);
            Helper.cmds.add("chmod " + cur.chmod + " " + path);
        }
    }
    for (FakeFile f : files) {
        if (f.isDirectory()) {
            Helper.getCommandsDump(f, path + f.getName() + "/");
        } else {
            try {
                Helper.cmds.add("createfile " + path + f.getName() + " "
                        + StringEscapeUtils.escapeJava(new String(f.data)));
                Helper.cmds.add("chmod " + f.chmod + " " + path + f.getName());
            } catch (Exception e) {
                //we should never reach this point
            }
        }
    }
    return Helper.cmds;
}

From source file:com.smash.revolance.ui.materials.mock.webdriver.MockedWebElement.java

public String getBg() {
    return StringEscapeUtils.escapeJava(bg);
}

From source file:com.denimgroup.threadfix.logging.SanitizedLogger.java

/**
 * Blacklist. Should probably be a whitelist but I'm not
 * sure what else needs to be sanitized.
 * @param startString/* w w  w.j a v  a2  s  . c  om*/
 * @return
 */
private String sanitize(String startString) {
    String retVal;

    if (startString == null) {
        retVal = "<NULL>";
    } else {
        //   This should handle ", \ and various CRLF characters as well as scary Unicode (non-ASCII) stuff
        // https://commons.apache.org/proper/commons-lang/javadocs/api-3.0/src-html/org/apache/commons/lang3/StringEscapeUtils.html
        retVal = StringEscapeUtils.escapeJava(startString);
    }

    return retVal;
}

From source file:de.fraunhofer.sciencedataamanager.beans.DataExportInstanceNew.java

/**
 * Creates a new data export instance//from   ww  w .ja  va  2 s.co  m
 *
 * @throws IOException General execpeiton
 */
public void createNewDataExportInstance() throws IOException {
    try {
        DataExportInstance dataExportInstance = new DataExportInstance();
        dataExportInstance.setName(getDataExportInstanceName());
        dataExportInstance.setGroovyCode(StringEscapeUtils.escapeJava(getDataExportInstanceGroovyCode()));

        dataExportInstance.setExportFilePrefix(getDataExportFilePrefix());
        dataExportInstance.setExportFilePostfix(getDataExportFilePostfix());
        dataExportInstance.setResponseContentType(getResponseContentType());

        DataExportInstanceDataManager dataExportInstanceDataProvider = new DataExportInstanceDataManager(
                applicationConfiguration);
        dataExportInstanceDataProvider.insert(dataExportInstance);
        FacesContext.getCurrentInstance().getExternalContext().redirect("index.xhtml");
    } catch (Exception ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        this.applicationConfiguration.getLoggingManager().logException(ex);

    }
}

From source file:com.blackducksoftware.integration.eclipseplugin.common.services.DependencyInformationServiceTest.java

private String getSystemSpecificFilepath(final String path, final String separator) {
    return path.replaceAll(separator, StringEscapeUtils.escapeJava(File.separator));
}

From source file:com.squarespace.less.model.Comment.java

/**
 * See {@link Node#modelRepr(Buffer)}//from   www  .  j a v a  2s. c  om
 */
@Override
public void modelRepr(Buffer buf) {
    typeRepr(buf);
    posRepr(buf);
    buf.append(' ').append(block ? "block" : "single line");
    buf.append(' ').append(newline ? "newline" : "inline").append('\n');
    buf.incrIndent();
    buf.indent();
    buf.append(StringEscapeUtils.escapeJava(body));
    buf.decrIndent();
}

From source file:de.micromata.genome.gwiki.page.impl.wiki.parser.WikiParserUtils.java

public static void dumpFragmentTree(GWikiFragment frag, StringBuilder sb, String indent) {
    sb.append(indent);//from  www .  j  ava 2s. co m
    sb.append(frag.getClass().getSimpleName());
    if (frag instanceof GWikiMacroFragment) {
        GWikiMacroFragment mf = (GWikiMacroFragment) frag;
        sb.append(": ");
        mf.getAttrs().toHeadContent(sb);
        sb.append("\n");
        if (mf.getAttrs().getChildFragment() != null
                && mf.getAttrs().getChildFragment().getChilds().isEmpty() == false) {
            dumpChildFragments(mf.getAttrs().getChildFragment(), sb, indent + "  ");
        } else if (mf.getMacro().hasBody() && mf.getMacro().evalBody() == false) {
            sb.append(StringEscapeUtils.escapeJava(mf.getAttrs().getBody()));
        }
        return;
    }
    if (frag instanceof GWikiFragmentText) {
        sb.append(": ").append(groovy.json.StringEscapeUtils.escapeJava(((GWikiFragmentText) frag).getHtml()));
    }
    sb.append("\n");
    if (frag instanceof GWikiFragmentChildsBase) {
        dumpChildFragments((GWikiFragmentChildsBase) frag, sb, indent + " ");
    }

}

From source file:edu.isi.karma.kr2rml.writer.N3KR2RMLRDFWriter.java

private String constructTripleWithLiteralObject(String subjUri, String predicateUri, String value,
        String literalType, String language) {
    // Use Apache Commons to escape the value
    value = StringEscapeUtils.escapeJava(value);
    if (subjUri.indexOf("<") != -1 && subjUri.indexOf(">") != -1) {
        String tmp = subjUri.substring(1, subjUri.length() - 1);
        subjUri = "<" + normalizeURI(tmp) + ">";
    }//from  www.  jav  a2  s . c om
    //https://www.w3.org/TeamSubmission/turtle/ - Literals may be given either a language suffix or a datatype URI but not both
    if (language != null && !language.equals("")) {
        return subjUri + " " + uriFormatter.getExpandedAndNormalizedUri(predicateUri) + " \"" + value + "\""
                + "@" + language + " .";
    } else if (literalType != null && !literalType.equals("")) {
        // Add the RDF literal type to the literal if present
        return subjUri + " " + uriFormatter.getExpandedAndNormalizedUri(predicateUri) + " \"" + value + "\""
                + "^^<" + literalType + "> .";
    }
    return subjUri + " " + uriFormatter.getExpandedAndNormalizedUri(predicateUri) + " \"" + value + "\" .";
}