List of usage examples for com.google.gwt.safehtml.shared SafeHtmlBuilder SafeHtmlBuilder
public SafeHtmlBuilder()
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 ww . j a v a 2 s . com 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 .ja va 2s.c om*/ 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 {//from www.j a v a 2 s. com 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/*from w w w.j a v a 2s . c o 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)); }
From source file:org.roda.wui.client.common.lists.SearchFileList.java
@Override protected void configureDisplay(CellTable<IndexedFile> display) { iconColumn = new Column<IndexedFile, SafeHtml>(new SafeHtmlCell()) { @Override/*from w ww. j ava 2 s. c o m*/ public SafeHtml getValue(IndexedFile file) { if (file != null) { if (file.isDirectory()) { return SafeHtmlUtils.fromSafeConstant("<i class='fa fa-folder-open'></i>"); } else { return SafeHtmlUtils.fromSafeConstant("<i class='fa fa-file-o'></i>"); } } else { logger.error("Trying to display a NULL item"); } return null; } }; pathColumn = new Column<IndexedFile, SafeHtml>(new SafeHtmlCell()) { @Override public SafeHtml getValue(IndexedFile file) { SafeHtmlBuilder b = new SafeHtmlBuilder(); if (file != null) { List<String> filePath = file.getPath(); String fileName = file.getOriginalName() != null ? file.getOriginalName() : file.getId(); List<String> fullpath = new ArrayList<>(filePath); fullpath.add(fileName); b.append(SafeHtmlUtils.fromSafeConstant("<div title='")); b.append(SafeHtmlUtils.fromString(StringUtils.join(fullpath, "/"))); b.append(SafeHtmlUtils.fromSafeConstant("'>")); if (showFilePath && filePath != null && !filePath.isEmpty()) { String path = StringUtils.join(filePath, "/"); b.append(SafeHtmlUtils.fromSafeConstant("<span class='file-path'>")); b.append(SafeHtmlUtils.fromString(path)); b.append(SafeHtmlUtils.fromSafeConstant("/")); b.append(SafeHtmlUtils.fromSafeConstant("</span>")); } b.append(SafeHtmlUtils.fromString(fileName)); b.append(SafeHtmlUtils.fromSafeConstant("</div>")); } return b.toSafeHtml(); } }; formatColumn = new TextColumn<IndexedFile>() { @Override public String getValue(IndexedFile file) { if (file != null && file.getFileFormat() != null) { FileFormat format = file.getFileFormat(); String ret; if (StringUtils.isNotBlank(format.getFormatDesignationName())) { ret = format.getFormatDesignationName(); if (StringUtils.isNotBlank(format.getFormatDesignationVersion())) { ret = ret + " " + format.getFormatDesignationVersion(); } } else if (StringUtils.isNotBlank(format.getPronom())) { ret = format.getPronom(); } else if (StringUtils.isNotBlank(format.getMimeType())) { ret = format.getMimeType(); } else { ret = null; } return ret; } else { return null; } } }; sizeColumn = new TextColumn<IndexedFile>() { @Override public String getValue(IndexedFile file) { return (file != null && file.getSize() > 0) ? Humanize.readableFileSize(file.getSize()) : ""; } }; /* add sortable */ iconColumn.setSortable(true); pathColumn.setSortable(true); formatColumn.setSortable(true); sizeColumn.setSortable(true); addColumn(iconColumn, SafeHtmlUtils.fromSafeConstant("<i class='fa fa-files-o'></i>"), false, false, 3); addColumn(pathColumn, messages.filePath(), true, false); addColumn(formatColumn, messages.fileFormat(), true, false); addColumn(sizeColumn, messages.fileSize(), true, false, 7); // define column width priority display.setColumnWidth(iconColumn, 3.0, Unit.EM); display.setColumnWidth(sizeColumn, 6.0, Unit.EM); pathColumn.setCellStyleNames("text-align-left"); formatColumn.setCellStyleNames("text-align-left"); sizeColumn.setCellStyleNames("text-align-right"); // define default sorting display.getColumnSortList().push(new ColumnSortInfo(pathColumn, true)); addStyleName("my-files-table"); }
From source file:org.roda.wui.client.common.slider.InfoSliderHelper.java
private static void updateInfoSliderPanel(IndexedFile file, SliderPanel infoSliderPanel) { HashMap<String, SafeHtml> values = new HashMap<>(); infoSliderPanel.clear();//from ww w . j av a 2s . co m infoSliderPanel.addTitle(new Label(messages.viewRepresentationInfoTitle())); if (file != null) { String fileName = file.getOriginalName() != null ? file.getOriginalName() : file.getId(); values.put(messages.viewRepresentationInfoFilename(), SafeHtmlUtils.fromString(fileName)); if (file.getSize() > 0) { values.put(messages.viewRepresentationInfoSize(), SafeHtmlUtils.fromString(Humanize.readableFileSize(file.getSize()))); } if (file.getFileFormat() != null) { FileFormat fileFormat = file.getFileFormat(); if (StringUtils.isNotBlank(fileFormat.getMimeType())) { values.put(messages.viewRepresentationInfoMimetype(), SafeHtmlUtils.fromString(fileFormat.getMimeType())); } if (StringUtils.isNotBlank(fileFormat.getFormatDesignationName())) { values.put(messages.viewRepresentationInfoFormat(), SafeHtmlUtils.fromString(fileFormat.getFormatDesignationName())); } if (StringUtils.isNotBlank(fileFormat.getFormatDesignationVersion())) { values.put(messages.viewRepresentationInfoFormatVersion(), SafeHtmlUtils.fromString(fileFormat.getFormatDesignationVersion())); } if (StringUtils.isNotBlank(fileFormat.getPronom())) { values.put(messages.viewRepresentationInfoPronom(), SafeHtmlUtils.fromString(fileFormat.getPronom())); } } if (StringUtils.isNotBlank(file.getCreatingApplicationName())) { values.put(messages.viewRepresentationInfoCreatingApplicationName(), SafeHtmlUtils.fromString(file.getCreatingApplicationName())); } if (StringUtils.isNotBlank(file.getCreatingApplicationVersion())) { values.put(messages.viewRepresentationInfoCreatingApplicationVersion(), SafeHtmlUtils.fromString(file.getCreatingApplicationVersion())); } if (StringUtils.isNotBlank(file.getDateCreatedByApplication())) { values.put(messages.viewRepresentationInfoDateCreatedByApplication(), SafeHtmlUtils.fromString(file.getDateCreatedByApplication())); } if (file.getHash() != null && !file.getHash().isEmpty()) { SafeHtmlBuilder b = new SafeHtmlBuilder(); boolean first = true; for (String hash : file.getHash()) { if (first) { first = false; } else { b.append(SafeHtmlUtils.fromSafeConstant("<br/>")); } b.append(SafeHtmlUtils.fromSafeConstant("<small>")); b.append(SafeHtmlUtils.fromString(hash)); b.append(SafeHtmlUtils.fromSafeConstant("</small>")); } values.put(messages.viewRepresentationInfoHash(), b.toSafeHtml()); } if (file.getStoragePath() != null) { SafeHtmlBuilder b = new SafeHtmlBuilder(); b.append(SafeHtmlUtils.fromSafeConstant("<small>")); b.append(SafeHtmlUtils.fromString(file.getStoragePath())); b.append(SafeHtmlUtils.fromSafeConstant("</small>")); values.put(messages.viewRepresentationInfoStoragePath(), b.toSafeHtml()); } } populate(infoSliderPanel, values); }
From source file:org.roda.wui.client.common.utils.HtmlSnippetUtils.java
public static SafeHtml getAIPStateHTML(AIPState aipState) { SafeHtmlBuilder b = new SafeHtmlBuilder(); switch (aipState) { case ACTIVE: b.append(SafeHtmlUtils.fromSafeConstant(OPEN_SPAN_CLASS_LABEL_SUCCESS)); break;//w w w .ja va2s . c o m case UNDER_APPRAISAL: b.append(SafeHtmlUtils.fromSafeConstant(OPEN_SPAN_CLASS_LABEL_WARNING)); break; default: b.append(SafeHtmlUtils.fromSafeConstant(OPEN_SPAN_CLASS_LABEL_DANGER)); break; } b.append(SafeHtmlUtils.fromString(messages.aipState(aipState))); b.append(SafeHtmlUtils.fromSafeConstant(CLOSE_SPAN)); return b.toSafeHtml(); }
From source file:org.roda.wui.client.common.utils.HtmlSnippetUtils.java
public static SafeHtml getRepresentationTypeHTML(String type, boolean isOriginal) { SafeHtmlBuilder b = new SafeHtmlBuilder(); b.append(SafeHtmlUtils.fromSafeConstant(OPEN_H4_CLASS_LABEL_SUCCESS)); b.append(SafeHtmlUtils.fromString(type)); b.append(SafeHtmlUtils.fromSafeConstant(CLOSE_SPAN)); b.append(SafeHtmlUtils.fromSafeConstant(OPEN_SPAN_ORIGINAL_LABEL_SUCCESS)); if (isOriginal) { b.append(SafeHtmlUtils.fromString(messages.originalRepresentation())); } else {/*from w w w . j av a 2 s . co m*/ b.append(SafeHtmlUtils.fromString(messages.alternativeRepresentation())); } b.append(SafeHtmlUtils.fromSafeConstant(CLOSE_SPAN)); return b.toSafeHtml(); }
From source file:org.roda.wui.client.ingest.process.ShowJob.java
private void update() { // set end date dateEndedLabel.setVisible(job.getEndDate() != null); dateEnded.setVisible(job.getEndDate() != null); if (job.getEndDate() != null) { dateEnded.setText(dateTimeFormat.format(job.getEndDate())); }/*from ww w .j a va2 s. co m*/ // set duration duration.setText(Humanize.durationInDHMS(job.getStartDate(), job.getEndDate(), DHMSFormat.LONG)); // set state status.setHTML(HtmlSnippetUtils.getJobStateHtml(job)); // set state details boolean hasStateDetails = StringUtils.isNotBlank(job.getStateDetails()); stateDetailsLabel.setVisible(hasStateDetails); stateDetailsValue.setVisible(hasStateDetails); if (hasStateDetails) { stateDetailsValue.setText(job.getStateDetails()); } // set counters SafeHtmlBuilder b = new SafeHtmlBuilder(); b.append(SafeHtmlUtils.fromSafeConstant("<span class='label-default'>")); b.append(messages.showJobProgressCompletionPercentage(job.getJobStats().getCompletionPercentage())); b.append(SafeHtmlUtils.fromSafeConstant("</span>")); if (job.getJobStats().getSourceObjectsCount() > 0) { b.append(SafeHtmlUtils.fromSafeConstant(" <span class='label-default'>")); b.append(messages.showJobProgressTotalCount(job.getJobStats().getSourceObjectsCount())); b.append(SafeHtmlUtils.fromSafeConstant("</span>")); } if (job.getJobStats().getSourceObjectsProcessedWithSuccess() > 0) { b.append(SafeHtmlUtils.fromSafeConstant(" <span class='label-success'>")); b.append(messages .showJobProgressSuccessfulCount(job.getJobStats().getSourceObjectsProcessedWithSuccess())); b.append(SafeHtmlUtils.fromSafeConstant("</span>")); } if (job.getJobStats().getSourceObjectsProcessedWithFailure() > 0) { b.append(SafeHtmlUtils.fromSafeConstant(" <span class='label-danger'>")); b.append(messages.showJobProgressFailedCount(job.getJobStats().getSourceObjectsProcessedWithFailure())); b.append(SafeHtmlUtils.fromSafeConstant("</span>")); } if (job.getJobStats().getSourceObjectsBeingProcessed() > 0) { b.append(SafeHtmlUtils.fromSafeConstant(" <span class='label-info'>")); b.append(messages.showJobProgressProcessingCount(job.getJobStats().getSourceObjectsBeingProcessed())); b.append(SafeHtmlUtils.fromSafeConstant("</span>")); } if (job.getJobStats().getSourceObjectsWaitingToBeProcessed() > 0) { b.append(SafeHtmlUtils.fromSafeConstant(" <span class='label-warning'>")); b.append( messages.showJobProgressWaitingCount(job.getJobStats().getSourceObjectsWaitingToBeProcessed())); b.append(SafeHtmlUtils.fromSafeConstant("</span>")); } progress.setHTML(b.toSafeHtml()); buttonStop.setText(messages.stopButton()); buttonStop.setVisible(!job.isInFinalState()); buttonStop.setEnabled(!job.isStopping()); buttonAppraisal.setText(messages.appraisalTitle() + " (" + job.getJobStats().getOutcomeObjectsWithManualIntervention() + ")"); buttonAppraisal.setVisible(job.getJobStats().getOutcomeObjectsWithManualIntervention() > 0); scheduleUpdateStatus(); }
From source file:org.roda.wui.client.main.BreadcrumbUtils.java
private static BreadcrumbItem getBreadcrumbItem(final IndexedDIP dip) { SafeHtmlBuilder b = new SafeHtmlBuilder(); // TODO get icon from config b.append(SafeHtmlUtils.fromSafeConstant("<i class='fa fa-play-circle-o'></i>")); b.append(SafeHtmlUtils.fromString(dip.getTitle())); SafeHtml label = b.toSafeHtml();/*from ww w. j a v a 2 s .c om*/ return new BreadcrumbItem(label, dip.getTitle(), new Command() { @Override public void execute() { HistoryUtils.openBrowse(dip); } }); }