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

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

Introduction

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

Prototype

CharSequenceTranslator ESCAPE_ECMASCRIPT

To view the source code for org.apache.commons.lang3 StringEscapeUtils ESCAPE_ECMASCRIPT.

Click Source Link

Document

Translator object for escaping EcmaScript/JavaScript.

Usage

From source file:com.servoy.j2db.server.ngclient.template.FormLayoutStructureGenerator.java

private static void generateLayoutContainer(LayoutContainer container, ServoyDataConverterContext context,
        PrintWriter writer, boolean design, boolean highlight) throws IOException {
    if (highlight)
        writer.print("<div class='highlight_element'>");
    writer.print("<");
    writer.print(container.getTagType());
    if (design) {
        writer.print(" svy-id='");
        writer.print(container.getUUID().toString());
        writer.print("'");
        WebComponentPackageSpecification<WebLayoutSpecification> pkg = WebComponentSpecProvider.getInstance()
                .getLayoutSpecifications().get(container.getPackageName());
        WebLayoutSpecification spec = null;
        if (pkg != null && (spec = pkg.getSpecification(container.getSpecName())) != null) {
            List<String> allowedChildren = spec.getAllowedChildren();
            if (allowedChildren.size() > 0) {
                writer.print(" svy-allowed-children='");
                writer.print("[" + StringUtil.join(allowedChildren, ",") + "]");
                writer.print("'");
            }/*from   w w w . ja  va 2 s .c  o  m*/
            writer.print(" svy-layoutname='");
            writer.print(spec.getName());
            writer.print("'");
            if (spec.getDesignStyleClass() != null) {
                writer.print(" svy-designclass='");
                writer.print(spec.getDesignStyleClass());
                writer.print("'");
            }
        }

    }
    if (container.getElementId() != null) {
        writer.print(" id='");
        writer.print(container.getElementId());
        writer.print("' ");
    }
    Map<String, String> attributes = container.getAttributes();
    if (attributes != null) {
        for (Entry<String, String> entry : attributes.entrySet()) {
            writer.print(" ");
            StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(entry.getKey(), writer);
            if (entry.getValue() != null && entry.getValue().length() > 0) {
                writer.print("=\"");
                StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(entry.getValue(), writer);
                writer.print("\"");
            }
        }
    }
    writer.println(">");

    Iterator<IPersist> components = container.getAllObjects(PositionComparator.XY_PERSIST_COMPARATOR);
    while (components.hasNext()) {
        IPersist component = components.next();
        if (component instanceof LayoutContainer) {
            generateLayoutContainer((LayoutContainer) component, context, writer, design, highlight);
        } else if (component instanceof IFormElement) {
            FormLayoutGenerator.generateFormElement(writer,
                    FormElementHelper.INSTANCE.getFormElement((IFormElement) component, context, null), design,
                    highlight);
        }
    }
    writer.print("</");
    writer.print(container.getTagType());
    writer.print(">");
    if (highlight)
        writer.print("</div>");
}

From source file:org.jboss.dashboard.ui.taglib.PropertyReadTag.java

protected Object getPropertyValue() {
    log.debug("Getting property " + property + " from " + object);
    Object subjectOfTheGetter = null;
    if ("workspace".equalsIgnoreCase(object)) {
        subjectOfTheGetter = NavigationManager.lookup().getCurrentWorkspace();
    } else if ("section".equalsIgnoreCase(object)) {
        subjectOfTheGetter = NavigationManager.lookup().getCurrentSection();
    } else if ("panel".equalsIgnoreCase(object)) {
        subjectOfTheGetter = RequestContext.lookup().getActivePanel();
    } else if ("request".equalsIgnoreCase(object)) {
        subjectOfTheGetter = RequestContext.lookup().getRequest();
    } else if ("session".equalsIgnoreCase(object)) {
        subjectOfTheGetter = RequestContext.lookup().getRequest().getSessionObject();
    } else {//  w  w w. j a va  2 s .  c om
        log.warn("Invalid object to get property from: " + object);
    }
    if (subjectOfTheGetter == null) {
        log.debug("Cannot get current " + object);
        return null;
    }
    try {
        Object val = JXPathContext.newContext(subjectOfTheGetter).getValue(property);
        if (localize != null && localize.booleanValue() && val instanceof Map) {
            return StringEscapeUtils.ESCAPE_ECMASCRIPT
                    .translate(StringEscapeUtils.ESCAPE_HTML4.translate((String) (localize((Map) val))));
        }
        return StringEscapeUtils.ESCAPE_ECMASCRIPT
                .translate(StringEscapeUtils.ESCAPE_HTML4.translate((String) val));
    } catch (Exception e) {
        log.warn("Error accessing property " + property + " in " + object + "." + e);
        return null;
    }
}

From source file:org.jboss.dashboard.ui.utils.javascriptUtils.JavascriptTree.java

public String toString() {
    StringBuffer sb = new StringBuffer();
    sb.append("['");
    sb.append(StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(key));
    sb.append("',");
    if (val != null) {
        sb.append("'");
        sb.append(StringEscapeUtils.ESCAPE_ECMASCRIPT.translate(val));
        sb.append("'");
    } else {//from ww w .j  a v  a  2 s.c om
        sb.append(valInt);
    }
    if (children != null) {
        for (Iterator it = children.iterator(); it.hasNext();) {
            sb.append(",");
            sb.append(it.next());
        }
    }
    sb.append("]");
    return sb.toString();
}