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:cc.alcina.framework.gwt.client.cell.UnsafeHtmlCell.java

License:Apache License

@Override
public void render(Context context, FunctionalTuple value, SafeHtmlBuilder sb) {
    String prelude = "<div>";
    if (Ax.notBlank(value.title)) {
        prelude = Ax.format("<div title='%s'>", SafeHtmlUtils.htmlEscape(value.title));
    }/*from w  w w.  j av  a 2 s . co  m*/
    sb.append(SafeHtmlUtils.fromTrustedString(prelude));
    sb.append(SafeHtmlUtils.fromTrustedString(Ax.blankToEmpty(value.text)));
    sb.append(SafeHtmlUtils.fromTrustedString("</div>"));
}

From source file:cc.alcina.framework.gwt.client.gwittir.widget.ExpandableLabel.java

License:Apache License

@Override
public void setValue(Object o) {
    fp.clear();//from  ww w.  j av a2s  . c  o m
    if (o == null) {
        // fp.add(new InlineLabel("[Undefined]"));
        return;
    }
    boolean hidden = false;
    if (o instanceof Collection) {
        ArrayList l = new ArrayList((Collection) o);
        if (l.size() > 0 && l.get(0) instanceof Comparable) {
            Collections.sort(l);
        }
        int strlen = 0;
        for (Object object : l) {
            InlineLabel comma = new InlineLabel(", ");
            if (strlen > 0) {
                fp.add(comma);
                strlen += 2;
            }
            String name = ClientReflector.get().displayNameForObject(object);
            InlineLabel label = new InlineLabel(name);
            if (strlen > getMaxLength()) {
                comma.setVisible(false);
                label.setVisible(false);
                hiddenWidgets.add(comma);
                hiddenWidgets.add(label);
                hidden = true;
            }
            strlen += name.length();
            fp.add(label);
        }
    } else {
        fullText = renderer == null ? o.toString() : renderer.render(o).toString();
        fullTextNoBrs = fullText;
        if (isShowNewlinesAsBreaks()) {
            fullText = SafeHtmlUtils.htmlEscape(fullText).replace("\n", "<br>\n");
        }
        int maxC = getMaxLength();
        int y1 = fullText.indexOf(">", maxC);
        int y2 = fullText.indexOf("<", maxC);
        int y3 = fullText.indexOf("<");
        if (y1 < y2 && y1 != -1 && y3 < maxC && !escapeHtml) {
            maxC = y1 + 1;
        }
        String vis = CommonUtils.trimToWsChars(fullText, maxC);
        com.google.gwt.user.client.ui.Label label;
        if (fullText.length() == vis.length()) {
            label = isShowNewlinesAsBreaks() ? new InlineHTML(fullText) : new InlineLabel(fullText);
            fp.add(label);
        } else {
            label = isShowNewlinesAsBreaks() ? new InlineHTML(vis) : new InlineLabel(vis);
            fp.add(label);
            hidden = true;
            if (!isShowAsPopup()) {
                String notVis = fullText.substring(vis.length());
                label = isShowNewlinesAsBreaks() ? new InlineHTML(notVis) : new InlineLabel(notVis);
                label.setVisible(false);
                fp.add(label);
                hiddenWidgets.add(label);
            }
        }
    }
    if (hidden) {
        this.dots = new InlineLabel("...");
        this.space = new InlineHTML("&nbsp;");
        fp.add(dots);
        this.hiding = true;
        this.showLink = new Link("[more]");
        this.hideLink = new Link("[less]");
        if (isShowHideAtEnd()) {
            fp.add(space);
            fp.add(hideLink);
        } else {
            fp.insert(hideLink, 0);
            fp.add(space);
        }
        hideLink.setVisible(false);
        space.setVisible(false);
        fp.add(showLink);
        hideLink.addClickHandler(showHideListener);
        showLink.addClickHandler(showHideListener);
    }
}

From source file:cc.alcina.framework.gwt.client.ide.node.DomainNode.java

License:Apache License

public void refreshFromObject() {
    ClientBeanReflector info = ClientReflector.get().beanInfoForClass(getUserObject().getClass());
    displayName = info.getObjectName(getUserObject());
    if (displayName != null) {
        displayName = SafeHtmlUtils.htmlEscape(displayName);
    } else {/*www.j a  va2s.c  om*/
        displayName = "[null]";
    }
    if (!isUnrendered()) {
        renderHtml();
    }
}

From source file:ch.unifr.pai.mindmap.client.mindmap.MindmapNoteWidget.java

License:Apache License

/**
 * The actual rendering of the HTML representation of the note widget. This method resets the previous rendering when called repeatedly.
 *//*  w ww . j  a  v  a  2 s.c o  m*/
private void render() {

    if (disclosed) {
        StringBuilder sb = new StringBuilder();
        sb.append("<span class=\"noteUserName\">");
        sb.append(SafeHtmlUtils.htmlEscape(note.getUserName()));
        sb.append("</span><span class=\"noteContent\" style=\"visibility:hidden;\">");
        sb.append(SafeHtmlUtils.htmlEscape(note.content).replaceAll("\n", "<br/>"));
        sb.append("</span>");
        view.setHTML(sb.toString());
    } else {
        view.setHTML("<span class=\"noteUserName\">" + SafeHtmlUtils.htmlEscape(note.getUserName())
                + "</span><span class=\"noteContent\">"
                + SafeHtmlUtils.htmlEscape(note.content).replaceAll("\n", "<br/>") + "</span>");
    }
    if (note.blocked != null && note.blocked)
        this.addStyleName("remotelyBlocked");
    else
        this.removeStyleName("remotelyBlocked");
    if (note.x != null)
        getElement().getStyle().setLeft(note.x, Unit.PX);
    if (note.y != null)
        getElement().getStyle().setTop(note.y, Unit.PX);
}

From source file:cl.uai.client.marks.Mark.java

License:Open Source License

protected String getMarkPopupHTML() {
    String html = "";
    if (this.getRawtext() != null && this.getRawtext().length() > 0) {
        html += "<div class=\"" + Resources.INSTANCE.css().markrawtext() + "\">"
                + SafeHtmlUtils.htmlEscape(this.getRawtext()) + "</div>";
    }/*w w  w  . j a v  a  2s.co m*/
    // Show the marker's name if the marking process is not anonymous
    if (!EMarkingConfiguration.isMarkerAnonymous()) {
        html += "<div class=\"" + Resources.INSTANCE.css().markmarkername() + "\">" + markername + "</div>";
    }
    return html;
}

From source file:cl.uai.client.marks.Mark.java

License:Open Source License

/**
 * Sets the inner HTML according to an icon
 *///from   w  w w .ja va2 s.c  o m
public void setMarkHTML() {

    // Starts with an empty HTML
    String html = "";
    String iconhtml = "";

    // Create the icon string if any
    if (this.iconType != null) {
        Icon icon = new Icon(this.iconType);
        iconhtml = icon.toString();
    } else if (this.iconOnly && this instanceof CustomMark) {
        CustomMark cmark = (CustomMark) this;
        iconhtml = cmark.getTitle();
    }

    String markername = EMarkingConfiguration.isMarkerAnonymous()
            ? MarkingInterface.messages.MarkerDetails(MarkingInterface.messages.Anonymous())
            : MarkingInterface.messages.MarkerDetails(this.getMarkername());
    String styleColor = "";

    // If the mark has a color, we use the background to color it
    if (this.criterionid > 0 && this.iconOnly) {
        styleColor = "style=\"color:" + Color.getCSSHueColor(criterionid) + "\"";
    }

    html += "<div class=\"" + Resources.INSTANCE.css().markicon() + "\" title=\"" + markername + "\" "
            + styleColor + ">" + iconhtml + "</div>";
    // If the mark is an icon
    if ((!this.iconOnly
            || EMarkingConfiguration.getRubricMarkType() == EMarkingConfiguration.EMARKING_RUBRICMARK_TEXTBOX)
            && this.getRawtext().trim().length() > 0) {
        html += "<div class=\"" + Resources.INSTANCE.css().markrawtext() + "\">"
                + SafeHtmlUtils.htmlEscape(this.getRawtext()) + "</div>";
        // Show the marker's name if the marking process is not anonymous
        if (!EMarkingConfiguration.isMarkerAnonymous()) {
            html += "<div class=\"" + Resources.INSTANCE.css().markmarkername() + "\">" + markername + "</div>";
        }
    }

    this.removeStyleName(Resources.INSTANCE.css().rubricmarkpopup());
    if (EMarkingConfiguration.getRubricMarkType() == EMarkingConfiguration.EMARKING_RUBRICMARK_TEXTBOX) {
        this.addStyleName(Resources.INSTANCE.css().rubricmarkpopup());
    }
    this.setHTML(html);
}

From source file:cl.uai.client.marks.RubricMark.java

License:Open Source License

@Override
protected String getMarkPopupHTML() {
    // Starts with an empty HTML
    String html = "";
    boolean headerOnly = false;

    RubricMark rmark = (RubricMark) this;
    headerOnly = rmark.isHeaderOnly();//from  www.j a va  2s.c  o  m

    String criterionindex = "" + EMarkingWeb.markingInterface.getRubricInterface().getRubricPanel()
            .getCriterionIndex(rmark.getCriterionId());
    String leveldesc = headerOnly ? criterionindex
            : " " + SafeHtmlUtils.htmlEscape(rmark.getLevel().getCriterion().getDescription());
    String score = EMarkingConfiguration.isFormativeFeedbackOnly() ?
    // Level information only
            rmark.getLevel().getCriterion()
                    .getLevelFormativeIndex(rmark.getLevel().getCriterion().getSelectedLevel().getId()) + " / "
                    + rmark.getLevel().getCriterion().getLevels().size()
            :
            // Score and bonus information
            RubricMark.scoreFormat(rmark.getLevel().getScore() + rmark.getLevel().getBonus(), false) + " / "
                    + RubricMark.scoreFormat(rmark.getLevel().getCriterion().getMaxscore(), false);
    Icon icon = new Icon(this.iconType);

    html += "<table class=\"markrubricheader\" style=\"background-color:hsl("
            + rmark.getLevel().getCriterion().getHue() + ",100%,75%);\" width=\"100%\">"
            + "<tr><td style=\"text-align: left;\"><div class=\"" + Resources.INSTANCE.css().markicon() + "\">"
            + icon.toString() + "</div></td><td><div class=\"" + Resources.INSTANCE.css().markcrit() + "\">"
            + leveldesc + "</div></td>";
    html += "<td style=\"text-align: right;\" nowrap><div class=\"" + Resources.INSTANCE.css().markpts() + "\">"
            + score + "</div></td></tr></table>";
    if (!headerOnly) {
        // Show the level description
        html += "<div class=\"" + Resources.INSTANCE.css().marklvl() + "\">" + rmark.getLevel().getDescription()
                + "</div>";
        html += "<div class=\"" + Resources.INSTANCE.css().markrawtext() + "\">"
                + SafeHtmlUtils.htmlEscape(this.getRawtext()) + "</div>";
        // Show the feedback
        if (!EMarkingConfiguration.getKeywords().equals("") && feedback.size() > 0) {
            html += "<div class=\"" + Resources.INSTANCE.css().markmarkername() + "\">" + "Feedback" + "</div>";
            int count = 0;
            while (count < feedback.size()) {
                Anchor resourceLink = new Anchor(feedback.get(count).getName().replaceAll("\\<.*?>", ""), true,
                        feedback.get(count).getLink(), "_blank");
                resourceLink.addStyleName(Resources.INSTANCE.css().resourcelink());

                String sourceName = "";
                switch (feedback.get(count).getNameOER()) {
                case "ocwmit":
                    sourceName = "OCW MIT";
                    break;
                case "merlot":
                    sourceName = "Merlot";
                    break;
                case "CS50":
                    sourceName = "CS50 Harvard";
                    break;
                default:
                    sourceName = "Webcursos";
                }
                html += "<div class=\"" + Resources.INSTANCE.css().markrawtext() + "\">" + (count + 1) + ".-"
                        + resourceLink + "<br>" + "Source: " + sourceName + "</div>";
                count = count + 1;
            }
        }
        // Show the marker's name if the marking process is not anonymous
        if (!EMarkingConfiguration.isMarkerAnonymous()) {
            html += "<div class=\"" + Resources.INSTANCE.css().markmarkername() + "\">"
                    + MarkingInterface.messages.MarkerDetails(this.getMarkername()) + "</div>";
        }
    }

    if (this.getRegradeid() > 0 && !headerOnly) {
        html += "<div style=\"background-color:#FFFF99; width:99%; font-size: 10pt;\" class=\""
                + Resources.INSTANCE.css().markcrit() + "\">" + MarkingInterface.messages.Regrade() + " "
                + MarkingInterface.messages.Requested() + "</div>";
        html += "<div class=\"" + Resources.INSTANCE.css().marklvl() + "\">"
                + MarkingInterface.messages.Motive() + ": " + this.getRegradeMotiveText() + "<hr>"
                + MarkingInterface.messages.Comment() + ": "
                + SafeHtmlUtils.htmlEscape(this.getRegradecomment()) + "</div>";
        if (this.getRegradeaccepted() > 0) {
            html += "<div style=\"background-color:#FFFF99; width:99%; font-size: 10pt;\" class=\""
                    + Resources.INSTANCE.css().markcrit() + "\">" + MarkingInterface.messages.Regrade() + " "
                    + MarkingInterface.messages.Replied() + "</div>";
            html += "<div class=\"" + Resources.INSTANCE.css().marklvl() + "\">" + "<hr>"
                    + MarkingInterface.messages.RegradeReply() + ": "
                    + SafeHtmlUtils.htmlEscape(this.getRegrademarkercomment()) + "</div>";
        }
    }

    return html;
}

From source file:com.alkacon.acacia.client.ui.AttributeValueView.java

License:Open Source License

/**
 * Generates the attribute label.<p>
 *//*from  w  w w .j  a  v  a2 s.c om*/
private void generateLabel() {

    HTML labelWidget = new HTML("<div title=\"" + SafeHtmlUtils.htmlEscape(stripHtml(m_help)) + "\" class=\""
            + formCss().label() + "\">" + m_label + "</div>");
    m_widgetHolder.add(labelWidget);
}

From source file:com.arcbees.chosen.client.ChosenImpl.java

License:Apache License

private void winnowResults(boolean isShowing) {
    noResultClear();/*w  ww .  j  av  a 2  s  .co  m*/

    String searchText = defaultText.equals(searchField.val()) ? "" : searchField.val().trim();
    searchText = SafeHtmlUtils.htmlEscape(searchText);

    resultsFilter.filter(searchText, this, isShowing);
}

From source file:com.extjs.gxt.ui.client.widget.grid.RowEditor.java

License:sencha.com license

protected SafeHtml getErrorText() {
    StringBuffer sb = new StringBuffer();
    sb.append("<ul>");
    for (int i = 0; i < getItemCount(); i++) {

        Field<?> f = (Field<?>) getItem(i);
        if (!f.isValid(true)) {
            sb.append("<li><b>");
            sb.append(grid.getColumnModel().getColumn(i).getHeaderHtml().asString());
            sb.append("</b>: ");
            sb.append(SafeHtmlUtils.htmlEscape(f.getErrorMessage()));
            sb.append("</li>");
        }/*  w w w . jav  a2s . co m*/
    }
    sb.append("</ul>");
    return SafeHtmlUtils.fromTrustedString(sb.toString());
}