Example usage for com.google.gwt.safehtml.shared SafeHtmlUtils htmlEscape

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlUtils htmlEscape

Introduction

In this page you can find the example usage for com.google.gwt.safehtml.shared SafeHtmlUtils htmlEscape.

Prototype

public static String htmlEscape(String s) 

Source Link

Document

HTML-escapes a string.

Usage

From source file:edu.arizona.biosemantics.gxt.theme.green.client.base.field.Css3TextFieldAppearance.java

License:sencha.com license

@Override
public void render(SafeHtmlBuilder sb, String type, String value, FieldAppearanceOptions options) {
    String inputStyles = "";
    String wrapStyles = "";

    int width = options.getWidth();

    String name = options.getName() != null ? " name='" + options.getName() + "' " : "";
    String disabled = options.isDisabled() ? "disabled=true" : "";
    String placeholder = options.getEmptyText() != null
            ? " placeholder='" + SafeHtmlUtils.htmlEscape(options.getEmptyText()) + "' "
            : "";

    boolean empty = false;

    if ((value == null || value.equals("")) && options.getEmptyText() != null) {
        if (GXT.isIE8() || GXT.isIE9()) {
            value = options.getEmptyText();
        }/*  ww  w .j  a  va 2 s.  c o  m*/
        empty = true;
    }

    if (width != -1) {
        wrapStyles += "width:" + width + "px;";
        width = adjustTextAreaWidth(width);
        inputStyles += "width:" + width + "px;";
    }

    String cls = style.text() + " " + style.field();
    if (empty) {
        cls += " " + style.empty();
    }

    String ro = options.isReadonly() ? " readonly" : "";

    value = SafeHtmlUtils.htmlEscape(value);

    sb.appendHtmlConstant("<div style='" + wrapStyles + "' class='" + style.wrap() + "'>");
    sb.appendHtmlConstant("<input " + name + disabled + " value='" + value + "' style='" + inputStyles
            + "' type='" + type + "' class='" + cls + "'" + ro + placeholder + ">");

}

From source file:edu.arizona.biosemantics.gxt.theme.green.client.base.field.Css3TriggerFieldAppearance.java

License:sencha.com license

protected void renderInput(SafeHtmlBuilder shb, String value, SafeStyles inputStyles,
        FieldAppearanceOptions options) {
    StringBuilder sb = new StringBuilder();
    sb.append("<input ");

    if (options.isDisabled()) {
        sb.append("disabled=true");
    }/*from  w  ww  .j av  a  2s. c  om*/

    if (options.getName() != null) {
        sb.append("name='").append(SafeHtmlUtils.htmlEscape(options.getName())).append("' ");
    }

    if (options.isReadonly() || !options.isEditable()) {
        sb.append("readonly ");
    }

    if (inputStyles != null) {
        sb.append("style='").append(inputStyles.asString()).append("' ");
    }

    sb.append("class='").append(getStyle().field()).append(" ").append(getStyle().text());

    String placeholder = options.getEmptyText() != null
            ? " placeholder='" + SafeHtmlUtils.htmlEscape(options.getEmptyText()) + "' "
            : "";

    if ("".equals(value) && options.getEmptyText() != null) {
        sb.append(" ").append(getStyle().empty());
        if (GXT.isIE8() || GXT.isIE9()) {
            value = options.getEmptyText();
        }
    }

    if (!options.isEditable()) {
        sb.append(" ").append(getStyle().noedit());
    }

    sb.append("' ");
    sb.append(placeholder);

    sb.append("type='text' value='").append(SafeHtmlUtils.htmlEscape(value)).append("' ");

    sb.append("/>");

    shb.append(SafeHtmlUtils.fromTrustedString(sb.toString()));
}

From source file:edu.arizona.biosemantics.gxt.theme.green.client.base.mask.Css3MaskAppearance.java

License:sencha.com license

@Override
public void mask(XElement parent, String message) {
    XElement mask = XElement.createElement("div");
    mask.setClassName(resources.styles().mask());
    parent.appendChild(mask);/*  ww w . java2  s .  c o  m*/

    XElement box = null;
    if (message != null) {
        box = XDOM.create(template.template(resources.styles(), SafeHtmlUtils.htmlEscape(message))).cast();
        parent.appendChild(box);
    }

    if (GXT.isIE() && !(GXT.isIE7()) && "auto".equals(parent.getStyle().getHeight())) {
        mask.setSize(parent.getOffsetWidth(), parent.getOffsetHeight());
    }

    if (box != null) {
        box.updateZIndex(0);
        box.center(parent);
    }

}

From source file:edu.arizona.biosemantics.gxt.theme.green.client.sliced.button.SlicedButtonCellAppearance.java

License:sencha.com license

@Override
public void render(final ButtonCell<C> cell, Context context, C value, SafeHtmlBuilder sb) {
    String constantHtml = cell.getHTML();
    boolean hasConstantHtml = constantHtml != null && constantHtml.length() != 0;
    boolean isBoolean = value != null && value instanceof Boolean;
    // is a boolean always a toggle button?
    String text = hasConstantHtml ? cell.getText()
            : (value != null && !isBoolean) ? SafeHtmlUtils.htmlEscape(value.toString()) : "";

    ImageResource icon = cell.getIcon();
    IconAlign iconAlign = cell.getIconAlign();

    String cls = style.button();/*from  w  w w .j a v  a  2 s . com*/
    String arrowCls = "";
    if (cell.getMenu() != null) {

        if (cell instanceof SplitButtonCell) {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowCls = style.split();
                break;
            case BOTTOM:
                arrowCls = style.splitBottom();
                break;
            default:
                // empty
            }

        } else {
            switch (cell.getArrowAlign()) {
            case RIGHT:
                arrowCls = style.arrow();
                break;
            case BOTTOM:
                arrowCls = style.arrowBottom();
                break;
            }
        }

    }

    ButtonScale scale = cell.getScale();

    switch (scale) {
    case SMALL:
        cls += " " + style.small();
        break;
    case MEDIUM:
        cls += " " + style.medium();
        break;
    case LARGE:
        cls += " " + style.large();
        break;
    default:
        // empty
    }

    SafeStylesBuilder stylesBuilder = new SafeStylesBuilder();

    int width = -1;

    if (cell.getWidth() != -1) {
        int w = cell.getWidth();
        if (w < cell.getMinWidth()) {
            w = cell.getMinWidth();
        }
        stylesBuilder.appendTrustedString("width:" + w + "px;");
        cls += " " + style.hasWidth() + " x-has-width";
        width = w;
    } else {

        if (cell.getMinWidth() != -1) {
            TextMetrics.get().bind(style.text());
            int length = TextMetrics.get().getWidth(text);
            length += 6; // frames

            if (icon != null) {
                switch (iconAlign) {
                case LEFT:
                case RIGHT:
                    length += icon.getWidth();
                    break;
                default:
                    // empty
                }
            }
        }
    }

    final int height = cell.getHeight();
    if (height != -1) {
        stylesBuilder.appendTrustedString("height:" + height + "px;");
    }

    if (icon != null) {
        switch (iconAlign) {
        case TOP:
            arrowCls += " " + style.iconTop();
            break;
        case BOTTOM:
            arrowCls += " " + style.iconBottom();
            break;
        case LEFT:
            arrowCls += " " + style.iconLeft();
            break;
        case RIGHT:
            arrowCls += " " + style.iconRight();
            break;
        }

    } else {
        arrowCls += " " + style.noIcon();
    }

    // toggle button
    if (value == Boolean.TRUE) {
        cls += " " + frame.pressedClass();
    }

    sb.append(templates.outer(cls, new SafeStylesBuilder().toSafeStyles()));

    SafeHtmlBuilder inside = new SafeHtmlBuilder();

    String innerWrap = arrowCls;
    if (GXT.isIE6() || GXT.isIE7()) {
        arrowCls += " " + CommonStyles.get().inlineBlock();
    }

    inside.appendHtmlConstant("<div class='" + innerWrap + "'>");
    inside.appendHtmlConstant("<table cellpadding=0 cellspacing=0 class='" + style.mainTable() + "'>");

    boolean hasText = text != null && !text.equals("");

    if (icon != null) {
        switch (iconAlign) {
        case LEFT:
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            if (hasText) {
                int w = width - (icon != null ? icon.getWidth() : 0) - 4;
                writeText(inside, text, w, height);
            }
            inside.appendHtmlConstant("</tr>");
            break;
        case RIGHT:
            inside.appendHtmlConstant("<tr>");
            if (hasText) {
                int w = width - (icon != null ? icon.getWidth() : 0) - 4;
                writeText(inside, text, w, height);
            }
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            break;
        case TOP:
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            if (hasText) {
                inside.appendHtmlConstant("<tr>");
                writeText(inside, text, width, height);
                inside.appendHtmlConstant("</tr>");
            }
            break;
        case BOTTOM:
            if (hasText) {
                inside.appendHtmlConstant("<tr>");
                writeText(inside, text, width, height);
                inside.appendHtmlConstant("</tr>");
            }
            inside.appendHtmlConstant("<tr>");
            writeIcon(inside, icon, height);
            inside.appendHtmlConstant("</tr>");
            break;
        }

    } else {
        inside.appendHtmlConstant("<tr>");
        if (text != null) {
            writeText(inside, text, width, height);
        }
        inside.appendHtmlConstant("</tr>");
    }
    inside.appendHtmlConstant("</table>");
    inside.appendHtmlConstant("</div>");

    frame.render(sb,
            new Frame.FrameOptions(0, CommonStyles.get().noFocusOutline(), stylesBuilder.toSafeStyles()),
            inside.toSafeHtml());

    sb.appendHtmlConstant("</div>");

}

From source file:edu.arizona.biosemantics.gxt.theme.green.client.sliced.mask.SlicedMaskAppearance.java

License:sencha.com license

@Override
public void mask(XElement parent, String message) {
    XElement mask = XElement.createElement("div");
    mask.setClassName(resources.style().mask());
    parent.appendChild(mask);// w ww.j a  v  a 2s.c o m

    XElement box = null;
    if (message != null) {
        SafeHtmlBuilder sb = new SafeHtmlBuilder();
        SafeHtml content = template.template(resources.style(), SafeHtmlUtils.htmlEscape(message));
        frame.render(sb, Frame.EMPTY_FRAME, content);
        box = XDOM.create(sb.toSafeHtml()).cast();
        parent.appendChild(box);
    }

    if (GXT.isIE() && !(GXT.isIE7()) && "auto".equals(parent.getStyle().getHeight())) {
        mask.setSize(parent.getOffsetWidth(), parent.getOffsetHeight());
    }

    if (box != null) {
        box.updateZIndex(0);
        box.center(parent);
    }
}

From source file:fi.jyu.student.jatahama.onlineinquirytool.shared.Utils.java

License:Open Source License

public static String getSafeXHTMLTag(String tag, String id, String cls, String text) {
    String isnull = (text == null ? " ca:isnull=\"true\"" : " ca:isnull=\"false\"");
    String str = "<" + tag + isnull + (id != null ? " id=\"" + id + "\"" : "")
            + (cls != null ? " class=\"" + cls + "\"" : "") + ">";
    //str += "<![CDATA["; // xhtml not working in new javascript opened window
    str += text != null ? SafeHtmlUtils.htmlEscape(text) : OnlineInquiryTool.constants.tcTxtChartTextEmpty();
    //str += "]]></pre>"; // xhtml not working in new javascript opened window
    str += "</" + tag + ">";
    return str;/*from   w  w w .  j  a v a  2s. com*/
}

From source file:fi.jyu.student.jatahama.onlineinquirytool.shared.Utils.java

License:Open Source License

public static String getSafeXHTMLAnchor(String id, String cls, String href, String text) {
    String isnull = (text == null ? " ca:isnull=\"true\"" : " ca:isnull=\"false\"");
    String hrefl = "";
    if (href != null) {
        hrefl = " href=\"";
        hrefl += URL.encode(href);
        hrefl += "\"";
    }/* w w w. j  a  v  a  2s .  co m*/
    String str = "<a" + isnull + hrefl + (id != null ? " id=\"" + id + "\"" : "")
            + (cls != null ? " class=\"" + cls + "\"" : "") + ">";
    //str += "<![CDATA["; // xhtml not working in new javascript opened window
    str += text != null ? SafeHtmlUtils.htmlEscape(text) : OnlineInquiryTool.constants.tcTxtChartTextEmpty();
    //str += "]]></pre>"; // xhtml not working in new javascript opened window
    str += "</a>";
    return str;
}

From source file:fi.jyu.student.jatahama.onlineinquirytool.shared.Utils.java

License:Open Source License

public static String getSafeXHTML(String text) {
    return SafeHtmlUtils.htmlEscape(text);
}

From source file:fr.amapj.service.services.edgenerator.velocity.VCBuilder.java

License:Open Source License

/**
 * Permet d'escaper les caracteres HTML  
 *//*from   w w  w .ja v  a2 s. c  o m*/
static public String s(String value) {
    if (value == null) {
        return "";
    }
    return SafeHtmlUtils.htmlEscape(value);
}

From source file:fr.amapj.view.engine.popup.swicthpopup.SwitchPopup.java

License:Open Source License

protected void addLine(String lib, CorePopup popup) {
    infos.add(new SwitchPopupInfo(SafeHtmlUtils.htmlEscape(lib), popup));
}