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

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

Introduction

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

Prototype

public static final String escapeEcmaScript(final String input) 

Source Link

Document

Escapes the characters in a String using EcmaScript String rules.

Escapes any values it finds into their EcmaScript String form.

Usage

From source file:org.efaps.ui.wicket.components.gridx.GridXComponent.java

/**
 * Gets the data JS./*  www .  j av a2  s . c  o  m*/
 *
 * @param _uiTable the ui table
 * @return the data JS
 * @throws EFapsException on error
 */
public static CharSequence getDataJS(final UIGrid _uiGrid) throws EFapsException {
    final StringBuilder ret = new StringBuilder().append(" [\n");
    int i = 0;
    for (final List<Cell> row : _uiGrid.getValues()) {
        if (i > 0) {
            ret.append(",\n");
        }
        ret.append("{ id:").append(i);
        for (final Cell cell : row) {

            ret.append(",").append(cell.getFieldConfig().getName()).append(":").append("'")
                    .append(StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(cell.getValue())))
                    .append("'");

            final Comparable<?> orderObject = (Comparable<?>) cell.getSortValue();
            if (orderObject != null) {
                final String orderVal;
                final boolean ps;
                if (orderObject instanceof Number) {
                    orderVal = ((Number) orderObject).toString();
                    ps = false;
                } else {
                    orderVal = String.valueOf(orderObject);
                    ps = true;
                }
                if (cell.getValue() != null && !cell.getValue().equals(orderVal)) {
                    ret.append(",").append(cell.getFieldConfig().getName()).append("_sort:")
                            .append(ps ? "'" : "").append(StringEscapeUtils.escapeEcmaScript(orderVal))
                            .append(ps ? "'" : "");
                }
            }
        }
        ret.append("}");
        i++;
    }
    ret.append("]\n");
    return ret;
}

From source file:org.efaps.ui.wicket.components.picker.PickerCallBack.java

/**
 * The actual Javascript that will be executed on close of the modal window.
 * @param _target Target/* w w w.  j  a va  2  s .  c  o m*/
 */
@Override
public void onClose(final AjaxRequestTarget _target) {
    final AbstractUIPageObject pageObject = (AbstractUIPageObject) this.pageReference.getPage()
            .getDefaultModelObject();
    if (pageObject.isOpenedByPicker()) {
        final UIPicker picker = pageObject.getPicker();
        pageObject.setPicker(null);
        if (picker.isExecuted()) {
            final Map<String, Object> map = picker.getReturnMap();
            final boolean escape = escape(map);
            final StringBuilder js = new StringBuilder();
            final String value = (String) map.get(EFapsKey.PICKER_VALUE.getKey());
            if (value != null) {
                js.append("require(['dojo/dom'], function(dom){\n").append("dom.byId('")
                        .append(this.targetMarkupId).append("').value ='")
                        .append(escape
                                ? StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(value))
                                : value)
                        .append("';").append("});");
            }
            for (final String keyString : map.keySet()) {
                // if the map contains a key that is not defined in this
                // class it is assumed to be the name of a field
                if (!(EFapsKey.PICKER_JAVASCRIPT.getKey().equals(keyString)
                        || EFapsKey.PICKER_DEACTIVATEESCAPE.getKey().equals(keyString)
                        || EFapsKey.PICKER_VALUE.getKey().equals(keyString))) {
                    final Object valueObj = map.get(keyString);
                    final String strValue;
                    final String strLabel;
                    if (valueObj instanceof String[] && ((String[]) valueObj).length == 2) {
                        strValue = escape && !((String[]) valueObj)[0].contains("Array(")
                                ? StringEscapeUtils.escapeEcmaScript(((String[]) valueObj)[0])
                                : ((String[]) valueObj)[0];
                        strLabel = escape && !((String[]) valueObj)[0].contains("Array(")
                                ? StringEscapeUtils.escapeEcmaScript(((String[]) valueObj)[1])
                                : ((String[]) valueObj)[1];
                    } else {
                        strValue = escape && !String.valueOf(valueObj).contains("Array(")
                                ? StringEscapeUtils.escapeEcmaScript(String.valueOf(valueObj))
                                : String.valueOf(valueObj);
                        strLabel = null;
                    }

                    js.append("eFapsSetFieldValue(")
                            .append(this.targetMarkupId == null ? 0 : "'" + this.targetMarkupId + "'")
                            .append(",'").append(keyString).append("',")
                            .append(strValue.contains("Array(") ? "" : "'").append(strValue)
                            .append(strValue.contains("Array(") ? "" : "'");
                    if (strLabel != null) {
                        js.append(",'").append(strLabel).append("'");
                    }
                    js.append(");");
                }
            }
            if (map.containsKey(EFapsKey.PICKER_JAVASCRIPT.getKey())) {
                js.append(map.get(EFapsKey.PICKER_JAVASCRIPT.getKey()));
            }
            _target.prependJavaScript(js.toString());
            picker.setExecuted(false);
        }
    }
}

From source file:org.geopoke.WorldMap.java

public void removeMarker(CacheDetailsNode node) {
        webview.getEngine().executeScript(
                "document.removeMarker(\"" + StringEscapeUtils.escapeEcmaScript(node.getCache().getName()) + "\")");
        markers.remove(node);/*w  w w  . j  a  va  2s  .  c  om*/
    }

From source file:org.gsweb.components.ui.TextBox.java

private Map<String, Object> getParameters(String type) {
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("id", this.id);
    params.put("name", this.name);
    params.put("maxlength", String.valueOf(this.maxlength));
    params.put("placeHolder", StringEscapeUtils.escapeEcmaScript(this.placeHolder));
    params.put("width", String.valueOf(this.width));
    params.put("value", this.value);
    Object valueStackObj = null;//from ww w .j  a  v  a2s .c o m
    if (!StringUtils.isBlank(this.value)) {
        valueStackObj = ActionContext.getContext().getValueStack().findValue(this.value);
    }
    if (valueStackObj != null) { //  action       
        this.fillValueByValueStackObj(params, valueStackObj);
    }
    params.put("readonly", this.readonly);
    return params;
}

From source file:org.jboss.arquillian.ajocado.waiting.ajax.DefaultAjaxWaiting.java

private <T> JavaScript prepareCondition(T oldValue, JavaScriptRetriever<T> retriever) {
    final String scriptString = retriever.getJavaScriptRetrieve().getAsString();
    final String oldValueString = retriever.getConvertor().forwardConversion(oldValue);
    final String escapedOldValueString = StringEscapeUtils.escapeEcmaScript(oldValueString);
    return js("{0} != '{1}'").parametrize(scriptString, escapedOldValueString);
}

From source file:org.jboss.arquillian.ajocado.waiting.retrievers.AttributeRetriever.java

/**
 * JavaScript expression to retrieve attribute value from element given by attributeLocator
 *///from   w  w  w.  j ava 2 s.com
@Override
public JavaScript getJavaScriptRetrieve() {
    String escapedLocator = StringEscapeUtils.escapeEcmaScript(attributeLocator.inSeleniumRepresentation());
    return js("selenium.getAttribute('{0}')").parametrize(escapedLocator);
}

From source file:org.jboss.arquillian.ajocado.waiting.retrievers.TextRetriever.java

/**
 * JavaScript expression to retrieve text value from element given by elementLocator
 *///  ww  w.ja v a2  s.  c  o  m
@Override
public JavaScript getJavaScriptRetrieve() {
    String escapedLocator = StringEscapeUtils.escapeEcmaScript(elementLocator.inSeleniumRepresentation());
    return js("selenium.getText('{0}')").parametrize(escapedLocator);
}

From source file:org.jtwig.functions.builtin.StringFunctions.java

@JtwigFunction(name = "escape", aliases = { "e" })
public String escape(@Parameter String input, @Parameter String strategy) throws FunctionException {
    switch (EscapeStrategy.strategyByName(strategy.toLowerCase())) {
    case JAVASCRIPT:
        return StringEscapeUtils.escapeEcmaScript(input);
    case XML:/*w w w . j av  a  2s.c  o m*/
        return StringEscapeUtils.escapeXml(input);
    case HTML: // Default html
    default:
        return StringEscapeUtils.escapeHtml4(input);
    }
}

From source file:org.messic.server.tld.EscapeMessic.java

public static String escapeJS(String texto) {
    String result = StringEscapeUtils.escapeEcmaScript(texto);
    return result;
}

From source file:org.messic.server.tld.EscapeMessic.java

public static String escapeAll(String texto) {
    String result = StringEscapeUtils.escapeEcmaScript(StringEscapeUtils.escapeHtml4(texto));
    return result;
}