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

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

Introduction

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

Prototype

public static SafeHtml fromString(String s) 

Source Link

Document

Returns a SafeHtml containing the escaped string.

Usage

From source file:org.opendatakit.aggregate.client.PreferencesSubTab.java

License:Apache License

private void setCredentialValues() {
    String value;/*from  ww  w  .  j a  v a2 s.  co m*/
    String enketoValue;

    value = SafeHtmlUtils.fromString(Preferences.getGoogleSimpleApiKey()).asString();
    if (value.length() == 0) {
        value = "undefined";
        simpleApiKey.setStyleName(UNDEFINED_STYLE, true);
        simpleApiKey.setStyleName(DEFINED_STYLE, false);
    } else {
        simpleApiKey.setStyleName(UNDEFINED_STYLE, false);
        simpleApiKey.setStyleName(DEFINED_STYLE, true);
    }
    simpleApiKey.setText(value);

    value = SafeHtmlUtils.fromString(Preferences.getGoogleApiClientId()).asString();
    if (value.length() == 0) {
        value = "undefined";
        googleApiClientId.setStyleName(UNDEFINED_STYLE, true);
        googleApiClientId.setStyleName(DEFINED_STYLE, false);
    } else {
        googleApiClientId.setStyleName(UNDEFINED_STYLE, false);
        googleApiClientId.setStyleName(DEFINED_STYLE, true);
    }
    googleApiClientId.setText(value);

    enketoValue = SafeHtmlUtils.fromString(Preferences.getEnketoApiUrl()).asString();
    if (enketoValue.length() == 0) {
        enketoValue = "undefined";

        enketoApiUrl.setStyleName(UNDEFINED_STYLE, true);
        enketoApiUrl.setStyleName(DEFINED_STYLE, false);
    } else {

        enketoApiUrl.setStyleName(UNDEFINED_STYLE, false);
        enketoApiUrl.setStyleName(DEFINED_STYLE, true);
    }
    enketoApiUrl.setText(enketoValue);

    enketoValue = SafeHtmlUtils.fromString(Preferences.getEnketoApiToken()).asString();
    if (enketoValue.length() == 0) {
        enketoValue = "undefined";

        enketoApiToken.setStyleName(UNDEFINED_STYLE, true);
        enketoApiToken.setStyleName(DEFINED_STYLE, false);
    } else {

        enketoApiToken.setStyleName(UNDEFINED_STYLE, false);
        enketoApiToken.setStyleName(DEFINED_STYLE, true);
    }
    enketoApiToken.setText(enketoValue);
}

From source file:org.opendatakit.common.web.client.UIEnabledActionCell.java

License:Apache License

public UIEnabledActionCell(String text, UIEnabledPredicate<T> isEnabledPredicate,
        UIEnabledActionCell.Delegate<T> delegate) {
    this(SafeHtmlUtils.fromString(text), null, isEnabledPredicate, delegate);
}

From source file:org.opendatakit.common.web.client.UIEnabledActionCell.java

License:Apache License

public UIEnabledActionCell(String text, UIVisiblePredicate<T> isVisiblePredicate,
        UIEnabledActionCell.Delegate<T> delegate) {
    this(SafeHtmlUtils.fromString(text), isVisiblePredicate, null, delegate);
}

From source file:org.opendatakit.common.web.client.UIEnabledActionCell.java

License:Apache License

public UIEnabledActionCell(String text, UIVisiblePredicate<T> isVisiblePredicate,
        UIEnabledPredicate<T> isEnabledPredicate, UIEnabledActionCell.Delegate<T> delegate) {
    this(SafeHtmlUtils.fromString(text), isVisiblePredicate, isEnabledPredicate, delegate);
}

From source file:org.roda.wui.client.browse.BitstreamPreview.java

private void errorPreview(String errorPreview) {
    HTML html = new HTML();
    SafeHtmlBuilder b = new SafeHtmlBuilder();

    b.append(SafeHtmlUtils.fromSafeConstant("<i class='fa fa-download fa-5'></i>"));
    b.append(SafeHtmlUtils.fromSafeConstant("<h4 class='errormessage'>"));
    b.append(SafeHtmlUtils.fromString(errorPreview));
    b.append(SafeHtmlUtils.fromSafeConstant("</h4>"));

    Button downloadButton = new Button(messages.viewRepresentationDownloadFileButton());
    downloadButton.addClickHandler(new ClickHandler() {

        @Override/*  ww  w  .  j  a v  a  2  s.  c  o m*/
        public void onClick(ClickEvent event) {
            downloadFile();
        }
    });

    html.setHTML(b.toSafeHtml());
    panel.add(html);
    panel.add(downloadButton);
    html.setStyleName("viewRepresentationErrorPreview");
    downloadButton.setStyleName("btn btn-donwload viewRepresentationNotSupportedDownloadButton");

    onPreviewFailure.execute();
}

From source file:org.roda.wui.client.browse.BitstreamPreview.java

private void notSupportedPreview() {
    HTML html = new HTML();
    SafeHtmlBuilder b = new SafeHtmlBuilder();

    b.append(SafeHtmlUtils.fromSafeConstant("<i class='fa fa-picture-o fa-5'></i>"));
    b.append(SafeHtmlUtils.fromSafeConstant("<h4 class='errormessage'>"));
    b.append(SafeHtmlUtils.fromString(messages.viewRepresentationNotSupportedPreview()));
    b.append(SafeHtmlUtils.fromSafeConstant("</h4>"));

    Button downloadButton = new Button(messages.viewRepresentationDownloadFileButton());
    downloadButton.addClickHandler(new ClickHandler() {

        @Override//  w  w  w .j  a  v a  2 s  .co m
        public void onClick(ClickEvent event) {
            downloadFile();
        }
    });

    html.setHTML(b.toSafeHtml());
    panel.add(html);
    panel.add(downloadButton);
    html.setStyleName("viewRepresentationNotSupportedPreview");
    downloadButton.setStyleName("btn btn-download viewRepresentationNotSupportedDownloadButton");

    onPreviewFailure.execute();

}

From source file:org.roda.wui.client.browse.BitstreamPreview.java

protected Widget directoryPreview() {
    HTML html = new HTML();
    SafeHtmlBuilder b = new SafeHtmlBuilder();

    b.append(SafeHtmlUtils.fromSafeConstant("<i class='fa fa-folder-open fa-5'></i>"));
    b.append(SafeHtmlUtils.fromSafeConstant("<h4 class='emptymessage'>"));
    b.append(SafeHtmlUtils.fromString(filename + " /"));
    b.append(SafeHtmlUtils.fromSafeConstant("</h4>"));

    html.setHTML(b.toSafeHtml());/*w ww. j a v  a  2s  .  c  o m*/
    html.setStyleName("viewRepresentationEmptyPreview");
    return html;
}

From source file:org.roda.wui.client.browse.BrowseAIP.java

private void getDescriptiveMetadataHTML(final String aipId, final String descId,
        final DescriptiveMetadataViewBundle bundle, final AsyncCallback<SafeHtml> callback) {
    SafeUri uri = RestUtils.createDescriptiveMetadataHTMLUri(aipId, descId);
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, uri.asString());
    requestBuilder.setHeader("Authorization", "Custom");
    try {//from  w ww. j av  a  2  s . co m
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                String escapedDescId = SafeHtmlUtils.htmlEscape(descId);

                if (200 == response.getStatusCode()) {
                    String html = response.getText();

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataLinks'>"));

                    if (bundle.hasHistory()) {
                        // History link
                        String historyLink = HistoryUtils.createHistoryHashLink(
                                DescriptiveMetadataHistory.RESOLVER, aipId, escapedDescId);
                        String historyLinkHtml = "<a href='" + historyLink
                                + "' class='toolbarLink'><i class='fa fa-history'></i></a>";
                        b.append(SafeHtmlUtils.fromSafeConstant(historyLinkHtml));
                    }

                    // Edit link
                    String editLink = HistoryUtils.createHistoryHashLink(EditDescriptiveMetadata.RESOLVER,
                            aipId, escapedDescId);
                    String editLinkHtml = "<a href='" + editLink
                            + "' class='toolbarLink'><i class='fa fa-edit'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(editLinkHtml));

                    // Download link
                    SafeUri downloadUri = RestUtils.createDescriptiveMetadataDownloadUri(aipId, escapedDescId);
                    String downloadLinkHtml = "<a href='" + downloadUri.asString()
                            + "' class='toolbarLink'><i class='fa fa-download'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(downloadLinkHtml));

                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataHTML'>"));
                    b.append(SafeHtmlUtils.fromTrustedString(html));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));
                    SafeHtml safeHtml = b.toSafeHtml();

                    callback.onSuccess(safeHtml);
                } else {
                    String text = response.getText();
                    String message;
                    try {
                        RestErrorOverlayType error = (RestErrorOverlayType) JsonUtils.safeEval(text);
                        message = error.getMessage();
                    } catch (IllegalArgumentException e) {
                        message = text;
                    }

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataLinks'>"));

                    if (bundle.hasHistory()) {
                        // History link
                        String historyLink = HistoryUtils.createHistoryHashLink(
                                DescriptiveMetadataHistory.RESOLVER, aipId, escapedDescId);
                        String historyLinkHtml = "<a href='" + historyLink
                                + "' class='toolbarLink'><i class='fa fa-history'></i></a>";
                        b.append(SafeHtmlUtils.fromSafeConstant(historyLinkHtml));
                    }

                    // Edit link
                    String editLink = HistoryUtils.createHistoryHashLink(EditDescriptiveMetadata.RESOLVER,
                            aipId, escapedDescId);
                    String editLinkHtml = "<a href='" + editLink
                            + "' class='toolbarLink'><i class='fa fa-edit'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(editLinkHtml));

                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    // error message
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='error'>"));
                    b.append(messages.descriptiveMetadataTransformToHTMLError());
                    b.append(SafeHtmlUtils.fromSafeConstant("<pre><code>"));
                    b.append(SafeHtmlUtils.fromString(message));
                    b.append(SafeHtmlUtils.fromSafeConstant("</core></pre>"));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    callback.onSuccess(b.toSafeHtml());
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
    } catch (RequestException e) {
        callback.onFailure(e);
    }
}

From source file:org.roda.wui.client.browse.BrowseRepresentation.java

private void getDescriptiveMetadataHTML(final String descId, final DescriptiveMetadataViewBundle bundle,
        final AsyncCallback<SafeHtml> callback) {
    SafeUri uri = RestUtils.createRepresentationDescriptiveMetadataHTMLUri(aipId, repId, descId);
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, uri.asString());
    requestBuilder.setHeader("Authorization", "Custom");
    try {/*from   www.  j  av  a2 s  .co m*/
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    String html = response.getText();

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataLinks'>"));

                    if (bundle.hasHistory()) {
                        // History link
                        String historyLink = HistoryUtils.createHistoryHashLink(
                                DescriptiveMetadataHistory.RESOLVER, aipId, repId, descId);
                        String historyLinkHtml = "<a href='" + historyLink
                                + "' class='toolbarLink'><i class='fa fa-history'></i></a>";
                        b.append(SafeHtmlUtils.fromSafeConstant(historyLinkHtml));
                    }
                    // Edit link
                    String editLink = HistoryUtils.createHistoryHashLink(EditDescriptiveMetadata.RESOLVER,
                            aipId, repId, descId);
                    String editLinkHtml = "<a href='" + editLink
                            + "' class='toolbarLink'><i class='fa fa-edit'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(editLinkHtml));

                    // Download link
                    SafeUri downloadUri = RestUtils.createRepresentationDescriptiveMetadataDownloadUri(aipId,
                            repId, descId);
                    String downloadLinkHtml = "<a href='" + downloadUri.asString()
                            + "' class='toolbarLink'><i class='fa fa-download'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(downloadLinkHtml));

                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataHTML'>"));
                    b.append(SafeHtmlUtils.fromTrustedString(html));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));
                    SafeHtml safeHtml = b.toSafeHtml();

                    callback.onSuccess(safeHtml);
                } else {
                    String text = response.getText();
                    String message;
                    try {
                        RestErrorOverlayType error = (RestErrorOverlayType) JsonUtils.safeEval(text);
                        message = error.getMessage();
                    } catch (IllegalArgumentException e) {
                        message = text;
                    }

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataLinks'>"));

                    if (bundle.hasHistory()) {
                        // History link
                        String historyLink = HistoryUtils.createHistoryHashLink(
                                DescriptiveMetadataHistory.RESOLVER, aipId, repId, descId);
                        String historyLinkHtml = "<a href='" + historyLink
                                + "' class='toolbarLink'><i class='fa fa-history'></i></a>";
                        b.append(SafeHtmlUtils.fromSafeConstant(historyLinkHtml));
                    }

                    // Edit link
                    String editLink = HistoryUtils.createHistoryHashLink(EditDescriptiveMetadata.RESOLVER,
                            aipId, repId, descId);
                    String editLinkHtml = "<a href='" + editLink
                            + "' class='toolbarLink'><i class='fa fa-edit'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(editLinkHtml));

                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    // error message
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='error'>"));
                    b.append(messages.descriptiveMetadataTransformToHTMLError());
                    b.append(SafeHtmlUtils.fromSafeConstant("<pre><code>"));
                    b.append(SafeHtmlUtils.fromString(message));
                    b.append(SafeHtmlUtils.fromSafeConstant("</core></pre>"));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    callback.onSuccess(b.toSafeHtml());
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
    } catch (RequestException e) {
        callback.onFailure(e);
    }
}

From source file:org.roda.wui.client.browse.DescriptiveMetadataHistory.java

private void getDescriptiveMetadata(final String aipId, final String representationId, final String descId,
        final String versionKey, final boolean inHTML, final AsyncCallback<SafeHtml> callback) {

    SafeUri uri;/*from ww  w  .  j  av  a 2 s.co  m*/
    if (inHTML) {
        if (representationId != null) {
            uri = RestUtils.createRepresentationDescriptiveMetadataHTMLUri(aipId, representationId, descId,
                    versionKey);
        } else {
            uri = RestUtils.createDescriptiveMetadataHTMLUri(aipId, descId, versionKey);
        }
    } else {
        if (representationId != null) {
            uri = RestUtils.createRepresentationDescriptiveMetadataDownloadUri(aipId, representationId, descId,
                    versionKey);
        } else {
            uri = RestUtils.createDescriptiveMetadataDownloadUri(aipId, descId, versionKey);
        }
    }
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, uri.asString());
    requestBuilder.setHeader("Authorization", "Custom");
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    String text = response.getText();

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    if (inHTML) {
                        b.append(SafeHtmlUtils.fromTrustedString(text));
                    } else {
                        b.append(SafeHtmlUtils.fromString(text));
                    }
                    SafeHtml safeHtml = b.toSafeHtml();

                    callback.onSuccess(safeHtml);
                } else {
                    String text = response.getText();
                    String message;
                    try {
                        RestErrorOverlayType error = (RestErrorOverlayType) JsonUtils.safeEval(text);
                        message = error.getMessage();
                    } catch (IllegalArgumentException e) {
                        message = text;
                    }

                    SafeHtmlBuilder b = new SafeHtmlBuilder();

                    // error message
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='error'>"));
                    b.append(messages.descriptiveMetadataTransformToHTMLError());
                    b.append(SafeHtmlUtils.fromSafeConstant("<pre><code>"));
                    b.append(SafeHtmlUtils.fromString(message));
                    b.append(SafeHtmlUtils.fromSafeConstant("</core></pre>"));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    callback.onSuccess(b.toSafeHtml());
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
    } catch (

    RequestException e)

    {
        callback.onFailure(e);
    }

}