Search in sources :

Example 1 with ContentCreationException

use of org.pentaho.reporting.libraries.repository.ContentCreationException in project pentaho-kettle by pentaho.

the class FileObjectContentLocation method createItem.

/**
 * Creates a new data item in the current location. This method must never return null. This method will fail if an
 * entity with the same name exists in this location.
 *
 * @param name the name of the new entity.
 * @return the newly created entity, never null.
 * @throws ContentCreationException if the item could not be created.
 */
public ContentItem createItem(final String name) throws ContentCreationException {
    if (RepositoryUtilities.isInvalidPathName(name)) {
        throw new IllegalArgumentException("The name given is not valid.");
    }
    try {
        final FileObject file = getBackend();
        final FileObject child = file.resolveFile(name);
        if (child.exists()) {
            if (child.getContent().getSize() == 0) {
                // probably one of the temp files created by the pentaho-system
                return new FileObjectContentItem(this, child);
            }
            throw new ContentCreationException("File already exists: " + child);
        }
        try {
            child.createFile();
            return new FileObjectContentItem(this, child);
        } catch (IOException e) {
            throw new ContentCreationException("IOError while create", e);
        }
    } catch (FileSystemException e) {
        throw new RuntimeException(e);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) ContentCreationException(org.pentaho.reporting.libraries.repository.ContentCreationException) FileObject(org.apache.commons.vfs2.FileObject) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException) IOException(java.io.IOException)

Example 2 with ContentCreationException

use of org.pentaho.reporting.libraries.repository.ContentCreationException in project pentaho-kettle by pentaho.

the class FileObjectContentLocation method createLocation.

/**
 * Creates a new content location in the current location. This method must never return null. This method will fail
 * if an entity with the same name exists in this location.
 *
 * @param name the name of the new entity.
 * @return the newly created entity, never null.
 * @throws ContentCreationException if the item could not be created.
 */
public ContentLocation createLocation(final String name) throws ContentCreationException {
    if (RepositoryUtilities.isInvalidPathName(name)) {
        throw new IllegalArgumentException("The name given is not valid.");
    }
    try {
        final FileObject file = getBackend();
        final FileObject child = file.resolveFile(name);
        if (child.exists()) {
            throw new ContentCreationException("File already exists.");
        }
        child.createFile();
        try {
            return new FileObjectContentLocation(this, child);
        } catch (ContentIOException e) {
            throw new ContentCreationException("Failed to create the content-location", e);
        }
    } catch (FileSystemException e) {
        throw new RuntimeException(e);
    }
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) ContentCreationException(org.pentaho.reporting.libraries.repository.ContentCreationException) FileObject(org.apache.commons.vfs2.FileObject) ContentIOException(org.pentaho.reporting.libraries.repository.ContentIOException)

Aggregations

FileObject (org.apache.commons.vfs2.FileObject)2 FileSystemException (org.apache.commons.vfs2.FileSystemException)2 ContentCreationException (org.pentaho.reporting.libraries.repository.ContentCreationException)2 ContentIOException (org.pentaho.reporting.libraries.repository.ContentIOException)2 IOException (java.io.IOException)1