Example usage for com.google.gwt.safehtml.shared SafeHtmlBuilder appendEscaped

List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder appendEscaped

Introduction

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

Prototype

public SafeHtmlBuilder appendEscaped(String text) 

Source Link

Document

Appends a string after HTML-escaping it.

Usage

From source file:com.eucalyptus.www.X509Download.java

License:Open Source License

public static String getError(String message) {
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    builder.append(SafeHtmlUtils.fromTrustedString(
            "<html><title>Getting credentials failed</title><body><div align=\"center\"><p><h1>Getting credentails failed</h1></p><p><img src=\"themes/active/logo.png\" /></p><p><h3 style=\"font-color: red;\">"));
    builder.appendEscaped(message);
    builder.append(SafeHtmlUtils.fromTrustedString("</h3></p></div></body></html>"));
    return builder.toSafeHtml().asString();
}

From source file:com.github.gwtbootstrap.client.ui.base.ValueBoxBase.java

License:Apache License

/**
 * //from www  . j  ava  2 s .c  om
 * @see com.google.gwt.editor.client.HasEditorErrors#showErrors(java.util.List)
 */
@Override
public void showErrors(List<EditorError> errors) {
    Widget decoratedWidget = controlGroup != null ? controlGroup : this;
    if (errors != null && !errors.isEmpty()) {
        StyleHelper.addStyle(decoratedWidget, ControlGroupType.ERROR);
        SafeHtmlBuilder sb = new SafeHtmlBuilder();
        for (EditorError error : errors) {
            if (error.getEditor() == this) {
                error.setConsumed(true);
                sb.appendEscaped(error.getMessage());
                sb.appendHtmlConstant("<br />");
            }
        }
        setErrorLabelText(sb.toSafeHtml().asString());
    } else {
        StyleHelper.removeStyle(decoratedWidget, ControlGroupType.ERROR);
        setErrorLabelText("");
    }
}

From source file:com.github.gwtbootstrap.client.ui.CodeBlock.java

License:Apache License

/**
 * Sets the widget's text./*from  w  w w .j  a  va  2  s  .com*/
 * <p>
 * Any HTML content is escaped and displayed as text.
 * 
 * @param html
 *            the text to be set
 */
public void setHTML(String html) {
    String[] lines = html.split("\\\\n");
    SafeHtmlBuilder shb = new SafeHtmlBuilder();

    for (String s : lines) {
        shb.appendEscaped(s);
        shb.appendHtmlConstant("<br/>");
    }

    if (getStyleName().contains("prettyprinted")) {
        removeStyleName("prettyprinted");
    }

    getElement().setInnerHTML(shb.toSafeHtml().asString());

    if (isAttached()) {
        helper.configure(linenums);
    }

}

From source file:com.goodow.web.ui.client.nav.TreeNodeCell.java

License:Apache License

@Override
public void render(final com.google.gwt.cell.client.Cell.Context context, final TreeNodeProxy value,
        final SafeHtmlBuilder sb) {
    if (value != null) {
        sb.appendEscaped(value.getName() == null ? value.getPath() : value.getName());
    }/*www  .j av a2 s .c o  m*/
}

From source file:com.google.api.explorer.client.auth.AuthView.java

License:Apache License

/**
 * Rebuild the popup from scratch with all of the scopes that we have from the last time we were
 * presented.//  ww  w .  j a  v a 2s  .  co  m
 */
private void buildScopePopup() {

    scopePanel.clear();
    additionalScopePanel.clear();

    Set<TextBox> oldEditors = Sets.newLinkedHashSet(freeFormEditors);
    freeFormEditors.clear();

    // Hide the service scopes label if there aren't any.
    hasScopesText.setVisible(!scopesFromDiscovery.isEmpty());
    noScopesText.setVisible(scopesFromDiscovery.isEmpty());

    // Show different text on the free-form scopes section when there are discovery scopes.
    optionalAdditionalScopes.setVisible(!scopesFromDiscovery.isEmpty());

    for (final Map.Entry<String, AuthScope> scope : scopesFromDiscovery.entrySet()) {
        // Add the check box to the table.
        CheckBox scopeToggle = new CheckBox();

        SafeHtmlBuilder safeHtml = new SafeHtmlBuilder();
        safeHtml.appendEscaped(scope.getKey()).appendHtmlConstant("<br><span>")
                .appendEscaped(scope.getValue().getDescription()).appendHtmlConstant("</span>");
        scopeToggle.setHTML(safeHtml.toSafeHtml());

        scopeToggle.addStyleName(style.discoveryScopeSelector());
        scopePanel.add(scopeToggle);

        // When the box is checked, add our scope to the selected list.
        scopeToggle.addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                CheckBox checkBox = (CheckBox) event.getSource();
                if (checkBox.getValue()) {
                    selectedScopes.add(scope.getKey());
                } else {
                    selectedScopes.remove(scope.getKey());
                }
            }
        });

        // Enable the check box if the scope is selected.
        scopeToggle.setValue(selectedScopes.contains(scope.getKey()));
    }

    // Process any scopes that are extra.
    for (TextBox editor : oldEditors) {
        if (!editor.getValue().trim().isEmpty()) {
            addFreeFormEditorRow(editor.getValue(), true);
        }
    }

    // There should always be one empty editor.
    addFreeFormEditorRow("", false);
}

From source file:com.google.developers.gdgfirenze.admin.client.cell.SampleCell.java

License:Apache License

@Override
public void render(Context context, AbstractSample sample, SafeHtmlBuilder sb) {
    // Value can be null, so do a null check..
    if (sample == null) {
        return;//  w w  w  . j a  v a  2 s. c o  m
    }
    sb.appendHtmlConstant("<table><tr><td colspan=\"2\"><strong>");
    if (sample.getType() != null) {
        final ResourcePrototype icon = ICON_BUNDLE.getResource(findIconName(sample.getType()));
        if (icon != null) {
            final Image image = new Image((ImageResource) icon);
            image.setTitle(sample.getType());
            sb.appendHtmlConstant(image.toString());
        } else {
            sb.appendEscaped(sample.getType());
        }
    }
    sb.appendEscaped(sample.getTime().toString());
    sb.appendHtmlConstant("</strong></td></tr>");
    if (sample instanceof NumericValueSample) {
        final NumericValueSample numericValueSample = (NumericValueSample) sample;
        sb.appendHtmlConstant(getTableRow("Value", numericValueSample.getValue()));
    } else if (sample instanceof StringValueSample) {
        final StringValueSample stringValueSample = (StringValueSample) sample;
        sb.appendHtmlConstant(getTableRow("Value", stringValueSample.getValue()));
    } else if (sample instanceof StringValueSample) {
        final StringValueSample stringValueSample = (StringValueSample) sample;
        sb.appendHtmlConstant("<tr><td>Value: </td><td>");
        sb.appendEscaped(stringValueSample.getValue());
        sb.appendHtmlConstant("</td><td>");
    } else if (sample instanceof PositionSample) {
        final PositionSample positionSample = (PositionSample) sample;
        sb.appendHtmlConstant(getTableRow("Latitude,Longitude", fromDoubleToString(positionSample.getLat())
                + "," + fromDoubleToString(positionSample.getLng())));
        sb.appendHtmlConstant(getTableRow("Altitude", positionSample.getAlt()));
        sb.appendHtmlConstant(getTableRow("Bearing", positionSample.getBearing()));
        sb.appendHtmlConstant(getTableRow("Speed", positionSample.getSpeed()));
        sb.appendHtmlConstant(getTableRow("Accuracy", positionSample.getAccuracy()));
    } else if (sample instanceof WifiSignalSample) {
        final WifiSignalSample wifiSignalSample = (WifiSignalSample) sample;
        sb.appendHtmlConstant(getTableRow("Frequency", wifiSignalSample.getFrequency()));
        sb.appendHtmlConstant(getTableRow("Level", wifiSignalSample.getLevel()));
        sb.appendHtmlConstant(getTableRow("BSSID", wifiSignalSample.getBssid()));
        sb.appendHtmlConstant(getTableRow("SSID", wifiSignalSample.getSsid()));
        sb.appendHtmlConstant(getTableRow("Capabilities", wifiSignalSample.getCapabilities()));
    }
    sb.appendHtmlConstant("</table>");
}

From source file:com.google.developers.gdgfirenze.admin.client.cell.SensorCell.java

License:Apache License

@Override
public void render(Context context, Sensor sensor, SafeHtmlBuilder sb) {

    // Value can be null, so do a null check..
    if (sensor == null) {
        return;//from w w  w .j a  va2s.c om
    }

    sb.appendHtmlConstant("<table><tr><td title=\"" + sensor.getId() + "\"><strong>");
    sb.appendEscaped(sensor.getName());
    sb.appendHtmlConstant("</strong>");
    if (sensor.getType() != null) {
        sb.appendHtmlConstant("</td><td>");
        final ResourcePrototype icon = ICON_BUNDLE.getResource(findIconName(sensor.getType()));
        if (icon != null) {
            final Image image = new Image((ImageResource) icon);
            image.setTitle(sensor.getType());
            sb.appendHtmlConstant(image.toString());
        } else {
            sb.appendEscaped(sensor.getType());
        }
    }
    sb.appendHtmlConstant("</td></tr><tr><td style=\"font-size:0.9em;\">");
    sb.appendEscaped(sensor.getDescription());
    if (sensor.getLastSeen() != null || sensor.getLat() != null) {
        sb.appendHtmlConstant("</td></tr><tr><td style=\"font-size:0.9em;\"><dl>");
        if (sensor.getLastSeen() != null) {
            sb.appendHtmlConstant("<dt>Last Seen:</dt><dd>");
            sb.appendEscaped(df.format(sensor.getLastSeen()));
            sb.appendHtmlConstant("</dd>");
        }

        if (sensor.getLat() != null) {
            sb.appendHtmlConstant("<dt>Position:</dt><dd>");
            sb.appendEscaped(sensor.getLat() + "," + sensor.getLng());
            sb.appendHtmlConstant("</dd>");
        }
        sb.appendHtmlConstant("</dl>");
    }

    sb.appendHtmlConstant("</td></td></table>");
}

From source file:com.google.gerrit.client.ui.HighlightSuggestion.java

License:Apache License

@Override
public String getDisplayString() {
    int start = 0;
    int keyLen = keyword.length();
    SafeHtmlBuilder builder = new SafeHtmlBuilder();
    for (;;) {//from   w w  w.  j  a v a2s .  co m
        int index = value.indexOf(keyword, start);
        if (index == -1) {
            builder.appendEscaped(value.substring(start));
            break;
        }
        builder.appendEscaped(value.substring(start, index));
        builder.appendHtmlConstant("<strong>");
        start = index + keyLen;
        builder.appendEscaped(value.substring(index, start));
        builder.appendHtmlConstant("</strong>");
    }
    return builder.toSafeHtml().asString();
}

From source file:com.google.gwt.sample.expenses.client.MobileReportList.java

License:Apache License

public MobileReportList(final Listener listener, final ExpensesRequestFactory requestFactory,
        EmployeeProxy employee) {//from  ww  w  .j  a  va2 s  .c  om
    this.listener = listener;
    this.requestFactory = requestFactory;
    this.employee = employee;

    EntityProxyKeyProvider<ReportProxy> keyProvider = new EntityProxyKeyProvider<ReportProxy>();

    reportDataProvider = new AsyncDataProvider<ReportProxy>(keyProvider) {
        @Override
        protected void onRangeChanged(HasData<ReportProxy> view) {
            requestReports();
        }
    };

    reportList = new CellList<ReportProxy>(new AbstractCell<ReportProxy>() {
        @Override
        public void render(Context context, ReportProxy value, SafeHtmlBuilder sb) {
            sb.appendHtmlConstant("<div class='item'>");
            sb.appendEscaped(value.getPurpose());
            sb.appendHtmlConstant("</div>");
        }
    });
    reportList.setKeyboardSelectionPolicy(KeyboardSelectionPolicy.DISABLED);

    reportSelection = new NoSelectionModel<ReportProxy>(keyProvider);
    reportSelection.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
        public void onSelectionChange(SelectionChangeEvent event) {
            listener.onReportSelected(reportSelection.getLastSelectedObject());
        }
    });

    reportList.setSelectionModel(reportSelection);
    reportDataProvider.addDataDisplay(reportList);

    initWidget(reportList);
    onRefresh(false);
}

From source file:com.google.gwt.sample.showcase.client.content.lists.CwStackLayoutPanel.java

License:Apache License

/**
 * Add a {@link TreeItem} to a root item.
 * /*from   w w  w . j a  v a2  s  .c o  m*/
 * @param root the root {@link TreeItem}
 * @param image the icon for the new child item
 * @param label the label for the child icon
 */
@ShowcaseSource
private void addItem(TreeItem root, ImageResource image, String label) {
    SafeHtmlBuilder sb = new SafeHtmlBuilder();
    sb.append(SafeHtmlUtils.fromTrustedString(AbstractImagePrototype.create(image).getHTML()));
    sb.appendEscaped(" ").appendEscaped(label);
    root.addItem(sb.toSafeHtml());
}