List of usage examples for org.apache.commons.vfs2 FileObject exists
boolean exists() throws FileSystemException;
From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.util.PublishUtil.java
public static ReportRenderContext openReport(final ReportDesignerContext context, final AuthenticationData loginData, final String path) throws IOException, ReportDataFactoryException, ResourceException { if (StringUtils.isEmpty(path)) { throw new IOException("Path is empty."); }/* w w w . j av a 2 s . c o m*/ final String urlPath = path.replaceAll("%", "%25").replaceAll("%2B", "+").replaceAll("\\!", "%21") .replaceAll(":", "%3A"); final FileObject connection = createVFSConnection(loginData); final FileObject object = connection.resolveFile(urlPath); if (object.exists() == false) { throw new FileNotFoundException(path); } final InputStream inputStream = object.getContent().getInputStream(); try { final ByteArrayOutputStream out = new ByteArrayOutputStream( Math.max(8192, (int) object.getContent().getSize())); IOUtils.getInstance().copyStreams(inputStream, out); final MasterReport report = loadReport(out.toByteArray(), path); final int index = context.addMasterReport(report); return context.getReportRenderContext(index); } finally { inputStream.close(); } }
From source file:org.pentaho.vfs.ui.VfsBrowser.java
public boolean createFolder(String folderName) throws FileSystemException { FileObject newFolder = getSelectedFileObject().resolveFile(folderName); if (newFolder.exists()) { throw new FileSystemException("vfs.provider/create-folder.error", folderName); }//from www .j a v a 2 s . c o m newFolder.createFolder(); TreeItem newFolderTreeItem = new TreeItem(fileSystemTree.getSelection()[0], SWT.NONE); newFolderTreeItem.setData(newFolder); newFolderTreeItem.setData("isLoaded", Boolean.TRUE); //$NON-NLS-1$ newFolderTreeItem.setImage(getFolderImage(newFolderTreeItem.getDisplay())); populateTreeItemText(newFolderTreeItem, newFolder); fileSystemTree.setSelection(newFolderTreeItem); setSelectedFileObject(newFolder); fireFileObjectSelected(); return true; }
From source file:org.pentaho.vfs.ui.VfsBrowser.java
public boolean renameItem(TreeItem ti, String newName) throws FileSystemException { FileObject file = (FileObject) ti.getData(); FileObject newFileObject = file.getParent().resolveFile(newName); if (file.canRenameTo(newFileObject)) { if (!newFileObject.exists()) { newFileObject.createFile();// w w w.j a v a 2s.co m } else { return false; } file.moveTo(newFileObject); ti.setText(newName); ti.setData(newFileObject); return true; } else { return false; } }
From source file:org.pentaho.vfs.ui.VfsBrowser.java
public boolean moveItem(TreeItem source, TreeItem destination) throws FileSystemException { FileObject file = (FileObject) source.getData(); FileObject destFile = (FileObject) destination.getData(); if (!file.exists() && !destFile.exists()) { return false; }//from w w w .j a va 2 s . c o m try { if (destFile.getChildren() != null) { destFile = destFile.resolveFile(source.getText()); } } catch (Exception e) { destFile = destFile.getParent().resolveFile(source.getText()); destination = destination.getParentItem(); } if (!file.getParent().equals(destFile.getParent())) { file.moveTo(destFile); TreeItem destTreeItem = new TreeItem(destination, SWT.NONE); destTreeItem.setImage(getFileImage(source.getDisplay())); destTreeItem.setData(destFile); destTreeItem.setData("isLoaded", Boolean.FALSE); //$NON-NLS-1$ populateTreeItemText(destTreeItem, destFile); source.dispose(); } return true; }
From source file:org.pentaho.vfs.ui.VfsFileChooserDialog.java
public void okPressed() { if (fileDialogMode == VFS_DIALOG_SAVEAS && "".equals(fileNameText.getText())) { //$NON-NLS-1$ // do nothing, user did not enter a file name for saving MessageBox messageDialog = new MessageBox(dialog, SWT.OK); messageDialog.setText(Messages.getString("VfsFileChooserDialog.error")); //$NON-NLS-1$ messageDialog.setMessage(Messages.getString("VfsFileChooserDialog.noFilenameEntered")); //$NON-NLS-1$ messageDialog.open();/*from w w w .j a v a 2 s .co m*/ return; } if (fileDialogMode == VFS_DIALOG_SAVEAS) { try { FileObject toBeSavedFile = vfsBrowser.getSelectedFileObject().resolveFile(fileNameText.getText()); if (toBeSavedFile.exists()) { MessageBox messageDialog = new MessageBox(dialog, SWT.YES | SWT.NO); messageDialog.setText(Messages.getString("VfsFileChooserDialog.fileExists")); //$NON-NLS-1$ messageDialog.setMessage(Messages.getString("VfsFileChooserDialog.fileExistsOverwrite")); //$NON-NLS-1$ int flag = messageDialog.open(); if (flag == SWT.NO) { return; } } } catch (FileSystemException e) { e.printStackTrace(); } } if (fileDialogMode == VFS_DIALOG_SAVEAS) { enteredFileName = fileNameText.getText(); } try { if (fileDialogMode == VFS_DIALOG_OPEN_FILE && vfsBrowser.getSelectedFileObject().getType().equals(FileType.FOLDER)) { // try to open this node, it is a directory vfsBrowser.selectTreeItemByFileObject(vfsBrowser.getSelectedFileObject(), true); return; } } catch (FileSystemException e) { } okPressed = true; hideCustomPanelChildren(); dialog.dispose(); }
From source file:org.pentaho.vfs.util.VfsHelper.java
public FileObject saveFile(String uri, InputStream is) throws IOException { if (fsManager != null) { FileObject savedFile = fsManager.resolveFile(uri); if (!savedFile.exists()) { throw new FileSystemException(Messages.getString("VfsHelper.fileDoesNotExist")); //$NON-NLS-1$ }// w w w . j a va 2 s. c o m IOUtils.copy(is, savedFile.getContent().getOutputStream()); return savedFile; } throw new FileSystemException(Messages.getString("VfsHelper.operationFailed")); //$NON-NLS-1$ }
From source file:org.pentaho.vfs.util.VfsHelper.java
public FileObject saveFileAs(String uri, InputStream is) throws FileSystemException, IOException { if (fsManager != null) { FileObject savedFile = fsManager.resolveFile(uri); if (!savedFile.exists()) { savedFile.createFile();// w ww. j a v a 2 s . c o m } IOUtils.copy(is, savedFile.getContent().getOutputStream()); return savedFile; } throw new FileSystemException(Messages.getString("VfsHelper.operationFailed")); //$NON-NLS-1$ }
From source file:org.pentaho.vfs.util.VfsHelper.java
public FileObject getFileObject(String uri) throws FileSystemException { if (fsManager != null) { FileObject file = fsManager.resolveFile(uri); if (!file.exists()) { throw new FileSystemException(Messages.getString("VfsHelper.fileDoesNotExist")); //$NON-NLS-1$ }//from w w w . j av a 2 s . c o m return file; } throw new FileSystemException(Messages.getString("VfsHelper.operationFailed")); //$NON-NLS-1$ }
From source file:org.pentaho.vfs.util.VfsHelper.java
public byte[] getFileContentAsByteArray(FileObject fileObject) throws IOException { if (fileObject != null && fileObject.exists()) { IOUtils.toByteArray(fileObject.getContent().getInputStream()); }// ww w .j a va2s . co m throw new FileSystemException(Messages.getString("VfsHelper.operationFailed")); //$NON-NLS-1$ }
From source file:org.renjin.appengine.AppEngineLocalFilesSystemProviderTest.java
@Test public void test() throws FileSystemException { File basePath = new File(getClass().getResource("/jarfiletest.jar").getFile()).getParentFile(); FileSystemManager dfsm = AppEngineContextFactory .createFileSystemManager(new AppEngineLocalFilesSystemProvider(basePath)); FileObject jarFile = dfsm.resolveFile("/jarfiletest.jar"); assertThat(jarFile.getName().getURI(), equalTo("file:///jarfiletest.jar")); assertThat(jarFile.exists(), equalTo(true)); FileObject jarRoot = dfsm.resolveFile("jar:file:///jarfiletest.jar!/r/library"); assertThat(jarRoot.exists(), equalTo(true)); assertThat(jarRoot.getType(), equalTo(FileType.FOLDER)); assertThat(jarRoot.getChildren().length, equalTo(1)); }