/** * 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." ); } final File file = getBackend(); final File child = new File( file, name ); if ( child.exists() ) { if ( child.length() == 0 ) { // probably one of the temp files created by the pentaho-system return new FileContentItem( this, child ); } throw new ContentCreationException( "File already exists: " + child ); } try { if ( child.createNewFile() == false ) { throw new ContentCreationException( "Unable to create the file." ); } return new FileContentItem( this, child ); } catch ( IOException e ) { throw new ContentCreationException( "IOError while create", e ); } }
return new FileContentLocation( this, child ); } else if ( child.isFile() ) { return new FileContentItem( this, child ); } else { throw new ContentIOException( "Not File nor directory." );