Search in sources :

Example 1 with FileContentItem

use of org.pentaho.platform.engine.core.output.FileContentItem in project pentaho-platform by pentaho.

the class FileOutputHandler method getFileOutputContentItem.

@Override
public IContentItem getFileOutputContentItem() {
    String contentRef = getContentRef();
    File file = new File(contentRef);
    File dir = file.getParentFile();
    if ((dir != null) && !dir.exists()) {
        boolean result = dir.mkdirs();
        if (!result) {
            try {
                URI uri = new URI(contentRef);
                file = new File(uri);
                dir = file.getParentFile();
            } catch (URISyntaxException e) {
                logger.error(Messages.getInstance().getErrorString("FileOutputHandler.ERROR_0001_COULD_NOT_CREATE_DIRECTORY", // $NON-NLS-1$
                dir.getAbsolutePath()));
                return null;
            }
        }
    }
    try {
        SimpleContentItem content = new FileContentItem(file);
        return content;
    } catch (FileNotFoundException e) {
        logger.error(Messages.getInstance().getErrorString("FileOutputHandler.ERROR_0002_COULD_NOT_CREATE_OUTPUT_FILE", file.getAbsolutePath()), // $NON-NLS-1$
        e);
    }
    return null;
}
Also used : SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) FileContentItem(org.pentaho.platform.engine.core.output.FileContentItem) FileNotFoundException(java.io.FileNotFoundException) URISyntaxException(java.net.URISyntaxException) File(java.io.File) URI(java.net.URI)

Example 2 with FileContentItem

use of org.pentaho.platform.engine.core.output.FileContentItem in project pentaho-platform by pentaho.

the class XactionUtil method deleteContentItem.

static void deleteContentItem(IContentItem contentItem, IUnifiedRepository unifiedRepository) {
    if (contentItem instanceof RepositoryFileContentItem) {
        String path = contentItem.getPath();
        RepositoryFile repositoryFile = unifiedRepository.getFile(path);
        // repositoryFile can be null if we have not access or file does not exist
        if (repositoryFile != null) {
            unifiedRepository.deleteFile(repositoryFile.getId(), true, null);
        }
    } else if (contentItem instanceof FileContentItem) {
        // Files in the file system must not be deleted here
        String path = ((FileContentItem) contentItem).getFile().getName();
        logger.warn(Messages.getInstance().getString("XactionUtil.SKIP_REMOVING_OUTPUT_FILE", path));
    }
}
Also used : RepositoryFileContentItem(org.pentaho.platform.repository2.unified.fileio.RepositoryFileContentItem) FileContentItem(org.pentaho.platform.engine.core.output.FileContentItem) RepositoryFileContentItem(org.pentaho.platform.repository2.unified.fileio.RepositoryFileContentItem) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Aggregations

FileContentItem (org.pentaho.platform.engine.core.output.FileContentItem)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)1 SimpleContentItem (org.pentaho.platform.engine.core.output.SimpleContentItem)1 RepositoryFileContentItem (org.pentaho.platform.repository2.unified.fileio.RepositoryFileContentItem)1