/** * Inserts a file into the specified buffer. The default implementation posts an I/O request to * the I/O thread. * * @param view The view * @param buffer The buffer * @param path The path */ public boolean insert(View view, Buffer buffer, String path) { if ((getCapabilities() & READ_CAP) == 0) { VFSManager.error(view, path, "vfs.not-supported.load", new String[] {name}); return false; } Object session = createVFSSession(path, view); if (session == null) return false; VFSManager.runInWorkThread(new BufferInsertRequest(view, buffer, session, this, path)); return true; } // }}}
/** * Rebuild the parent view after a directory has been loaded. * * @param node * @param path * @param directory */ public void directoryLoaded(Object node, String path, java.util.List<VFSFile> directory) { // {{{ If reloading root, update parent directory list if (node == null) { DefaultListModel parentList = new DefaultListModel(); String parent = path; for (; ; ) { VFS _vfs = VFSManager.getVFSForPath(parent); VFSFile file = null; if (_vfs instanceof FileVFS) { Object session = _vfs.createVFSSession(path, browser); try { file = _vfs._getFile(session, parent, browser); if (file != null) { file.setName(_vfs.getFileName(parent)); } } catch (IOException e) { Log.log(Log.ERROR, this, e, e); } } if (file == null) { // create a DirectoryEntry manually // instead of using _vfs._getFile() // since so many VFS's have broken // implementations of this method file = new VFSFile(_vfs.getFileName(parent), parent, parent, VFSFile.DIRECTORY, 0L, false); } /*parentList.insertElementAt(new VFSFile( _vfs.getFileName(parent), parent,parent, VFSFile.DIRECTORY, 0L,false),0);*/ parentList.insertElementAt(file, 0); String newParent = _vfs.getParentOfPath(parent); if (newParent == null || MiscUtilities.pathsEqual(parent, newParent)) break; else parent = newParent; } parentDirectories.setModel(parentList); int index = parentList.getSize() - 1; parentDirectories.setSelectedIndex(index); parentDirectories.ensureIndexIsVisible(index); } // }}} table.setDirectory(VFSManager.getVFSForPath(path), node, directory, tmpExpanded); } // }}}
// {{{ loadDirectory() method public void loadDirectory( final Object node, String path, final boolean addToHistory, final Runnable delayedAWTTask) { path = MiscUtilities.constructPath(browser.getDirectory(), path); VFS vfs = VFSManager.getVFSForPath(path); Object session = vfs.createVFSSession(path, this); if (session == null) { if (delayedAWTTask != null) ThreadUtilities.runInDispatchThread(delayedAWTTask); return; } if (node == null) { parentDirectories.setListData(new Object[] {new LoadingPlaceholder()}); } final Object[] loadInfo = new Object[2]; Runnable awtRunnable = new Runnable() { public void run() { browser.directoryLoaded(node, loadInfo, addToHistory); if (delayedAWTTask != null) delayedAWTTask.run(); } }; ThreadUtilities.runInBackground( new ListDirectoryBrowserTask(browser, session, vfs, path, loadInfo, awtRunnable)); } // }}}
/** * Saves the specifies buffer. The default implementation posts an I/O request to the I/O thread. * * @param view The view * @param buffer The buffer * @param path The path */ public boolean save(View view, Buffer buffer, String path) { if ((getCapabilities() & WRITE_CAP) == 0) { VFSManager.error(view, path, "vfs.not-supported.save", new String[] {name}); return false; } Object session = createVFSSession(path, view); if (session == null) return false; /* When doing a 'save as', the path to save to (path) * will not be the same as the buffer's previous path * (buffer.getPath()). In that case, we want to create * a backup of the new path, even if the old path was * backed up as well (BACKED_UP property set) */ if (!path.equals(buffer.getPath())) buffer.unsetProperty(Buffer.BACKED_UP); VFSManager.runInWorkThread(new BufferSaveRequest(view, buffer, session, this, path)); return true; } // }}}
/** * Loads the specified buffer. The default implementation posts an I/O request to the I/O thread. * * @param view The view * @param buffer The buffer * @param path The path */ public boolean load(View view, Buffer buffer, String path) { if ((getCapabilities() & READ_CAP) == 0) { VFSManager.error(view, path, "vfs.not-supported.load", new String[] {name}); return false; } Object session = createVFSSession(path, view); if (session == null) return false; if ((getCapabilities() & WRITE_CAP) == 0) buffer.setReadOnly(true); BufferIORequest request = new BufferLoadRequest(view, buffer, session, this, path); if (buffer.isTemporary()) // this makes HyperSearch much faster request.run(); else VFSManager.runInWorkThread(request); return true; } // }}}
/** * Copy a file to another using VFS. * * @param progress the progress observer. It could be null if you don't want to monitor progress. * If not null you should probably launch this command in a WorkThread * @param sourcePath the source path * @param targetPath the target path * @param comp comp The component that will parent error dialog boxes * @param canStop if true the copy can be stopped * @return true if the copy was successful * @throws IOException IOException If an I/O error occurs * @since jEdit 4.3pre3 */ public static boolean copy( ProgressObserver progress, String sourcePath, String targetPath, Component comp, boolean canStop) throws IOException { VFS sourceVFS = VFSManager.getVFSForPath(sourcePath); Object sourceSession = sourceVFS.createVFSSession(sourcePath, comp); if (sourceSession == null) { Log.log( Log.WARNING, VFS.class, "Unable to get a valid session from " + sourceVFS + " for path " + sourcePath); return false; } VFS targetVFS = VFSManager.getVFSForPath(targetPath); Object targetSession = targetVFS.createVFSSession(targetPath, comp); if (targetSession == null) { Log.log( Log.WARNING, VFS.class, "Unable to get a valid session from " + targetVFS + " for path " + targetPath); return false; } return copy( progress, sourceVFS, sourceSession, sourcePath, targetVFS, targetSession, targetPath, comp, canStop); } // }}}
// {{{ DirectoryEntry constructor public DirectoryEntry( String name, String path, String deletePath, int type, long length, boolean hidden) { this.name = name; this.path = path; this.deletePath = deletePath; this.symlinkPath = path; this.type = type; this.length = length; this.hidden = hidden; if (path != null) { // maintain backwards compatibility VFS vfs = VFSManager.getVFSForPath(path); canRead = ((vfs.getCapabilities() & READ_CAP) != 0); canWrite = ((vfs.getCapabilities() & WRITE_CAP) != 0); } } // }}}
/** * Copy a file to another using VFS. * * @param progress the progress observer. It could be null if you don't want to monitor progress. * If not null you should probably launch this command in a WorkThread * @param sourceVFS the source VFS * @param sourceSession the VFS session * @param sourcePath the source path * @param targetVFS the target VFS * @param targetSession the target session * @param targetPath the target path * @param comp comp The component that will parent error dialog boxes * @param canStop could this copy be stopped ? * @return true if the copy was successful * @throws IOException IOException If an I/O error occurs * @since jEdit 4.3pre3 */ public static boolean copy( ProgressObserver progress, VFS sourceVFS, Object sourceSession, String sourcePath, VFS targetVFS, Object targetSession, String targetPath, Component comp, boolean canStop) throws IOException { if (progress != null) progress.setStatus("Initializing"); InputStream in = null; OutputStream out = null; try { VFSFile sourceVFSFile = sourceVFS._getFile(sourceSession, sourcePath, comp); if (sourceVFSFile == null) throw new FileNotFoundException(sourcePath); if (progress != null) { progress.setMaximum(sourceVFSFile.getLength()); } VFSFile targetVFSFile = targetVFS._getFile(targetSession, targetPath, comp); if (targetVFSFile.getType() == VFSFile.DIRECTORY) { if (targetVFSFile.getPath().equals(sourceVFSFile.getPath())) return false; targetPath = MiscUtilities.constructPath(targetPath, sourceVFSFile.getName()); } in = new BufferedInputStream( sourceVFS._createInputStream(sourceSession, sourcePath, false, comp)); out = new BufferedOutputStream(targetVFS._createOutputStream(targetSession, targetPath, comp)); boolean copyResult = IOUtilities.copyStream(IOBUFSIZE, progress, in, out, canStop); VFSManager.sendVFSUpdate(targetVFS, targetPath, true); return copyResult; } finally { IOUtilities.closeQuietly(in); IOUtilities.closeQuietly(out); } }
/** * Creates an output stream. This method is called from the I/O thread. * * @param session the VFS session * @param path The path * @param comp The component that will parent error dialog boxes * @exception IOException If an I/O error occurs * @since jEdit 2.7pre1 */ public OutputStream _createOutputStream(Object session, String path, Component comp) throws IOException { VFSManager.error(comp, path, "vfs.not-supported.save", new String[] {name}); return null; } // }}}
/** * Creates an input stream. This method is called from the I/O thread. * * @param session the VFS session * @param path The path * @param ignoreErrors If true, file not found errors should be ignored * @param comp The component that will parent error dialog boxes * @return an inputstream or <code>null</code> if there was a problem * @exception IOException If an I/O error occurs * @since jEdit 2.7pre1 */ public InputStream _createInputStream( Object session, String path, boolean ignoreErrors, Component comp) throws IOException { VFSManager.error(comp, path, "vfs.not-supported.load", new String[] {name}); return null; } // }}}
/** @deprecated Use <code>_listFiles()</code> instead. */ @Deprecated public DirectoryEntry[] _listDirectory(Object session, String directory, Component comp) throws IOException { VFSManager.error(comp, directory, "vfs.not-supported.list", new String[] {name}); return null; } // }}}