use of com.haulmont.cuba.gui.export.ByteArrayDataProvider in project cuba by cuba-platform.
the class WebImage method createImageResource.
protected Resource createImageResource(final Object resourceObject) {
if (resourceObject == null) {
return null;
}
if (resourceObject instanceof FileDescriptor) {
FileDescriptorResource imageResource = createResource(FileDescriptorResource.class);
imageResource.setFileDescriptor((FileDescriptor) resourceObject);
return imageResource;
}
if (resourceObject instanceof byte[]) {
StreamResource imageResource = createResource(StreamResource.class);
Supplier<InputStream> streamSupplier = () -> new ByteArrayDataProvider((byte[]) resourceObject).provide();
imageResource.setStreamSupplier(streamSupplier);
return imageResource;
}
throw new GuiDevelopmentException("The Image component supports only FileDescriptor and byte[] datasource property value binding", getFrame().getId());
}
use of com.haulmont.cuba.gui.export.ByteArrayDataProvider in project cuba by cuba-platform.
the class CreditsFrame method exportLicenses.
public void exportLicenses() {
List<CreditsItem> items = new CreditsLoader().load().getItems();
Map<String, String> licenses = new TreeMap<>();
StringBuilder sb = new StringBuilder();
sb.append("<html><body>\n");
sb.append("<h1>Credits</h1>\n");
StringBuilder acknowledgements = new StringBuilder();
StringBuilder forks = new StringBuilder();
for (CreditsItem item : items) {
if (item.getAcknowledgement() != null)
acknowledgements.append("<p>").append(item.getAcknowledgement());
if (item.isFork())
forks.append("<li>").append(item.getName());
}
if (acknowledgements.length() > 0) {
sb.append("<h2>Acknowledgements</h2>\n");
sb.append(acknowledgements);
}
if (forks.length() > 0) {
sb.append("<h2>Forks and modifications</h2>\n");
sb.append("<p>The following libraries have been modified by Haulmont:");
sb.append("<ul>").append(forks).append("</ul>");
sb.append("<p>All modifications are distributed under the same license as the corresponding library.");
}
sb.append("<h2>Third-party products</h2>\n");
sb.append("<ol>\n");
for (CreditsItem item : items) {
sb.append("<li><b>").append(item.getName()).append("</b>\n");
sb.append("<p>Web site: <a href='").append(item.getWebPage()).append("' target='_blank'>").append(item.getWebPage()).append("</a></p>\n");
sb.append("<p>License: ");
if (item.getLicenseId() == null) {
sb.append("<br>").append(item.getLicense().replace("\n", "<br>"));
} else {
sb.append("<a href='#").append(item.getLicenseId()).append("'>").append(item.getLicenseId()).append("</a>");
licenses.put(item.getLicenseId(), item.getLicense());
}
sb.append("</p>");
sb.append("</li>\n");
}
sb.append("</ol>\n");
sb.append("<a name='licenses'></a><h2>Common Licenses</h2>\n");
sb.append("<ol>\n");
for (Map.Entry<String, String> entry : licenses.entrySet()) {
sb.append("<li><a name='").append(entry.getKey()).append("'></a><b>").append(entry.getKey()).append("</b>\n");
sb.append("<p>").append(entry.getValue().replace("\n", "<br>")).append("</p>");
sb.append("</li>\n");
}
sb.append("</ol>\n");
sb.append("</body></html>\n");
ByteArrayDataProvider dataProvider = new ByteArrayDataProvider(sb.toString().getBytes(StandardCharsets.UTF_8));
exportDisplay.show(dataProvider, "Credits", ExportFormat.HTML);
}
use of com.haulmont.cuba.gui.export.ByteArrayDataProvider in project cuba by cuba-platform.
the class GroupBrowser method export.
protected void export(ExportFormat exportFormat) {
Set<Group> selected = groupsTree.getSelected();
View view = viewRepository.getView(Group.class, "group.export");
if (view == null) {
throw new DevelopmentException("View 'group.export' for sec$Group was not found");
}
if (!selected.isEmpty()) {
try {
if (exportFormat == ExportFormat.ZIP) {
byte[] data = entityImportExportService.exportEntitiesToZIP(selected, view);
exportDisplay.show(new ByteArrayDataProvider(data), "Groups", ExportFormat.ZIP);
} else if (exportFormat == ExportFormat.JSON) {
byte[] data = entityImportExportService.exportEntitiesToJSON(selected, view).getBytes(StandardCharsets.UTF_8);
exportDisplay.show(new ByteArrayDataProvider(data), "Groups", ExportFormat.JSON);
}
} catch (Exception e) {
showNotification(getMessage("exportFailed"), e.getMessage(), NotificationType.ERROR);
log.error("Groups export failed", e);
}
}
}
use of com.haulmont.cuba.gui.export.ByteArrayDataProvider in project cuba by cuba-platform.
the class DesktopFileDescriptorResource method createResource.
@Override
protected void createResource() {
try {
byte[] file = AppBeans.get(FileStorageService.class).loadFile(fileDescriptor);
ByteArrayDataProvider provider = new ByteArrayDataProvider(file);
resource = ImageIO.read(provider.provide());
} catch (FileStorageException e) {
throw new RuntimeException(FILE_STORAGE_EXCEPTION_MESSAGE, e);
} catch (IOException e) {
throw new RuntimeException("An error occurred while loading an image.", e);
}
}
use of com.haulmont.cuba.gui.export.ByteArrayDataProvider in project cuba by cuba-platform.
the class OperationResultWindow method exportToFile.
public void exportToFile() {
if (result != null || exception != null) {
String exportResult = String.format("JMX Method %s : %s result\n", beanName, methodName);
if (result != null) {
exportResult += AttributeHelper.convertToString(result);
}
if (exception != null) {
exportResult += getExceptionMessage(exception);
}
byte[] bytes = exportResult.getBytes(StandardCharsets.UTF_8);
exportDisplay.show(new ByteArrayDataProvider(bytes), String.format("jmx.%s-%s-%s.log", beanName, methodName, new SimpleDateFormat("HH:mm:ss").format(timeSource.currentTimestamp())));
} else {
showNotification(getMessage("operationResult.resultIsEmpty"), NotificationType.HUMANIZED);
}
}
Aggregations