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: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 www.  jav a 2s  .c  om

    // 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.jaeksoft.searchlib.crawler.web.spider.ClickCapture.java

@JsonIgnore
@XmlTransient// ww  w. j a v a  2s.  c  o m
private String sql(String sql) {
    sql = StringUtils.replace(sql, "{custom}",
            selector.custom == null ? StringUtils.EMPTY : StringEscapeUtils.escapeEcmaScript(selector.custom));
    sql = StringUtils.replace(sql, "{anchor_href}",
            anchorHref == null ? StringUtils.EMPTY : StringEscapeUtils.escapeEcmaScript(anchorHref));
    sql = StringUtils.replace(sql, "{final_url}",
            finalUrl == null ? StringUtils.EMPTY : StringEscapeUtils.escapeEcmaScript(finalUrl));
    sql = StringUtils.replace(sql, "{embed_src}",
            embedSrc == null ? StringUtils.EMPTY : StringEscapeUtils.escapeEcmaScript(embedSrc));
    sql = StringUtils.replace(sql, "{img_src}",
            imgSrc == null ? StringUtils.EMPTY : StringEscapeUtils.escapeEcmaScript(imgSrc));
    sql = StringUtils.replace(sql, "{filename}",
            filename == null ? StringUtils.EMPTY : StringEscapeUtils.escapeEcmaScript(filename));
    sql = StringUtils.replace(sql, "{file_md5}",
            file_md5 == null ? StringUtils.EMPTY : StringEscapeUtils.escapeEcmaScript(file_md5));
    sql = StringUtils.replace(sql, "{file_phash}",
            file_phash == null ? StringUtils.EMPTY : StringEscapeUtils.escapeEcmaScript(file_phash));
    return sql;
}

From source file:com.wegas.log.neo4j.Neo4jPlayerReply.java

/**
 * Creates a new Question node, with all the necessary properties.
 *
 * @param player             the player data
 * @param reply              the player's answer data
 * @param choiceDescriptor   the selected choice description
 * @param questionDescriptor the selected question description
 * @return a node object//www.j  ava  2 s .  c  o  m
 */
private static ObjectNode createJsonNode(Player player, Reply reply, ChoiceDescriptor choiceDescriptor,
        QuestionDescriptor questionDescriptor) {
    ObjectNode jsonObject = objectMapper.createObjectNode();

    jsonObject.put("playerId", player.getId());
    jsonObject.put("type", TYPE.QUESTION.toString());
    jsonObject.put("teamId", player.getTeamId());
    jsonObject.put("gameId", player.getGameId());
    jsonObject.put("name", player.getName());
    jsonObject.put("starttime", (new Date()).getTime());
    jsonObject.put("choice", choiceDescriptor.getName());
    jsonObject.put("question", questionDescriptor.getName());
    jsonObject.put("result", reply.getResult().getName());
    jsonObject.put("times", reply.getQuestionInstance().getReplies().size());
    if (reply.getResult().getImpact() != null) {
        jsonObject.put("impact",
                StringEscapeUtils.escapeEcmaScript(reply.getResult().getImpact().getContent()));
    } else {
        jsonObject.put("impact", "");
    }
    jsonObject.put("logID", player.getGameModel().getProperties().getLogID());
    return jsonObject;
}

From source file:com.tuplejump.stargate.cassandra.SearchSupport.java

@Override
public List<Row> search(ExtendedFilter mainFilter) {
    List<IndexExpression> clause = mainFilter.getClause();
    if (logger.isDebugEnabled())
        logger.debug("All IndexExprs {}", clause);
    try {//from  ww  w  .  ja  v  a2  s.c o m
        String queryString = getQueryString(matchThisIndex(clause));
        Search search = getQuery(queryString);
        return getRows(mainFilter, search, queryString);
    } catch (Exception e) {
        logger.error("Exception occurred while querying", e);
        if (tableMapper.isMetaColumn) {
            ByteBuffer errorMsg = UTF8Type.instance
                    .decompose("{\"error\":\"" + StringEscapeUtils.escapeEcmaScript(e.getMessage()) + "\"}");
            Row row = tableMapper.getRowWithMetaColumn(errorMsg);
            if (row != null) {
                return Collections.singletonList(row);
            }
        }
        return Collections.EMPTY_LIST;
    }
}

From source file:com.tuplejump.stargate.cassandra.ErrorReporter.java

public void addErrorColumn(ColumnFamilyStore table, String colName, String errorMsg,
        ColumnFamily cleanColumnFamily) {
    CompositeType baseComparator = (CompositeType) table.getComparator();
    int prefixSize = baseComparator.types.size() - (table.metadata.getCfDef().hasCollections ? 2 : 1);
    CompositeType.Builder builder = baseComparator.builder();
    for (int i = 0; i < prefixSize; i++)
        builder.add(Fields.defaultValue(baseComparator.types.get(i)));
    builder.add(UTF8Type.instance.decompose(colName));
    ByteBuffer finalColumnName = builder.build();
    Column scoreColumn = new Column(finalColumnName, UTF8Type.instance
            .decompose("{\"error\":\"" + StringEscapeUtils.escapeEcmaScript(errorMsg) + "\"}"));
    cleanColumnFamily.addColumn(scoreColumn);
}

From source file:com.day.cq.wcm.foundation.forms.FieldHelper.java

/**
 * Get the full qualified path to a suffixed field (e.g. @Write) to be used in client java script.
 * @param request The request//  w w  w .j av a2 s.c  o m
 * @param desc The field descritpion
 * @param suffix The suffix
 * @return The qualified path
 * @since 5.5
 */
public static String getClientFieldQualifier(SlingHttpServletRequest request, FieldDescription desc,
        String suffix) {
    final String formId = FormsHelper.getFormId(request);
    return "document.forms[\"" + StringEscapeUtils.escapeEcmaScript(formId) + "\"]" + ".elements[\""
            + desc.getName() + suffix + "\"]";
}

From source file:com.premiumminds.webapp.wicket.bootstrap.BootstrapFeedbackPopover.java

@Override
public void renderHead(IHeaderResponse response) {
    super.renderHead(response);

    List<FeedbackMessage> msgs = model.getObject();
    if (msgs.size() > 0) {
        for (Component component : messages.keySet()) {
            StringBuffer sb = new StringBuffer();
            for (FeedbackMessage msg : messages.get(component)) {
                sb.append(msg.getMessage() + "\n");
                msg.markRendered();//from  ww  w  . j a  v  a2  s.  com
            }

            String script = "$(\"#" + component.getMarkupId() + "\")" + ".popover({ 'trigger': 'focus', "
                    + "'placement': 'top', " + "'content': \""
                    + StringEscapeUtils.escapeEcmaScript(sb.toString()) + "\", "
                    + "'template': '<div class=\"popover feedback-popover\"><div class=\"arrow\"></div><div class=\"popover-inner\"><h3 class=\"popover-title\"></h3><div class=\"popover-content\"><p></p></div></div></div>'"
                    + "});";
            script += "$(\"#" + component.getMarkupId() + "\").keypress(function(){ $(\"#" + this.getMarkupId()
                    + "\").removeClass('has-error'); $(this).popover('destroy'); });";
            response.render(OnDomReadyHeaderItem.forScript(script));
        }
    }

}

From source file:com.day.cq.wcm.foundation.forms.ValidationHelper.java

/**
 * Write java script client code for a required check.
 * @deprecated Use {@link FieldHelper#writeClientRequiredCheck(SlingHttpServletRequest, SlingHttpServletResponse, FieldDescription)}
 *//*from w  w  w  .  ja  v a  2s. c om*/
@Deprecated
public static void writeRequiredCheck(final SlingHttpServletRequest request, final Resource resource,
        final JspWriter out) throws IOException {
    final String formId = FormsHelper.getFormId(request);
    final String name = FormsHelper.getParameterName(resource);

    if (FormsHelper.isRequired(resource)) {
        final String qualifier = getFormElementQualifier(request, resource);
        out.print("if (cq5forms_isEmpty(");
        out.print(qualifier);
        out.print(")) {cq5forms_showMsg('");
        out.print(StringEscapeUtils.escapeEcmaScript(formId));
        out.print("','");
        out.print(StringEscapeUtils.escapeEcmaScript(name));
        out.print("','");
        out.print(StringEscapeUtils.escapeEcmaScript(ValidationHelper.getRequiredMessage(resource)));
        out.println("'); return false; }");
    }
}

From source file:com.day.cq.wcm.foundation.forms.FieldHelper.java

/**
 * Write the client java script code to check a required field on
 * form submit.//from  w  ww.  j ava2 s  . c  om
 */
public static void writeClientRequiredCheck(final SlingHttpServletRequest request,
        final SlingHttpServletResponse response, final FieldDescription desc) throws IOException {
    final String formId = FormsHelper.getFormId(request);
    if (desc.isRequired()) {
        final PrintWriter out = response.getWriter();
        final String qualifier = getClientFieldQualifier(request, desc);
        out.write("if (cq5forms_isEmpty(");
        out.write(qualifier);
        out.write(")) {cq5forms_showMsg('");
        out.write(StringEscapeUtils.escapeEcmaScript(formId));
        out.write("','");
        out.write(StringEscapeUtils.escapeEcmaScript(desc.getName()));
        out.write("','");
        out.write(StringEscapeUtils.escapeEcmaScript(desc.getRequiredMessage()));
        out.write("'); return false; }\n");
    }
}

From source file:com.thejustdo.util.Utils.java

/**
 * Formats a string to avoid any injection exploit by escaping the special
 * characters.//from  www .  j  a  va2  s.com
 *
 * @param s String to be modified.
 * @return Modified string.
 */
public static String escapeString(String s) {
    String answer;
    answer = StringEscapeUtils.escapeCsv(s);
    answer = StringEscapeUtils.escapeEcmaScript(answer);
    answer = StringEscapeUtils.escapeHtml3(answer);
    answer = StringEscapeUtils.escapeHtml4(answer);
    answer = StringEscapeUtils.escapeJava(answer);
    answer = StringEscapeUtils.escapeXml(answer);
    return answer;
}