Search in sources :

Example 6 with ByteArrayDataProvider

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());
}
Also used : ByteArrayDataProvider(com.haulmont.cuba.gui.export.ByteArrayDataProvider) StreamResource(com.haulmont.cuba.gui.components.StreamResource) InputStream(java.io.InputStream) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) FileDescriptorResource(com.haulmont.cuba.gui.components.FileDescriptorResource) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor)

Example 7 with ByteArrayDataProvider

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);
}
Also used : ByteArrayDataProvider(com.haulmont.cuba.gui.export.ByteArrayDataProvider) TreeMap(java.util.TreeMap) ParamsMap(com.haulmont.bali.util.ParamsMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 8 with ByteArrayDataProvider

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);
        }
    }
}
Also used : ByteArrayDataProvider(com.haulmont.cuba.gui.export.ByteArrayDataProvider) EntityImportView(com.haulmont.cuba.core.app.importexport.EntityImportView) IOException(java.io.IOException)

Example 9 with ByteArrayDataProvider

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);
    }
}
Also used : ByteArrayDataProvider(com.haulmont.cuba.gui.export.ByteArrayDataProvider) FileStorageService(com.haulmont.cuba.core.app.FileStorageService) IOException(java.io.IOException) FileStorageException(com.haulmont.cuba.core.global.FileStorageException)

Example 10 with ByteArrayDataProvider

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);
    }
}
Also used : ByteArrayDataProvider(com.haulmont.cuba.gui.export.ByteArrayDataProvider) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

ByteArrayDataProvider (com.haulmont.cuba.gui.export.ByteArrayDataProvider)10 IOException (java.io.IOException)3 EntityImportView (com.haulmont.cuba.core.app.importexport.EntityImportView)2 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)2 FileStorageException (com.haulmont.cuba.core.global.FileStorageException)2 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)2 InputStream (java.io.InputStream)2 ParamsMap (com.haulmont.bali.util.ParamsMap)1 DomainDescriptionService (com.haulmont.cuba.core.app.DomainDescriptionService)1 FileStorageService (com.haulmont.cuba.core.app.FileStorageService)1 FileDescriptorResource (com.haulmont.cuba.gui.components.FileDescriptorResource)1 StreamResource (com.haulmont.cuba.gui.components.StreamResource)1 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1 ExportDisplay (com.haulmont.cuba.gui.export.ExportDisplay)1 WebExportDisplay (com.haulmont.cuba.web.filestorage.WebExportDisplay)1 StreamResource (com.vaadin.server.StreamResource)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1