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

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

Introduction

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

Prototype

public static final String unescapeEcmaScript(final String input) 

Source Link

Document

Unescapes any EcmaScript literals found in the String .

For example, it will turn a sequence of '\' and 'n' into a newline character, unless the '\' is preceded by another '\' .

Usage

From source file:de.wbuecke.codec.EcmaScriptInput.java

@Override
public String decode(String input) {
    return StringEscapeUtils.unescapeEcmaScript(input);
}

From source file:com.wjxinfo.core.base.utils.security.EncodeUtils.java

/**
 * Javascript decode
 */
public static String unescapeScript(String input) {
    return StringEscapeUtils.unescapeEcmaScript(input);
}

From source file:com.geemvc.taglib.html.MessageTagSupport.java

@Override
public void doTag() throws JspException {
    if (locale != null && (lang != null || country != null))
        throw new JspException(
                "You can only set one of of either 'locale' or a 'language/country' combination.");

    if (lang != null && country != null)
        locale = new Locale(lang, country);

    else if (lang != null)
        locale = new Locale(lang);

    String label = null;//from ww  w.  j  av  a 2 s.  c  o  m

    // Handle string keys normally.
    if (key instanceof String) {
        label = messageResolver.resolve((String) key, locale, requestContext(), true);
    } else if (key.getClass().isEnum()) {
        // Attempt to resolve <enun-fqn>.<enum-value>.
        label = messageResolver.resolve(
                new StringBuilder(key.getClass().getName()).append(Char.DOT).append(key).toString(),
                requestContext(), true);

        // Attempt to resolve <enun-simple-name>.<enum-value>.
        if (label == null)
            label = messageResolver.resolve(
                    new StringBuilder(key.getClass().getSimpleName()).append(Char.DOT).append(key).toString(),
                    requestContext(), true);
    } else if (key instanceof Boolean) {
        // Attempt to resolve Boolean.true or Boolean.false.
        label = messageResolver.resolve(new StringBuilder(Boolean.class.getSimpleName()).append(Char.DOT)
                .append(String.valueOf(key).toLowerCase()).toString(), requestContext(), true);
    } else {
        throw new JspException("The type '" + key.getClass().getName()
                + "' cannot be used as a message key in MessageTagSupport. Only the types String, Boolean or enums are supported.");
    }

    if (label != null) {
        if (escapeHTML)
            label = StringEscapeUtils.escapeHtml4(label);

        if (escapeJavascript)
            label = StringEscapeUtils.escapeEcmaScript(label);

        if (escapeJson)
            label = StringEscapeUtils.escapeJson(label);

        if (unescapeHTML)
            label = StringEscapeUtils.unescapeHtml4(label);

        if (unescapeJavascript)
            label = StringEscapeUtils.unescapeEcmaScript(label);

        if (unescapeJson)
            label = StringEscapeUtils.unescapeJson(label);
    }

    if (label == null) {
        label = getBodyContent();

        if (label == null)
            label = String.format("???%s???", key);
    }

    // Deal with parameters.
    if (label != null) {
        List<Object> params = messageParameters();

        if (params != null && !params.isEmpty())
            label = MessageFormat.format(label, params.toArray());
    }

    if (!Str.isEmpty(var)) {
        jspContext.setAttribute(var, label, scope());
    } else {
        try {
            jspContext.getOut().write(label);
        } catch (IOException e) {
            throw new JspException(e);
        }
    }
}

From source file:com.mirth.connect.client.ui.util.VariableListUtil.java

private static String getMapKey(Matcher matcher) {
    /*/* w w w . j  a va 2  s.co m*/
     * Since multiple capturing groups are used and the final key could
     * reside on either side of the alternation, we use two specific group
     * indices (2 and 5), one for the full "xxxxxMap" case and one for
     * the short "$x" case. We also replace JavaScript-specific escape
     * sequences like \', \", etc.
     */
    String key = matcher.group(FULL_NAME_MATCHER_INDEX);
    if (key == null) {
        key = matcher.group(SHORT_NAME_MATCHER_INDEX);
    }
    return StringEscapeUtils.unescapeEcmaScript(key);
}

From source file:edu.psu.swe.scim.spec.protocol.filter.ExpressionBuildingListener.java

private static Object parseJsonType(String jsonValue) {
    if (jsonValue.startsWith("\"")) {
        String doubleEscaped = jsonValue.substring(1, jsonValue.length() - 1)
                // StringEscapeUtils follows the outdated JSON spec requiring "/" to be escaped, this could subtly break things
                .replaceAll("\\\\/", "\\\\\\\\/")
                // Just in case someone needs a single-quote with a backslash in front of it, this will be unnecessary with escapeJson()
                .replaceAll("\\\\'", "\\\\\\\\'");

        // TODO change this to escapeJson() when dependencies get upgraded
        return StringEscapeUtils.unescapeEcmaScript(doubleEscaped);
    } else if ("null".equals(jsonValue)) {
        return null;
    } else if ("true".equals(jsonValue)) {
        return true;
    } else if ("false".equals(jsonValue)) {
        return false;
    } else {/*from   w  w w.j  av a  2 s .co m*/
        try {
            return Double.parseDouble(jsonValue);
        } catch (NumberFormatException e) {
            LOG.warn("Unable to parse a json number: " + jsonValue);
        }
    }

    throw new IllegalStateException("Unable to parse JSON Value");
}

From source file:com.netsteadfast.greenstep.action.SystemTwitterSaveOrUpdateAction.java

private void update() throws ControllerException, AuthorityException, ServiceException, Exception {
    this.checkFields();
    SysTwitterVO oldSysTwitter = new SysTwitterVO();
    oldSysTwitter.setOid(this.getFields().get("oid"));
    DefaultResult<SysTwitterVO> oldResult = this.sysTwitterService.findObjectByOid(oldSysTwitter);
    if (oldResult.getValue() == null) {
        throw new ServiceException(oldResult.getSystemMessage().getValue());
    }/* w  ww  . java  2 s . c o  m*/
    oldSysTwitter = oldResult.getValue();
    SysTwitterVO sysTwitter = new SysTwitterVO();
    sysTwitter.setOid(oldSysTwitter.getOid());
    sysTwitter.setSystem(oldSysTwitter.getSystem());
    sysTwitter.setTitle(this.getFields().get("title"));
    sysTwitter.setEnableFlag(("true".equals(this.getFields().get("enableFlag")) ? YesNo.YES : YesNo.NO));
    sysTwitter.setContent(null); // ?blob
    this.sysTwitterService.updateObject(sysTwitter); // ?blob      
    String content = StringEscapeUtils.unescapeEcmaScript(this.getFields().get("content"));
    sysTwitter.setContent(content.getBytes());
    DefaultResult<SysTwitterVO> result = this.sysTwitterService.updateObject(sysTwitter);
    this.message = result.getSystemMessage().getValue();
    if (result.getValue() != null) {
        this.success = IS_YES;
    }
}

From source file:io.github.seleniumquery.utils.SelectorUtils.java

/**
 * Escapes the attributes values into a valid CSS string.
 * Deals with the way the CSS parser gives the attributes' values to us.
  */*w w w. j  a  v  a2 s . c  om*/
  * @param stringValue The string value to escape into a valid CSS string
  * @return The string value escaped to into a valid CSS string
 */
public static String unescapeString(String stringValue) {
    String escapedString = stringValue;
    char firstChar = stringValue.charAt(0);
    if (firstChar == '\'' || firstChar == '"') {
        escapedString = StringEscapeUtils.unescapeEcmaScript(stringValue);
        escapedString = escapedString.substring(1, escapedString.length() - 1);
    }
    return escapedString;
}

From source file:com.mirth.connect.client.ui.panels.connectors.SourceSettingsPanel.java

private String getMapKey(Matcher matcher) {
    /*//  w w  w  . j a va2  s . c o  m
     * Since multiple capturing groups are used and the final key could reside on either side of
     * the alternation, we use two specific group indices (2 and 5), one for the full
     * "responseMap" case and one for the short "$r" case. We also replace JavaScript-specific
     * escape sequences like \', \", etc.
     */
    String key = matcher.group(FULL_NAME_MATCHER_INDEX);
    if (key == null) {
        key = matcher.group(SHORT_NAME_MATCHER_INDEX);
    }
    return StringEscapeUtils.unescapeEcmaScript(key);
}

From source file:org.protocoder.network.ProtocoderHttpServer.java

private Response sendWebAppFile(String uri, String method, Properties header, Properties parms,
        Properties files) {//w w  w .  j  a  v  a  2 s  .  c  o  m
    Response res = null;

    MLog.d(TAG, "" + method + " '" + uri + " " + /* header + */" " + parms);

    String escapedCode = parms.getProperty("code");
    String unescapedCode = StringEscapeUtils.unescapeEcmaScript(escapedCode);
    MLog.d("HTTP Code", "" + escapedCode);
    MLog.d("HTTP Code", "" + unescapedCode);

    // Clean up uri
    uri = uri.trim().replace(File.separatorChar, '/');
    if (uri.indexOf('?') >= 0) {
        uri = uri.substring(0, uri.indexOf('?'));
    }

    // We never want to request just the '/'
    if (uri.length() == 1) {
        uri = "index.html";
    }

    // We're using assets, so we can't have a leading '/'
    if (uri.charAt(0) == '/') {
        uri = uri.substring(1, uri.length());
    }

    // have the object build the directory structure, if needed.
    AssetManager am = ctx.get().getAssets();
    try {
        MLog.d(TAG, WEBAPP_DIR + uri);
        InputStream fi = am.open(WEBAPP_DIR + uri);

        // Get MIME type from file name extension, if possible
        String mime = null;
        int dot = uri.lastIndexOf('.');
        if (dot >= 0) {
            mime = MIME_TYPES.get(uri.substring(dot + 1).toLowerCase());
        }
        if (mime == null) {
            mime = NanoHTTPD.MIME_DEFAULT_BINARY;
        }

        res = new Response(HTTP_OK, mime, fi);
    } catch (IOException e) {
        e.printStackTrace();
        MLog.d(TAG, e.getStackTrace().toString());
        res = new Response(HTTP_INTERNALERROR, "text/html", "ERROR: " + e.getMessage());
    }

    return res;

}

From source file:sh.scrap.scrapper.core.DataScrapperBuilderFactory.java

private Object parseArgument(String text) {
    if (text.startsWith("'") || text.startsWith("\"")) {
        boolean startsWithSingleQuote = text.startsWith("'");
        text = text.substring(1, text.length() - 1);
        text = StringEscapeUtils.unescapeEcmaScript(text);
        if (startsWithSingleQuote && text.length() == 1)
            return text.charAt(0);
        else/*from   w w w . j a va 2  s.co m*/
            return text;

    } else
        switch (text) {
        case "null":
            return null;
        case "true":
        case "false":
            return Boolean.valueOf(text);
        default:
            try {
                return Integer.parseInt(text);
            } catch (NumberFormatException e) {
                return Double.parseDouble(text);
            }
        }
}