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

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

Introduction

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

Prototype

public SafeHtmlBuilder append(SafeHtml html) 

Source Link

Document

Appends the contents of another SafeHtml object, without applying HTML-escaping to it.

Usage

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

private void audioPreview() {
    Audio audioPlayer = Audio.createIfSupported();
    if (audioPlayer != null) {
        HTML html = new HTML();
        SafeHtmlBuilder b = new SafeHtmlBuilder();
        b.append(SafeHtmlUtils.fromSafeConstant("<i class='fa fa-headphones fa-5'></i>"));
        html.setHTML(b.toSafeHtml());// w w w .ja va 2 s. c o m

        // TODO check if audio source type needs to be transformed
        // TODO check if audio player supports provided file format
        audioPlayer.addSource(bitstreamDownloadUri.asString(), getAudioSourceType());
        audioPlayer.setControls(true);
        panel.add(html);
        panel.add(audioPlayer);
        audioPlayer.addStyleName("viewRepresentationAudioFilePreview");
        html.addStyleName("viewRepresentationAudioFilePreviewHTML");
    } else {
        notSupportedPreview();
    }
}

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/*from w w w. java 2s  .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 av a  2 s  .c om
        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());/*from  w w w. ja 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  w w  .j  a v a 2  s .  c o  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 {//  w  w  w . j  a  v  a 2  s  .  c o 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.CreateDescriptiveMetadata.java

protected void updateErrors(ValidationException e) {
    SafeHtmlBuilder b = new SafeHtmlBuilder();
    for (ValidationIssue issue : e.getReport().getIssues()) {
        b.append(SafeHtmlUtils.fromSafeConstant("<span class='error'>"));
        b.append(messages.metadataParseError(issue.getLineNumber(), issue.getColumnNumber(),
                issue.getMessage()));//from w  w w  .ja v a  2s  .c  om
        b.append(SafeHtmlUtils.fromSafeConstant("</span>"));

    }

    errors.setHTML(b.toSafeHtml());
    errors.setVisible(true);
}

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;/*ww w.  j ava  2 s .  c o 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);
    }

}

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

private void getEventDetailsHTML(final AsyncCallback<SafeHtml> callback) {
    IndexedPreservationEvent event = bundle.getEvent();
    SafeUri uri = RestUtils.createPreservationEventDetailsHTMLUri(eventId, event.getAipID(),
            event.getRepresentationUUID(), event.getFileUUID());
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, uri.asString());
    requestBuilder.setHeader("Authorization", "Custom");
    try {/* ww w .ja v  a  2 s  .  c om*/
        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='eventHTML'>"));
                    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();

                    // error message
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='error'>"));
                    b.append(messages.preservationEventDetailsTransformToHTMLError());
                    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.common.lists.JobList.java

@Override
protected void configureDisplay(CellTable<Job> display) {

    nameColumn = new TooltipTextColumn<Job>() {

        @Override/*  w ww.  j  a  v a  2s  . co m*/
        public String getValue(Job job) {
            return job != null ? job.getName() : null;
        }
    };

    usernameColumn = new TextColumn<Job>() {

        @Override
        public String getValue(Job job) {
            return job != null ? job.getUsername() : null;
        }
    };

    startDateColumn = new Column<Job, Date>(
            new DateCell(DateTimeFormat.getFormat(RodaConstants.DEFAULT_DATETIME_FORMAT))) {
        @Override
        public Date getValue(Job job) {
            return job != null ? job.getStartDate() : null;
        }
    };

    durationColumn = new TextColumn<Job>() {

        @Override
        public String getValue(Job job) {
            if (job == null) {
                return null;
            }
            Date end = job.getEndDate() != null ? job.getEndDate() : getDate();
            return Humanize.durationInDHMS(job.getStartDate(), end, DHMSFormat.SHORT);
        }
    };

    statusColumn = new Column<Job, SafeHtml>(new SafeHtmlCell()) {
        @Override
        public SafeHtml getValue(Job job) {
            return HtmlSnippetUtils.getJobStateHtml(job);
        }
    };

    objectsTotalCountColumn = new TextColumn<Job>() {

        @Override
        public String getValue(Job job) {
            String ret = "";
            if (job != null && job.getJobStats().getSourceObjectsCount() > 0) {
                ret = Integer.toString(job.getJobStats().getSourceObjectsCount());
            }
            return ret;
        }
    };

    objectsSuccessCountColumn = new Column<Job, SafeHtml>(new SafeHtmlCell()) {

        @Override
        public SafeHtml getValue(Job job) {
            SafeHtmlBuilder b = new SafeHtmlBuilder();
            if (job != null) {
                b.append(job.getJobStats().getSourceObjectsProcessedWithSuccess() > 0
                        ? SafeHtmlUtils.fromSafeConstant("<span>")
                        : SafeHtmlUtils.fromSafeConstant("<span class='ingest-process-counter-0'>"));
                b.append(job.getJobStats().getSourceObjectsProcessedWithSuccess());
                b.append(SafeHtmlUtils.fromSafeConstant("</span>"));
            }
            return b.toSafeHtml();
        }
    };

    objectsFailureCountColumn = new Column<Job, SafeHtml>(new SafeHtmlCell()) {
        @Override
        public SafeHtml getValue(Job job) {
            SafeHtmlBuilder b = new SafeHtmlBuilder();
            if (job != null) {
                b.append(SafeHtmlUtils.fromSafeConstant("<span"));
                if (job.getJobStats().getSourceObjectsProcessedWithFailure() > 0) {
                    b.append(SafeHtmlUtils.fromSafeConstant(" class='ingest-process-failed-column'"));
                } else {
                    b.append(SafeHtmlUtils.fromSafeConstant(" class='ingest-process-counter-0'"));
                }
                b.append(SafeHtmlUtils.fromSafeConstant(">"));
                b.append(job.getJobStats().getSourceObjectsProcessedWithFailure());
                b.append(SafeHtmlUtils.fromSafeConstant("</span>"));
            }
            return b.toSafeHtml();
        }
    };

    progressColumn = new TextColumn<Job>() {
        @Override
        public String getValue(Job job) {
            return job != null ? job.getJobStats().getCompletionPercentage() + "%" : null;
        }
    };

    nameColumn.setSortable(true);
    usernameColumn.setSortable(true);
    startDateColumn.setSortable(true);
    statusColumn.setSortable(true);
    objectsTotalCountColumn.setSortable(true);
    objectsSuccessCountColumn.setSortable(true);
    objectsFailureCountColumn.setSortable(true);
    progressColumn.setSortable(true);

    addColumn(nameColumn, messages.jobName(), true, false);
    addColumn(usernameColumn, messages.jobCreator(), true, false);
    addColumn(startDateColumn, messages.jobStartDate(), true, false, 11);
    addColumn(durationColumn, messages.jobDuration(), true, true, 6);
    addColumn(statusColumn, messages.jobStatus(), true, false, 7);
    addColumn(progressColumn, messages.jobProgress(), true, true, 5);
    addColumn(objectsTotalCountColumn, messages.jobTotalCountMessage(), true, true, 5);
    addColumn(objectsSuccessCountColumn, messages.jobSuccessCountMessage(), true, true, 6);
    addColumn(objectsFailureCountColumn, messages.jobFailureCountMessage(), true, true, 5);

    // default sorting
    display.getColumnSortList().push(new ColumnSortInfo(startDateColumn, false));

}