/** * Checks, whether an content entity with the given name exists in this content location. This method will report * invalid filenames as non-existent. * * @param name the name of the new entity. * @return true, if an entity exists with this name, false otherwise. */ public boolean exists( final String name ) { if ( RepositoryUtilities.isInvalidPathName( name ) ) { return false; } try { final FileObject file = getBackend(); final FileObject child = file.resolveFile( name ); return child.exists(); } catch ( FileSystemException e ) { throw new RuntimeException( e ); } } }
/** * 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 ); } }
/** * Lists all content entities stored in this content-location. This method filters out all files that have an invalid * name (according to the repository rules). * * @return the content entities for this location. * @throws ContentIOException if an repository error occured. */ public ContentEntity[] listContents() throws ContentIOException { try { final FileObject file = getBackend(); final FileObject[] files = file.getChildren(); final ContentEntity[] entities = new ContentEntity[files.length]; for ( int i = 0; i < files.length; i++ ) { final FileObject child = files[i]; if ( RepositoryUtilities.isInvalidPathName( child.getPublicURIString() ) ) { continue; } if ( child.isFolder() ) { entities[i] = new FileObjectContentLocation( this, child ); } else if ( child.isFile() ) { entities[i] = new FileObjectContentLocation( this, child ); } } return entities; } catch ( FileSystemException e ) { throw new RuntimeException( e ); } }
/** * Returns the content entity with the given name. If the entity does not exist, an Exception will be raised. * * @param name the name of the entity to be retrieved. * @return the content entity for this name, never null. * @throws ContentIOException if an repository error occured. */ public ContentEntity getEntry( final String name ) throws ContentIOException { try { if ( RepositoryUtilities.isInvalidPathName( name ) ) { throw new IllegalArgumentException( "The name given is not valid." ); } final FileObject file = getBackend(); final FileObject child = file.resolveFile( name ); if ( child.exists() == false ) { throw new ContentIOException( "Not found:" + child ); } if ( child.isFolder() ) { return new FileObjectContentLocation( this, child ); } else if ( child.isFile() ) { return new FileObjectContentItem( this, child ); } else { throw new ContentIOException( "Not File nor directory." ); } } catch ( FileSystemException e ) { throw new RuntimeException( e ); } }
if ( RepositoryUtilities.isInvalidPathName( name ) ) { throw new IllegalArgumentException( "The name given is not valid." );
/** * Checks, whether an content entity with the given name exists in this content location. This method will report * invalid filenames as non-existent. * * @param name the name of the new entity. * @return true, if an entity exists with this name, false otherwise. */ public boolean exists( final String name ) { if ( RepositoryUtilities.isInvalidPathName( name ) ) { return false; } final File file = getBackend(); final File child = new File( file, name ); return ( child.exists() ); } }
throw new IllegalStateException( "ContentLocation with an empty name" ); if ( isInvalidPathName( name ) ) { throw new IllegalStateException( "ContentLocation with an illegal name: " + name );
/** * Lists all content entities stored in this content-location. This method filters out all files that have an invalid * name (according to the repository rules). * * @return the content entities for this location. * @throws ContentIOException if an repository error occured. */ public ContentEntity[] listContents() throws ContentIOException { final File file = getBackend(); final File[] files = file.listFiles(); final ContentEntity[] entities = new ContentEntity[ files.length ]; for ( int i = 0; i < files.length; i++ ) { final File child = files[ i ]; if ( RepositoryUtilities.isInvalidPathName( child.getName() ) ) { continue; } if ( child.isDirectory() ) { entities[ i ] = new FileContentLocation( this, child ); } else if ( child.isFile() ) { entities[ i ] = new FileContentLocation( this, child ); } } return entities; }
/** * Creates a new data item in the current location. This method must never return null. * * @param name * @return * @throws org.pentaho.reporting.libraries.repository.ContentCreationException if the item could not be created. */ public ContentItem createItem( final String name ) throws ContentCreationException { if ( entries.containsKey( name ) ) { throw new ContentCreationException( "Entry already exists" ); } if ( RepositoryUtilities.isInvalidPathName( name ) ) { throw new ContentCreationException( "Entry-Name is not valid" ); } final ZipContentItem item = new ZipContentItem( name, repository, this ); entries.put( name, item ); return item; }
public ContentLocation createLocation( final String name ) throws ContentCreationException { if ( entries.containsKey( name ) ) { throw new ContentCreationException( "Entry already exists" ); } if ( RepositoryUtilities.isInvalidPathName( name ) ) { throw new ContentCreationException( "Entry-Name is not valid" ); } final ZipContentLocation item = new ZipContentLocation( repository, this, name ); entries.put( name, item ); if ( "/".equals( this.contentId ) == false ) { try { final ZipEntry entry = new ZipEntry( contentId + name + '/' ); repository.writeDirectory( entry ); } catch ( IOException e ) { throw new ContentCreationException( "Failed to create directory.", e ); } } return item; }
/** * 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." ); } final File file = getBackend(); final File child = new File( file, name ); if ( child.exists() ) { throw new ContentCreationException( "File already exists." ); } if ( child.mkdir() == false ) { throw new ContentCreationException( "Unable to create the directory" ); } try { return new FileContentLocation( this, child ); } catch ( ContentIOException e ) { throw new ContentCreationException( "Failed to create the content-location", e ); } }
/** * 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 ); } }
if ( RepositoryUtilities.isInvalidPathName( name ) ) { throw new IllegalArgumentException( "The name given is not valid." );