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

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

Introduction

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

Prototype

public static SafeHtml fromSafeConstant(String s) 

Source Link

Document

Returns a SafeHtml constructed from a safe string, i.e., without escaping the string.

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());//from w w w.j  a  v  a 2s.  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 ww  . ja va2  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//from w  w w .  j a v a2  s  . c o  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());//ww  w . j a v  a 2  s.  com
    html.setStyleName("viewRepresentationEmptyPreview");
    return html;
}

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

private void updateSectionDescriptiveMetadata(BrowseAIPBundle bundle) {
    final List<Pair<String, HTML>> descriptiveMetadataContainers = new ArrayList<>();
    final Map<String, DescriptiveMetadataViewBundle> bundles = new HashMap<>();

    List<DescriptiveMetadataViewBundle> descMetadata = bundle.getDescriptiveMetadata();
    if (descMetadata != null) {
        for (DescriptiveMetadataViewBundle descMetadatum : descMetadata) {
            String title = descMetadatum.getLabel() != null ? descMetadatum.getLabel() : descMetadatum.getId();
            HTML container = new HTML();
            container.addStyleName("metadataContent");
            descriptiveMetadata.add(container, title);
            descriptiveMetadataContainers.add(Pair.of(descMetadatum.getId(), container));
            bundles.put(descMetadatum.getId(), descMetadatum);
        }//from ww w  . j  a  v a 2  s. c o m
    }

    HandlerRegistration tabHandler = descriptiveMetadata.addSelectionHandler(new SelectionHandler<Integer>() {

        @Override
        public void onSelection(SelectionEvent<Integer> event) {
            if (event.getSelectedItem() < descriptiveMetadataContainers.size()) {
                Pair<String, HTML> pair = descriptiveMetadataContainers.get(event.getSelectedItem());
                String descId = pair.getFirst();
                final HTML html = pair.getSecond();
                final DescriptiveMetadataViewBundle descBundle = bundles.get(descId);
                if (html.getText().length() == 0) {
                    getDescriptiveMetadataHTML(aipId, descId, descBundle, new AsyncCallback<SafeHtml>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            if (!AsyncCallbackUtils.treatCommonFailures(caught)) {
                                Toast.showError(messages.errorLoadingDescriptiveMetadata(caught.getMessage()));
                            }
                        }

                        @Override
                        public void onSuccess(SafeHtml result) {
                            html.setHTML(result);
                        }
                    });
                }
            }
        }
    });

    final int addTabIndex = descriptiveMetadata.getWidgetCount();
    FlowPanel addTab = new FlowPanel();
    addTab.add(new HTML(SafeHtmlUtils.fromSafeConstant("<i class=\"fa fa-plus-circle\"></i>")));
    descriptiveMetadata.add(new Label(), addTab);
    HandlerRegistration addTabHandler = descriptiveMetadata
            .addSelectionHandler(new SelectionHandler<Integer>() {
                @Override
                public void onSelection(SelectionEvent<Integer> event) {
                    if (event.getSelectedItem() == addTabIndex) {
                        newDescriptiveMetadataRedirect();
                    }
                }
            });
    addTab.addStyleName("addTab");
    addTab.getParent().addStyleName("addTabWrapper");

    handlers.add(tabHandler);
    handlers.add(addTabHandler);

    if (descMetadata != null && !descMetadata.isEmpty()) {
        descriptiveMetadata.setVisible(true);
        descriptiveMetadata.selectTab(0);
    } else {
        newDescriptiveMetadata.setVisible(true);
    }

    WCAGUtilities.getInstance().makeAccessible(descriptiveMetadata.getElement());
}

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 .  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

public BrowseRepresentation(BrowseRepresentationBundle bundle) {
    this.representation = bundle.getRepresentation();

    this.aipId = representation.getAipId();
    this.repId = representation.getId();
    this.repUUID = representation.getUUID();

    handlers = new ArrayList<>();
    String summary = messages.representationListOfFiles();

    AIPState state = bundle.getAip().getState();
    boolean justActive = AIPState.ACTIVE.equals(state);
    boolean selectable = true;
    boolean showFilesPath = false;

    // FILES//from  ww w . j  a v  a  2s  .c  o m

    Filter filter = new Filter(new SimpleFilterParameter(RodaConstants.FILE_REPRESENTATION_UUID, repUUID),
            new EmptyKeyFilterParameter(RodaConstants.FILE_PARENT_UUID));

    filesList = new SearchFileList(filter, justActive, Facets.NONE, summary, selectable, showFilesPath);
    LastSelectedItemsSingleton.getInstance().setSelectedJustActive(justActive);
    filesList.setActionable(FileActions.get(aipId, repId));

    ListSelectionUtils.bindBrowseOpener(filesList);

    filesSearch = new SearchPanel(filter, ALL_FILTER, true, messages.searchPlaceHolder(), false, false, true);
    filesSearch.setList(filesList);

    // DISSEMINATIONS
    disseminationsList = new DIPList(Filter.NULL, Facets.NONE, messages.listOfDisseminations(), true);
    disseminationsList.setActionable(DisseminationActions.get());
    ListSelectionUtils.bindBrowseOpener(disseminationsList);

    disseminationsSearch = new SearchPanel(Filter.NULL, RodaConstants.DIP_SEARCH, true,
            messages.searchPlaceHolder(), false, false, true);
    disseminationsSearch.setList(disseminationsList);

    // INIT
    initWidget(uiBinder.createAndBindUi(this));

    // STATUS
    aipState.setHTML(HtmlSnippetUtils.getAIPStateHTML(state));
    aipState.setVisible(!justActive);

    // IDENTIFICATION

    HTMLPanel representationIconHtmlPanel = new HTMLPanel(
            DescriptionLevelUtils.getRepresentationTypeIcon(representation.getType(), false));
    representationIconHtmlPanel.addStyleName("browseItemIcon-other");
    representationIcon.setWidget(representationIconHtmlPanel);

    String type = representation.getType() != null ? representation.getType() : representation.getId();
    representationType.setHTML(HtmlSnippetUtils.getRepresentationTypeHTML(type, representation.isOriginal()));
    representationId.setText(representation.getId());

    breadcrumb.updatePath(BreadcrumbUtils.getRepresentationBreadcrumbs(bundle));
    breadcrumb.setVisible(true);

    // DESCRIPTIVE METADATA

    final List<Pair<String, HTML>> descriptiveMetadataContainers = new ArrayList<>();
    final Map<String, DescriptiveMetadataViewBundle> bundles = new HashMap<>();
    for (DescriptiveMetadataViewBundle descMetadataBundle : bundle.getRepresentationDescriptiveMetadata()) {
        String title = descMetadataBundle.getLabel() != null ? descMetadataBundle.getLabel()
                : descMetadataBundle.getId();
        HTML container = new HTML();
        container.addStyleName("metadataContent");
        itemMetadata.add(container, title);
        descriptiveMetadataContainers.add(Pair.of(descMetadataBundle.getId(), container));
        bundles.put(descMetadataBundle.getId(), descMetadataBundle);
    }

    HandlerRegistration tabHandler = itemMetadata.addSelectionHandler(new SelectionHandler<Integer>() {

        @Override
        public void onSelection(SelectionEvent<Integer> event) {
            if (event.getSelectedItem() < descriptiveMetadataContainers.size()) {
                Pair<String, HTML> pair = descriptiveMetadataContainers.get(event.getSelectedItem());
                String descId = pair.getFirst();
                final HTML html = pair.getSecond();
                final DescriptiveMetadataViewBundle bundle = bundles.get(descId);
                if (html.getText().length() == 0) {
                    getDescriptiveMetadataHTML(descId, bundle, new AsyncCallback<SafeHtml>() {

                        @Override
                        public void onFailure(Throwable caught) {
                            if (!AsyncCallbackUtils.treatCommonFailures(caught)) {
                                Toast.showError(messages.errorLoadingDescriptiveMetadata(caught.getMessage()));
                            }
                        }

                        @Override
                        public void onSuccess(SafeHtml result) {
                            html.setHTML(result);
                        }
                    });
                }
            }
        }
    });

    final int addTabIndex = itemMetadata.getWidgetCount();
    FlowPanel addTab = new FlowPanel();
    addTab.add(new HTML(SafeHtmlUtils.fromSafeConstant("<i class=\"fa fa-plus-circle\"></i>")));
    itemMetadata.add(new Label(), addTab);
    HandlerRegistration addTabHandler = itemMetadata.addSelectionHandler(new SelectionHandler<Integer>() {
        @Override
        public void onSelection(SelectionEvent<Integer> event) {
            if (event.getSelectedItem() == addTabIndex) {
                newRepresentationDescriptiveMetadata();
            }
        }
    });
    addTab.addStyleName("addTab");
    addTab.getParent().addStyleName("addTabWrapper");

    handlers.add(tabHandler);
    handlers.add(addTabHandler);

    if (!bundle.getRepresentationDescriptiveMetadata().isEmpty()) {
        newDescriptiveMetadata.setVisible(false);
        itemMetadata.setVisible(true);
        itemMetadata.selectTab(0);
    } else {
        newDescriptiveMetadata.setVisible(true);
        itemMetadata.setVisible(false);
    }

    // DISSEMINATIONS (POST-INIT)
    if (bundle.getDipCount() > 0) {
        Filter disseminationsFilter = new Filter(
                new SimpleFilterParameter(RodaConstants.DIP_REPRESENTATION_UUIDS, repUUID));
        disseminationsList.set(disseminationsFilter, state.equals(AIPState.ACTIVE), Facets.NONE);
        disseminationsSearch.setDefaultFilter(disseminationsFilter, true);
        disseminationsSearch.clearSearchInputBox();
    }
    disseminationsList.getParent().setVisible(bundle.getDipCount() > 0);

    // SIDEBAR
    actionsSidebar.setWidget(RepresentationActions.get(aipId).createActionsLayout(representation,
            new AsyncCallback<Actionable.ActionImpact>() {

                @Override
                public void onFailure(Throwable caught) {
                    AsyncCallbackUtils.defaultFailureTreatment(caught);
                }

                @Override
                public void onSuccess(Actionable.ActionImpact impact) {
                    if (Actionable.ActionImpact.UPDATED.equals(impact)) {
                        BrowserService.Util.getInstance().retrieve(IndexedRepresentation.class.getName(),
                                representation.getUUID(), representationFields,
                                new AsyncCallback<IndexedRepresentation>() {

                                    @Override
                                    public void onFailure(Throwable caught) {
                                        AsyncCallbackUtils.defaultFailureTreatment(caught);
                                    }

                                    @Override
                                    public void onSuccess(IndexedRepresentation rep) {
                                        representation = rep;
                                        representationType.setText(rep.getType());
                                    }
                                });
                    }
                }
            }));

    ListSelectionUtils.bindLayout(representation, searchPrevious, searchNext, keyboardFocus, true, false, false,
            searchSection);

    // CSS
    this.addStyleName("browse");
    this.addStyleName("browse-representation");
    this.addStyleName(state.toString().toLowerCase());

    Element firstElement = this.getElement().getFirstChildElement();
    if ("input".equalsIgnoreCase(firstElement.getTagName())) {
        firstElement.setAttribute("title", "browse input");
    }

    WCAGUtilities.getInstance().makeAccessible(itemMetadata.getElement());
}

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  a2  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

@UiHandler("buttonApply")
void buttonApplyHandler(ClickEvent e) {
    buttonApply.setEnabled(false);/*from  w ww.  j  a v  a  2  s .co  m*/
    String idText = id.getText();
    String typeText = selectedBundle != null ? selectedBundle.getType() : messages.otherItem(); // Other
    String typeVersion = selectedBundle != null ? selectedBundle.getVersion() : null;
    String template = selectedBundle != null ? selectedBundle.getTemplate() : null;
    String xmlText = metadataXML.getText();
    boolean hasOverridenTheForm = inXML && !xmlText.equals(metadataTextFromForm);

    if (idText.length() > 0) {
        Set<MetadataValue> values = null;
        // we only send the values map if the user hasn't overriden the form by
        // modifying the XML directly
        if (!hasOverridenTheForm && selectedBundle != null) {
            values = selectedBundle.getValues();
        }
        DescriptiveMetadataEditBundle newBundle = new DescriptiveMetadataEditBundle(idText, typeText,
                typeVersion, xmlText, template, values, true);

        BrowserService.Util.getInstance().createDescriptiveMetadataFile(aipId, representationId, newBundle,
                new AsyncCallback<Void>() {

                    @Override
                    public void onFailure(Throwable caught) {
                        if (caught instanceof ValidationException) {
                            ValidationException e = (ValidationException) caught;
                            updateErrors(e);
                            idError.setVisible(false);
                        } else if (caught instanceof AlreadyExistsException) {
                            idError.setVisible(true);
                            idError.setHTML(SafeHtmlUtils.fromSafeConstant(messages.fileAlreadyExists()));
                            errors.setVisible(false);
                        } else {
                            idError.setVisible(false);
                            AsyncCallbackUtils.defaultFailureTreatment(caught);
                        }
                        buttonApply.setEnabled(true);
                    }

                    @Override
                    public void onSuccess(Void result) {
                        errors.setText("");
                        errors.setVisible(false);
                        Toast.showInfo(messages.dialogSuccess(), messages.metadataFileCreated());
                        if (representationId == null) {
                            HistoryUtils.newHistory(BrowseAIP.RESOLVER, aipId);
                        } else {
                            HistoryUtils.newHistory(BrowseRepresentation.RESOLVER, aipId, representationId);
                        }
                    }
                });
    } else {
        Toast.showError("Please fill the mandatory fields");
        buttonApply.setEnabled(true);
    }

}

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  .  j  av a2s  .  c o m
        b.append(SafeHtmlUtils.fromSafeConstant("</span>"));

    }

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