Example usage for com.google.gwt.safehtml.shared SimpleHtmlSanitizer sanitizeHtml

List of usage examples for com.google.gwt.safehtml.shared SimpleHtmlSanitizer sanitizeHtml

Introduction

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

Prototype

public static SafeHtml sanitizeHtml(String html) 

Source Link

Document

HTML-sanitizes a string.

Usage

From source file:cc.kune.common.client.msgs.UserMessageWidget.java

License:GNU Affero Public License

/**
 * Sets the msg./*www .  ja va2 s.co m*/
 *
 * @param title the title
 * @param message the message
 */
private void setMsg(final String title, final String message) {
    if (TextUtils.notEmpty(title)) {
        label.setHTML(MSG_WITH_TITLE.format(SimpleHtmlSanitizer.sanitizeHtml(title), sanitize(message)));
    } else {
        label.setHTML(MSG_NO_TITLE.format(sanitize(message)));
    }
}

From source file:com.ait.lienzo.ks.shared.XSS.java

License:Open Source License

public final String clean(String html) {
    if ((null == html) || (html.isEmpty())) {
        return html;
    }/*w  w w  .  j av a2 s.c  o  m*/
    return SimpleHtmlSanitizer.sanitizeHtml(html).asString();
}

From source file:de.eckhartarnold.client.ExtendedHtmlSanitizer.java

License:Apache License

@Override
public SafeHtml sanitize(String html) {
    String s = html.replaceAll("\n", "").replaceAll("<br>", "\n").replaceAll("<br />", "\n");
    String sanitized = SimpleHtmlSanitizer.sanitizeHtml(s).asString();
    return new OnlyToBeUsedInGeneratedCodeStringBlessedAsSafeHtml(sanitized.replaceAll("\n", "<br />"));
}

From source file:de.eckhartarnold.client.StatusTag.java

License:Apache License

/**
 * Sets the status tag if it (still) exists. Does nothing
 * otherwise.//  ww w  .  ja  v  a  2 s. com
 * 
 * @param html  the html code for the status tag
 */
public static void setHTML(String html) {
    if (create()) {
        tag.setInnerHTML(SimpleHtmlSanitizer.sanitizeHtml(html).asString());
    }
}

From source file:org.eclipse.che.ide.ext.git.client.GitOutputPartViewImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override//w  w w  .  ja  va 2s  . c o m
public void print(String text) {
    String preStyle = " style='margin:0px; font-size: 12px;' ";

    HTML html = new HTML();

    String TEXT = text.toUpperCase();
    if (TEXT.startsWith("[INFO]")) {
        html.setHTML("<pre" + preStyle + ">[<span style='color:" + INFO_COLOR + ";'><b>INFO</b></span>] "
                + SimpleHtmlSanitizer.sanitizeHtml(text.substring(6)).asString() + "</pre>");

    } else if (TEXT.startsWith("[ERROR]")) {
        html.setHTML("<pre" + preStyle + ">[<span style='color:" + ERROR_COLOR + ";'><b>ERROR</b></span>] "
                + SimpleHtmlSanitizer.sanitizeHtml(text.substring(7)).asString() + "</pre>");

    } else if (TEXT.startsWith("[WARNING]")) {
        html.setHTML("<pre" + preStyle + ">[<span style='color:" + WARNING_COLOR + ";'><b>WARNING</b></span>] "
                + SimpleHtmlSanitizer.sanitizeHtml(text.substring(9)).asString() + "</pre>");

    } else {
        html.setHTML("<pre" + preStyle + ">" + SimpleHtmlSanitizer.sanitizeHtml(text).asString() + "</pre>");
    }

    html.getElement().setAttribute("style", "padding-left: 2px;");
    consoleArea.add(html);
}

From source file:org.eclipse.che.ide.ext.git.client.GitOutputPartViewImpl.java

License:Open Source License

@Override
public void print(String text, String color) {
    String preStyle = " style='margin:0px; font-size: 12px;' ";

    HTML html = new HTML();
    html.setHTML("<pre" + preStyle + "><span style='color:" + SimpleHtmlSanitizer.sanitizeHtml(color).asString()
            + ";'>" + SimpleHtmlSanitizer.sanitizeHtml(text).asString() + "</span></pre>");

    html.getElement().setAttribute("style", "padding-left: 2px;");
    consoleArea.add(html);/*from w  ww.ja  va 2  s  . c om*/
}

From source file:org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputPartViewImpl.java

License:Open Source License

@Override
public void print(String text, String color) {
    PreElement pre = DOM.createElement("pre").cast();
    pre.setInnerText(text.isEmpty() ? "&nbsp;" : text);

    try {/*w  ww.j  a va 2 s . c  om*/
        pre.getStyle().setColor(SimpleHtmlSanitizer.sanitizeHtml(color).asString());
    } catch (Exception e) {
        Log.error(getClass(), "Unable to set color [" + color + "]", e);
    }

    consoleLines.getElement().appendChild(pre);
}

From source file:org.eclipse.che.ide.ext.runner.client.tabs.console.panel.MessageBuilder.java

License:Open Source License

/** @return an instance of {@link SafeHtml} with all given information */
@Nonnull/*from ww w . j  av a2 s .  c  o m*/
public SafeHtml build() {
    SafeHtmlBuilder builder = new SafeHtmlBuilder().appendHtmlConstant("<pre style='margin:0px;'>");
    StringBuilder prefixes = new StringBuilder();

    for (Iterator<MessageType> iterator = types.iterator(); iterator.hasNext();) {
        MessageType type = iterator.next();

        if (UNDEFINED.equals(type)) {
            builder.append(SimpleHtmlSanitizer.sanitizeHtml(message));
        } else {
            String prefix = type.getPrefix();

            builder.appendHtmlConstant("[<span style='color:" + type.getColor() + ";'>")
                    .appendHtmlConstant("<b>" + prefix.replaceAll("[\\[\\]]", "") + "</b></span>]");

            prefixes.append(prefix);

            if (iterator.hasNext()) {
                prefixes.append(' ');
            }
        }
    }

    builder.append(SimpleHtmlSanitizer.sanitizeHtml(message.substring(prefixes.length())));

    return builder.appendHtmlConstant("</pre>").toSafeHtml();
}

From source file:org.eclipse.che.ide.extension.builder.client.console.BuilderConsoleViewImpl.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from   ww  w. jav a  2  s  .c  om*/
public void printFF(char ch) {
    if (consoleArea.getWidgetCount() > 0) {
        final Widget firstWidget = consoleArea.getWidget(0);
        if (!firstWidget.getElement().getId().equals(FULL_LOGS_WIDGET_ID)) {
            consoleArea.insert(getFullLogsWidget(getFullLogsLink()), 0);
        }
    }

    final HTML html = new InlineHTML();
    final SafeHtml safeHtml = new SafeHtmlBuilder().appendHtmlConstant("<span>")
            .append(SimpleHtmlSanitizer.sanitizeHtml(String.valueOf(ch))).appendHtmlConstant("</span>")
            .toSafeHtml();
    html.setHTML(safeHtml);
    html.getElement().getStyle().setPaddingLeft(2, Style.Unit.PX);
    consoleArea.add(html);
}

From source file:org.eclipse.che.ide.extension.builder.client.console.BuilderConsoleViewImpl.java

License:Open Source License

/**
 * Return sanitized message (with all restricted HTML-tags escaped) in SafeHtml.
 *
 * @param type//w ww .  ja  va  2 s . c o m
 *         message type (info, error etc.)
 * @param color
 *         color constant
 * @param message
 *         message to print
 * @return message in SafeHtml
 */
private SafeHtml buildSafeHtmlMessage(String type, String color, String message) {
    return new SafeHtmlBuilder().appendHtmlConstant("<pre " + PRE_STYLE + ">")
            .appendHtmlConstant("[<span style='color:" + color + ";'><b>" + type + "</b></span>]")
            .append(SimpleHtmlSanitizer.sanitizeHtml(message.substring(("[" + type + "]").length())))
            .appendHtmlConstant("</pre>").toSafeHtml();
}