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);
}
}
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);
}
}
Aggregations