List of usage examples for org.apache.commons.vfs2 FileObject isFolder
boolean isFolder() throws FileSystemException;
From source file:org.pentaho.di.trans.steps.pentahoreporting.urlrepository.FileObjectContentLocation.java
/** * Creates a new root-location for the given repository and directory. * * @param repository the repository for which a location should be created. * @param backend the backend./*from www. j a v a2s . c o m*/ * @throws ContentIOException if an error occured or the file did not point to a directory. */ public FileObjectContentLocation(final Repository repository, final FileObject backend) throws ContentIOException { super(repository, backend); boolean error; try { error = backend.exists() == false || backend.isFolder() == false; } catch (FileSystemException e) { throw new RuntimeException(e); } if (error) { throw new ContentIOException("The given backend-file is not a directory."); } }
From source file:org.pentaho.di.trans.steps.pentahoreporting.urlrepository.FileObjectContentLocation.java
/** * 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. *///from ww w . j av a 2 s .co m 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); } }
From source file:org.pentaho.di.trans.steps.pentahoreporting.urlrepository.FileObjectContentLocation.java
/** * 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. *///w ww. j av a 2s .c o m 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); } }
From source file:org.pentaho.googledrive.vfs.test.GoogleDriveFileObjectTest.java
@Test public void testFileObject() throws Exception { FileSystemManager manager = mock(FileSystemManager.class); GoogleDriveFileObject fileObjectMock = mock(GoogleDriveFileObject.class); when(manager.resolveFile(FOLDER)).thenReturn(fileObjectMock); when(fileObjectMock.isFolder()).thenReturn(true); when(fileObjectMock.exists()).thenReturn(true); when(fileObjectMock.delete()).thenReturn(true); FileObject fileObject = manager.resolveFile(FOLDER); fileObject.createFolder();/*from w w w . j a v a 2s. c o m*/ assertTrue(fileObject.isFolder()); assertTrue(fileObject.exists()); assertTrue(fileObject.delete()); assertNull(fileObject.getChildren()); }