Search in sources :

Example 1 with FileDataProvider

use of com.haulmont.cuba.gui.export.FileDataProvider in project cuba by cuba-platform.

the class DesktopFileUploadField method getFileContent.

@Override
public InputStream getFileContent() {
    if (contentProvider != null) {
        return contentProvider.provide();
    }
    FileDescriptor fileDescriptor = getValue();
    switch(mode) {
        case MANUAL:
            if (fileId == null) {
                return new FileDataProvider(fileDescriptor).provide();
            }
            File file = fileUploading.getFile(fileId);
            if (file != null) {
                try {
                    return new FileInputStream(file);
                } catch (FileNotFoundException e) {
                    log.error("Unable to get content of {}", file, e);
                }
                return null;
            }
            FileStorageService fileStorageService = AppBeans.get(FileStorageService.NAME);
            try {
                if (fileStorageService.fileExists(fileDescriptor)) {
                    return new FileDataProvider(fileDescriptor).provide();
                }
            } catch (FileStorageException e) {
                log.error("Unable to get content of {}", fileDescriptor, e);
                return null;
            }
            break;
        case IMMEDIATE:
            if (fileDescriptor != null) {
                return new FileDataProvider(fileDescriptor).provide();
            }
    }
    return null;
}
Also used : FileDataProvider(com.haulmont.cuba.gui.export.FileDataProvider) FileStorageService(com.haulmont.cuba.core.app.FileStorageService) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor)

Example 2 with FileDataProvider

use of com.haulmont.cuba.gui.export.FileDataProvider in project cuba by cuba-platform.

the class WebFileUploadField method getFileContent.

@Override
public InputStream getFileContent() {
    if (contentProvider != null) {
        return contentProvider.provide();
    }
    FileDescriptor fileDescriptor = getValue();
    switch(mode) {
        case MANUAL:
            if (fileId == null) {
                return new FileDataProvider(fileDescriptor).provide();
            }
            File file = fileUploading.getFile(fileId);
            if (file != null) {
                try {
                    return new FileInputStream(file);
                } catch (FileNotFoundException e) {
                    log.error("Unable to get content of {}", file, e);
                }
                return null;
            }
            FileStorageService fileStorageService = AppBeans.get(FileStorageService.NAME);
            try {
                if (fileStorageService.fileExists(fileDescriptor)) {
                    return new FileDataProvider(fileDescriptor).provide();
                }
            } catch (FileStorageException e) {
                log.error("Unable to get content of {}", fileDescriptor, e);
                return null;
            }
            break;
        case IMMEDIATE:
            if (fileDescriptor != null) {
                return new FileDataProvider(fileDescriptor).provide();
            }
    }
    return null;
}
Also used : FileDataProvider(com.haulmont.cuba.gui.export.FileDataProvider) FileStorageService(com.haulmont.cuba.core.app.FileStorageService) FileStorageException(com.haulmont.cuba.core.global.FileStorageException) FileDescriptor(com.haulmont.cuba.core.entity.FileDescriptor)

Aggregations

FileStorageService (com.haulmont.cuba.core.app.FileStorageService)2 FileDescriptor (com.haulmont.cuba.core.entity.FileDescriptor)2 FileDataProvider (com.haulmont.cuba.gui.export.FileDataProvider)2 FileStorageException (com.haulmont.cuba.core.global.FileStorageException)1