List of usage examples for org.apache.commons.vfs FileObject exists
public boolean exists() throws FileSystemException;
From source file:org.apache.ivy.plugins.repository.vfs.VfsRepository.java
/** * Return a listing of the contents of a parent directory. Listing is a set of strings * representing VFS URIs./*from w w w . jav a 2s . c om*/ * * @param vfsURI * providing identifying a VFS provided resource * @throws IOException * on failure. * @see "Supported File Systems in the jakarta-commons-vfs documentation" */ public List list(String vfsURI) throws IOException { ArrayList list = new ArrayList(); Message.debug("list called for URI" + vfsURI); FileObject resourceImpl = getVFSManager().resolveFile(vfsURI); Message.debug("resourceImpl=" + resourceImpl.toString()); Message.debug("resourceImpl.exists()" + resourceImpl.exists()); Message.debug("resourceImpl.getType()" + resourceImpl.getType()); Message.debug("FileType.FOLDER" + FileType.FOLDER); if ((resourceImpl != null) && resourceImpl.exists() && (resourceImpl.getType() == FileType.FOLDER)) { FileObject[] children = resourceImpl.getChildren(); for (int i = 0; i < children.length; i++) { FileObject child = children[i]; Message.debug("child " + i + child.getName().getURI()); list.add(VfsResource.normalize(child.getName().getURI())); } } return list; }
From source file:org.bibalex.gallery.storage.BAGStorage.java
public static URL cacheFileLocally(String cacheLocalPath, String fileUrlStr) throws BAGException { try {/*w w w . ja v a 2 s . c om*/ // String extension = ""; // // int lastDotIx = fileUrlStr.lastIndexOf('.'); // if (lastDotIx > fileUrlStr.lastIndexOf('/')) { // extension = fileUrlStr.substring(lastDotIx); // } // String cacheFileName = "cached" + fileUrlStr.hashCode() + extension; int lastSlashIx = fileUrlStr.lastIndexOf('/'); String cacheFileName = fileUrlStr.substring(lastSlashIx + 1); String cacheFilePath = URLPathStrUtils.appendParts(cacheLocalPath, cacheFileName); FileSystemManager fsMgr = VFS.getManager(); final FileObject cacheFileFO = fsMgr.resolveFile(cacheFilePath); final FileObject cacheDirFO = fsMgr.resolveFile(cacheLocalPath); if (!cacheFileFO.exists()) { synchronized (BAGStorage.class) { if (!cacheDirFO.exists()) { cacheDirFO.createFolder(); } cacheFileFO.createFile(); OutputStream cacheFileOut = cacheFileFO.getContent().getOutputStream(); try { readRemoteFile(fileUrlStr, cacheFileOut); } finally { cacheFileOut.close(); } } } return cacheFileFO.getURL(); } catch (FileSystemException e) { throw new BAGException(e); } catch (IOException e) { throw new BAGException(e); } }
From source file:org.cfeclipse.cfml.views.explorer.vfs.view.VFSView.java
/** * Creates the toolbar/*from w w w . j a va2s. com*/ * * @param shell the shell on which to attach the toolbar * @param layoutData the layout data */ private Control createToolBar(final Composite shell) { //, Object layoutData) { final ToolBar toolBar = new ToolBar(shell, SWT.FLAT); // toolBar.setLayoutData(layoutData); // New VFS ToolItem item = new ToolItem(toolBar, SWT.PUSH); item.setImage(iconCache.get(CFPluginImages.ICON_DRIVE_FTP));//.iconFile]); //item.setText(getResourceString("tool.New.vfs.text")); item.setToolTipText(getResourceString("tool.New.vfs.tip")); item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { connectionAction.run(); } }); // Home item = new ToolItem(toolBar, SWT.PUSH); item.setImage(iconCache.get(CFPluginImages.ICON_HOME)); //item.setText(getResourceString("tool.home.text")); item.setToolTipText(getResourceString("tool.home.tip")); item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { try { // Jump the file system home directory, some FS don't have homes String homeDir = getCurrentDirectory().getName().getScheme().equals("file") ? VFSUtil.USER_HOME : (String) getCurrentDirectory().getFileSystem().getAttribute("HOME_DIRECTORY"); // Build a URI from the home dir String uri = Os.isFamily(Os.OS_FAMILY_UNIX) ? getCurrentDirectory().getName().getRootURI() + homeDir : getCurrentDirectory().getName().getScheme() + ":///" + homeDir.replace('\\', '/'); FileObject fo = resolveURI(uri, getCurrentConnectionId()); if (fo.exists()) notifySelectedDirectory(fo, getCurrentConnectionId()); else VFSUtil.MessageBoxInfo(getResourceString("error.jump.home", new Object[] { homeDir })); } catch (FileSystemException ex) { FileObject fo; try { fo = resolveURI(fConnections.get(getCurrentConnectionId()).getURI().toString(), getCurrentConnectionId()); if (fo.exists()) notifySelectedDirectory(fo, getCurrentConnectionId()); else VFSUtil.MessageBoxInfo( getResourceString("error.jump.home", new Object[] { fo.getURL().toString() })); } catch (FileSystemException e1) { VFSUtil.MessageBoxInfo(ex.getMessage()); } } } }); // New folder item = new ToolItem(toolBar, SWT.PUSH); item.setImage(iconCache.get(CFPluginImages.ICON_FOLDER_NEW)); //item.setText(getResourceString("tool.New.folder.text")); item.setToolTipText(getResourceString("tool.New.folder.tip")); item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { VFSUtil.newFolder(getCurrentDirectory()); } }); item = new ToolItem(toolBar, SWT.SEPARATOR); // Parent item = new ToolItem(toolBar, SWT.PUSH); item.setImage(iconCache.get(CFPluginImages.ICON_FOLDER_PARENT)); //item.setText(getResourceString("tool.Parent.tiptext")); item.setToolTipText(getResourceString("tool.Parent.tiptext")); item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { doParent(); } }); // Refresh item = new ToolItem(toolBar, SWT.PUSH); item.setImage(iconCache.get(CFPluginImages.ICON_REFRESH)); //item.setText(getResourceString("tool.Refresh.tiptext")); item.setToolTipText(getResourceString("tool.Refresh.tiptext")); item.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { doRefresh(); } }); return toolBar; }
From source file:org.cfeclipse.cfml.views.explorer.vfs.view.VFSView.java
/** * Creates the combo box view.// www .j ava 2s . c om * * @param parent the parent control */ private Control createComboView(Composite parent, Object layoutData) { combo = new Combo(parent, SWT.NONE); combo.setLayoutData(layoutData); combo.addSelectionListener(new SelectionAdapter() { public void widgetSelected(SelectionEvent e) { final FileObject[] roots = (FileObject[]) combo.getData(COMBODATA_ROOTS); if (roots == null) return; int selection = combo.getSelectionIndex(); if (selection >= 0 && selection < roots.length) { try { System.out.println("combo.widgetSelected " + roots[selection]); notifySelectedDirectory(roots[selection], roots[selection].getName().toString()); } catch (Exception ex) { System.err.println("createComboView.widgetSelected: " + ex); } } } public void widgetDefaultSelected(SelectionEvent e) { final String lastText = (String) combo.getData(COMBODATA_LASTTEXT); final String lastConnectionId = (String) combo.getData(COMBODATA_LASTCONNECTIONID); String text = combo.getText(); if (text == null) return; if (lastText != null && lastText.equals(text)) return; combo.setData(COMBODATA_LASTTEXT, text); try { FileObject file = resolveURI(text, lastConnectionId); if (file.exists()) notifySelectedDirectory(file, lastConnectionId); else { VFSUtil.MessageBoxInfo(getResourceString("file.not.found", new Object[] { file })); combo.setText(getCurrentDirectory().toString()); } } catch (FileSystemException ex) { System.err.println("createComboView::widgetDefaultSelected Error: " + ex); } } }); return combo; }
From source file:org.cfeclipse.cfml.views.explorer.vfs.view.VFSView.java
/** * Gets filesystem root entries/*w ww . ja v a2 s.c om*/ * @param fsManager * @return an array of Files corresponding to the root directories on the platform, * may be empty but not null */ FileObject[] getRoots(FileSystemManager fsManager) throws FileSystemException { /* * On JDK 1.22 only... */ // return File.listRoots(); FileObject[] roots = null; // FileObject[] newRequest = null; /* * On JDK 1.1.7 and beyond... * -- PORTABILITY ISSUES HERE -- */ if (System.getProperty("os.name").indexOf("Windows") != -1) { Vector /* of FileObject */ list = new Vector(); list.add(fsManager.resolveFile(DRIVE_A)); for (char i = 'c'; i <= 'z'; ++i) { //FileObject drive = new FileObject(i + ":" + FileName.SEPARATOR); FileObject drive = fsManager.resolveFile(i + ":" + FileName.SEPARATOR); if (VFSUtil.isDirectory(drive) && drive.exists()) { list.add(drive); if (initial && i == 'c') { setCurrentDirectory(drive); setCurrentConnectionId(drive.getName().toString()); initial = false; } } } roots = (FileObject[]) list.toArray(new FileObject[list.size()]); VFSUtil.sortFiles(roots); //return roots; } else { FileObject root = fsManager.resolveFile(FileName.SEPARATOR); if (initial) { setCurrentDirectory(root); setCurrentConnectionId(root.getName().toString()); initial = false; } roots = new FileObject[] { root }; } return roots; //newRequest; }
From source file:org.codehaus.cargo.container.spi.configuration.StandaloneConfigurationTest.java
/** * Test the creation of a config directory when the target directory does not exist yet. * @throws Exception If anything goes wrong. *//* w w w. ja v a 2s . c om*/ public void testCreateConfigDirWhenDirectoryDoesNotExist() throws Exception { String configDir = "ram:///cargo/testCreateConfigDirWhenDirectoryDoesNotExist"; FileObject configDirObject = VFS.getManager().resolveFile(configDir); FileObject timestampFileObject = configDirObject.resolveFile(".cargo"); configDirObject.delete(new AllFileSelector()); TestableAbstractStandaloneConfiguration configuration = new TestableAbstractStandaloneConfiguration( configDir); configuration.setFileHandler(new VFSFileHandler()); configuration.setupConfigurationDir(); assertTrue("Config dir should have been created", configDirObject.exists()); assertTrue("Cargo timestamp should have existed", timestampFileObject.exists()); }
From source file:org.codehaus.cargo.container.spi.configuration.StandaloneConfigurationTest.java
/** * Test the creation of a config directory when the target directory exists and is empty. * @throws Exception If anything goes wrong. *//*from w w w .j a v a 2 s . c om*/ public void testCreateConfigDirWhenDirectoryExistButIsEmpty() throws Exception { String configDir = "ram:///cargo/testCreateConfigDirWhenDirectoryExistButIsEmpty"; FileObject configDirObject = VFS.getManager().resolveFile(configDir); FileObject timestampFileObject = configDirObject.resolveFile(".cargo"); configDirObject.createFolder(); TestableAbstractStandaloneConfiguration configuration = new TestableAbstractStandaloneConfiguration( configDir); configuration.setFileHandler(new VFSFileHandler()); configuration.setupConfigurationDir(); assertTrue("Cargo timestamp should have existed", timestampFileObject.exists()); }
From source file:org.codehaus.cargo.util.VFSFileHandlerTest.java
/** * Test the {@link FileHandler#copyDirectory(java.lang.String, java.lang.String)} method. * @throws Exception If anything goes wrong. */// w w w. j a va 2s. c o m public void testCopyDirectory() throws Exception { String source = "ram:///some/path1"; this.fsManager.resolveFile(source).resolveFile("file1").createFile(); String target = "ram:///other/path2"; FileObject targetObject = this.fsManager.resolveFile(target); assertFalse(targetObject.exists()); assertFalse(this.fsManager.resolveFile("ram:///other/path2/file1").exists()); this.fileHandler.copyDirectory(source, target); assertTrue(targetObject.exists()); assertTrue(this.fsManager.resolveFile("ram:///other/path2/file1").exists()); }
From source file:org.codehaus.cargo.util.VFSFileHandlerTest.java
/** * Test the {@link FileHandler#copyFile(java.lang.String, java.lang.String)} method. * @throws Exception If anything goes wrong. *///from www .j ava 2s . c o m public void testCopyFile() throws Exception { String source = "ram:///some/path/file.war"; String target = "ram:///other/path/newfile.war"; FileObject sourceObject = this.fsManager.resolveFile(source); sourceObject.createFile(); FileObject targetObject = this.fsManager.resolveFile(target); assertFalse(targetObject.exists()); this.fileHandler.copyFile(source, target); assertTrue(targetObject.exists()); }
From source file:org.codehaus.cargo.util.VFSFileHandlerTest.java
/** * Test the {@link FileHandler#copyFile(java.lang.String, java.lang.String, boolean)} method. * @throws Exception If anything goes wrong. *///from ww w . jav a2 s . c o m public void testCopyFileOverwrite() throws Exception { String source = "ram:///some/path/file.war"; String target = "ram:///other/path/newfile.war"; FileObject sourceObject = this.fsManager.resolveFile(source); sourceObject.createFile(); FileObject targetObject = this.fsManager.resolveFile(target); assertFalse(targetObject.exists()); this.fileHandler.copyFile(source, target, true); assertTrue(targetObject.exists()); }