List of usage examples for org.apache.commons.vfs2 FileType FILE
FileType FILE
To view the source code for org.apache.commons.vfs2 FileType FILE.
Click Source Link
From source file:org.pentaho.metaverse.impl.VfsLineageCollector.java
@Override public List<String> listArtifacts(final String startingDate, final String endingDate) throws IllegalArgumentException { List<String> paths = new ArrayList<>(); try {//from www.ja v a2 s . com FileSystemOptions opts = new FileSystemOptions(); FileObject lineageRootFolder = KettleVFS.getFileObject(getOutputFolder(), opts); FileSelector dateRangeFilter = new VfsDateRangeFilter(format, startingDate, endingDate); FileSelector depthFilter = new FileDepthSelector(1, 256); if (lineageRootFolder.exists() && lineageRootFolder.getType() == FileType.FOLDER) { // get the folders that come on or after the startingDate FileObject[] dayFolders = lineageRootFolder.findFiles(dateRangeFilter); for (FileObject dayFolder : dayFolders) { FileObject[] listThisFolder = dayFolder.findFiles(depthFilter); for (FileObject currentFile : listThisFolder) { if (currentFile.getType() == FileType.FILE) { paths.add(currentFile.getName().getPath()); } } } } return paths; } catch (Exception e) { throw new IllegalArgumentException(e); } }
From source file:org.pentaho.metaverse.impl.VfsLineageCollector.java
@Override public List<String> listArtifactsForFile(String pathToArtifact, String startingDate, String endingDate) throws IllegalArgumentException { List<String> paths = new ArrayList<>(); try {//from www .j av a 2 s . co m FileSystemOptions opts = new FileSystemOptions(); FileObject lineageRootFolder = KettleVFS.getFileObject(getOutputFolder(), opts); FileSelector dateRangeFilter = new VfsDateRangeFilter(format, startingDate, endingDate); FileSelector depthFilter = new FileDepthSelector(1, 256); if (lineageRootFolder.exists() && lineageRootFolder.getType() == FileType.FOLDER) { // get all of the date folders of lineage we have FileObject[] dayFolders = lineageRootFolder.findFiles(dateRangeFilter); for (FileObject dayFolder : dayFolders) { FileObject[] listThisFolder = dayFolder.findFiles(depthFilter); for (FileObject currentFile : listThisFolder) { FileObject requested = currentFile.resolveFile(pathToArtifact); if (requested.exists() && requested.getType() == FileType.FOLDER) { FileObject[] requestedChildren = requested.getChildren(); for (FileObject requestedChild : requestedChildren) { if (requestedChild.getType() == FileType.FILE) { paths.add(requestedChild.getName().getPath()); } } } } } } return paths; } catch (Exception e) { throw new IllegalArgumentException(e); } }
From source file:org.pentaho.metaverse.util.VfsDateRangeFilterTest.java
@Test public void testAccept_notFolder() throws Exception { filter = new VfsDateRangeFilter(format, start); FileSelectInfo fsi = mock(FileSelectInfo.class); FileObject fo = mock(FileObject.class); when(fo.getType()).thenReturn(FileType.FILE); when(fsi.getFile()).thenReturn(fo);//from ww w .j a v a2 s . c o m when(fsi.getDepth()).thenReturn(1); assertFalse(filter.includeFile(fsi)); }
From source file:org.pentaho.platform.pdi.vfs.MetadataToMondrianVfsFileObject.java
public MetadataToMondrianVfsFileObject(final String fileRef) { this.fileRef = fileRef; // try to guess the file type type = FileType.FILE; name = new MetadataToMondrianVfsFileName(fileRef, type); }
From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.dialogs.RepositoryOpenDialog.java
public void setSelectedView(final FileObject selectedView) { this.selectedView = selectedView; if (selectedView != null) { logger.debug("Setting selected view to " + selectedView); try {/*from w ww .ja v a 2s . c o m*/ if (selectedView.getType() == FileType.FILE) { logger.debug("Setting filename in selected view to " + selectedView.getName().getBaseName()); this.fileNameTextField .setText(URLDecoder.decode(selectedView.getName().getBaseName(), "UTF-8")); } } catch (Exception e) { // can be ignored .. logger.debug("Unable to determine file type. This is not fatal.", e); } final ComboBoxModel comboBoxModel = createLocationModel(selectedView); this.locationCombo.setModel(comboBoxModel); this.table.setSelectedPath((FileObject) comboBoxModel.getSelectedItem()); } else { this.fileNameTextField.setText(null); this.table.setSelectedPath(null); this.locationCombo.setModel(new DefaultComboBoxModel()); } }
From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.dialogs.RepositoryOpenDialog.java
private ComboBoxModel createLocationModel(final FileObject selectedFolder) { if (fileSystemRoot == null) { return new DefaultComboBoxModel(); }//from w w w . ja v a2 s. c o m try { final ArrayList<FileObject> list = new ArrayList<FileObject>(); FileObject folder = selectedFolder; while (folder != null) { if (fileSystemRoot.equals(folder)) { break; } if (folder.getType() != FileType.FILE) { list.add(folder); } final FileObject parent = folder.getParent(); if (folder.equals(parent)) { // protect yourself against infinite loops .. break; } folder = parent; } list.add(fileSystemRoot); final DefaultComboBoxModel model = new DefaultComboBoxModel(list.toArray()); model.setSelectedItem(list.get(0)); return model; } catch (FileSystemException e) { return new DefaultComboBoxModel(); } }
From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.dialogs.RepositoryOpenDialog.java
protected String getSelectedFile() throws FileSystemException, UnsupportedEncodingException { if (StringUtils.isEmpty(fileNameTextField.getText())) { return null; }/*from w w w . j av a 2 s. c o m*/ if (selectedView.getType() == FileType.FILE) { selectedView = selectedView.getParent(); } final FileObject targetFile = selectedView.resolveFile(fileNameTextField.getText().replaceAll("\\%", "%25") .replaceAll("\\!", "%21").replaceAll(":", "%3A")); return targetFile.getName().getPathDecoded(); }
From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.model.RepositoryTreeModelTest.java
@Test public void testGetChild() { RepositoryTreeModel treeModel = new RepositoryTreeModel(); assertNotNull(treeModel);//from w w w . j ava 2 s .co m assertNull(treeModel.getFileSystemRoot()); FileObject[] childFiles = new FileObject[] { childFile1, childFile2, childFile3 }; try { doReturn(childFiles).when(repositoryRoot).getChildren(); } catch (FileSystemException e) { e.printStackTrace(); } treeModel.setFileSystemRoot(repositoryRoot); Object value = treeModel.getChild(repositoryRoot, 1); assertEquals(childFile2, value); treeModel.setShowFoldersOnly(true); try { doReturn(FileType.FILE).when(childFile1).getType(); doReturn(FileType.FILE).when(childFile2).getType(); doReturn(FileType.FILE).when(childFile3).getType(); } catch (FileSystemException e) { e.printStackTrace(); } value = treeModel.getChild(repositoryRoot, 0); assertEquals(childFile1, value); treeModel.setShowHiddenFiles(false); try { doReturn(FileType.FOLDER).when(childFile1).getType(); doReturn(FileType.FOLDER).when(childFile2).getType(); doReturn(FileType.FOLDER).when(childFile3).getType(); doReturn(true).when(childFile1).isHidden(); doReturn(true).when(childFile2).isHidden(); doReturn(true).when(childFile3).isHidden(); } catch (FileSystemException e) { e.printStackTrace(); } value = treeModel.getChild(repositoryRoot, 2); assertEquals(childFile3, value); }
From source file:org.pentaho.reporting.libraries.pensol.WebSolutionFileObject.java
/** * Determines the type of this file. Must not return null. The return value of this method is cached, so the * implementation can be expensive.//from w w w.ja v a2s .c om */ protected FileType doGetType() throws Exception { if (getName().getDepth() < 2) { return FileType.FOLDER; } if (fs.exists(getName()) == false) { return FileType.IMAGINARY; } if (fs.isDirectory(getName())) { return FileType.FOLDER; } return FileType.FILE; }
From source file:org.pentaho.repositoryvfs.vfs.RepositoryVfsFileObject.java
protected synchronized RepositoryFile getRepositoryFile() { if (repositoryFile == null) { try {/*www .ja va 2s . com*/ repositoryFile = provider.getRepo().getUnderlyingRepository().getFile(path); if (repositoryFile == null) { return null; } type = repositoryFile.isFolder() ? FileType.FOLDER : FileType.FILE; } catch (Exception ex) { throw new RuntimeException(ex); } } return repositoryFile; }