public abstract class VFS
extends java.lang.Object
Plugins can provide virtual file systems by defining entries in their
services.xml
files like so:
<SERVICE CLASS="org.gjt.sp.jedit.io.VFS" NAME="name"> new MyVFS(); </SERVICE>URLs of the form
name:path
will then be handled
by the VFS named name
.
See ServiceManager
for details.
Methods whose names are prefixed with "_" expect to be given a previously-obtained session object. A session must be obtained with this method:
That method should be called from the AWT (EDT) thread, unless the filesystem hasNON_AWT_SESSION_CAP
capability.
When done, the session must be disposed of using
_endVFSSession(Object,Component)
.
createVFSSession(String,Component)
- unless
NON_AWT_SESSION_CAP
capability is setinsert(View,Buffer,String)
load(View,Buffer,String)
save(View,Buffer,String)
getCapabilities()
returns a value reflecting the functionality
implemented by your VFS.Modifier and Type | Class and Description |
---|---|
static class |
VFS.DirectoryEntryCompare
Implementation of
Comparator
interface that compares VFSFile instances. |
Modifier and Type | Field and Description |
---|---|
static int |
BROWSE_CAP
Browse capability
|
static int |
CASE_INSENSITIVE_CAP
Case insensitive file system capability.
|
static int |
DELETE_CAP
Delete file capability.
|
static java.lang.String |
EA_MODIFIED
File last modified date.
|
static java.lang.String |
EA_SIZE
File size.
|
static java.lang.String |
EA_STATUS
File status (read only, read write, etc).
|
static java.lang.String |
EA_TYPE
File type.
|
static int |
IOBUFSIZE |
static int |
LOW_LATENCY_CAP
Low latency capability.
|
static int |
MKDIR_CAP
Make directory capability.
|
static int |
NON_AWT_SESSION_CAP
Sessions created outside Event Dispatching Thread -
file system capability.
|
static int |
READ_CAP
Read capability.
|
static int |
RENAME_CAP
Rename file capability.
|
static int |
WRITE_CAP
Write capability.
|
Modifier | Constructor and Description |
---|---|
protected |
VFS(java.lang.String name,
int caps)
Creates a new virtual filesystem.
|
protected |
VFS(java.lang.String name,
int caps,
java.lang.String[] extAttrs)
Creates a new virtual filesystem.
|
Modifier and Type | Method and Description |
---|---|
void |
_backup(java.lang.Object session,
java.lang.String path,
java.awt.Component comp)
Backs up the specified file.
|
java.lang.String |
_canonPath(java.lang.Object session,
java.lang.String path,
java.awt.Component comp)
Returns the canonical form of the specified path name.
|
java.io.InputStream |
_createInputStream(java.lang.Object session,
java.lang.String path,
boolean ignoreErrors,
java.awt.Component comp)
Creates an input stream.
|
java.io.OutputStream |
_createOutputStream(java.lang.Object session,
java.lang.String path,
java.awt.Component comp)
Creates an output stream.
|
boolean |
_delete(java.lang.Object session,
java.lang.String path,
java.awt.Component comp)
Deletes the specified URL.
|
void |
_endVFSSession(java.lang.Object session,
java.awt.Component comp)
Finishes the specified VFS session.
|
void |
_finishTwoStageSave(java.lang.Object session,
Buffer buffer,
java.lang.String path,
java.awt.Component comp)
Called after a file has been saved and we use twoStageSave (first saving to
another file).
|
VFSFile |
_getFile(java.lang.Object session,
java.lang.String path,
java.awt.Component comp)
Returns the specified directory entry.
|
java.lang.String[] |
_listDirectory(java.lang.Object session,
java.lang.String directory,
java.lang.String glob,
boolean recursive,
java.awt.Component comp)
A convinience method that matches file names against globs, and can
optionally list the directory recursively.
|
java.lang.String[] |
_listDirectory(java.lang.Object session,
java.lang.String directory,
java.lang.String glob,
boolean recursive,
java.awt.Component comp,
boolean skipBinary,
boolean skipHidden)
A convenience method that matches file names against globs, and can
optionally list the directory recursively.
|
java.lang.String[] |
_listDirectory(java.lang.Object session,
java.lang.String directory,
VFSFileFilter filter,
boolean recursive,
java.awt.Component comp,
boolean skipBinary,
boolean skipHidden)
A convenience method that filters the directory listing
according to a filter, and can optionally list the directory
recursively.
|
VFSFile[] |
_listFiles(java.lang.Object session,
java.lang.String directory,
java.awt.Component comp)
Lists the specified directory.
|
boolean |
_mkdir(java.lang.Object session,
java.lang.String directory,
java.awt.Component comp)
Creates a new directory with the specified URL.
|
boolean |
_rename(java.lang.Object session,
java.lang.String from,
java.lang.String to,
java.awt.Component comp)
Renames the specified URL.
|
void |
_saveComplete(java.lang.Object session,
Buffer buffer,
java.lang.String path,
java.awt.Component comp)
Called after a file has been saved.
|
java.lang.String |
constructPath(java.lang.String parent,
java.lang.String path)
Constructs a path from the specified directory and
file name component.
|
static boolean |
copy(ProgressObserver progress,
java.lang.String sourcePath,
java.lang.String targetPath,
java.awt.Component comp,
boolean canStop)
Copy a file to another using VFS.
|
static boolean |
copy(ProgressObserver progress,
java.lang.String sourcePath,
java.lang.String targetPath,
java.awt.Component comp,
boolean canStop,
boolean sendVFSUpdate)
Copy a file to another using VFS.
|
static boolean |
copy(ProgressObserver progress,
VFS sourceVFS,
java.lang.Object sourceSession,
java.lang.String sourcePath,
VFS targetVFS,
java.lang.Object targetSession,
java.lang.String targetPath,
java.awt.Component comp,
boolean canStop)
Copy a file to another using VFS.
|
static boolean |
copy(ProgressObserver progress,
VFS sourceVFS,
java.lang.Object sourceSession,
java.lang.String sourcePath,
VFS targetVFS,
java.lang.Object targetSession,
java.lang.String targetPath,
java.awt.Component comp,
boolean canStop,
boolean sendVFSUpdate)
Copy a file to another using VFS.
|
java.lang.Object |
createVFSSession(java.lang.String path,
java.awt.Component comp)
Creates a VFS session.
|
java.lang.Object |
createVFSSessionSafe(java.lang.String path,
java.awt.Component comp)
Same as
createVFSSession(java.lang.String, java.awt.Component) , but may be called fromy any
thread. |
int |
getCapabilities()
Returns the capabilities of this VFS.
|
static java.awt.Color |
getDefaultColorFor(java.lang.String name)
Returns color of the specified file name, by matching it against
user-specified regular expressions.
|
java.lang.String[] |
getExtendedAttributes()
Returns the extended attributes supported by this VFS.
|
java.lang.String |
getFileName(java.lang.String path)
Returns the file name component of the specified path.
|
java.lang.String |
getFilePath(java.lang.String vfsPath)
Returns the path component of the specified VFS path.
|
char |
getFileSeparator()
Returns the file separator used by this VFS.
|
java.lang.String |
getName()
Returns this VFS's name.
|
java.lang.String |
getParentOfPath(java.lang.String path)
Returns the parent of the specified path.
|
java.lang.String |
getTwoStageSaveName(java.lang.String path)
Returns a temporary file name based on the given path.
|
boolean |
insert(View view,
Buffer buffer,
java.lang.String path)
Inserts a file into the specified buffer.
|
boolean |
isMarkersFileSupported()
Returns if an additional markers file can be saved by this VFS.
|
boolean |
load(View view,
Buffer buffer,
java.lang.String path)
Loads the specified buffer.
|
void |
reloadDirectory(java.lang.String path)
Called before a directory is reloaded by the file system browser.
|
boolean |
save(View view,
Buffer buffer,
java.lang.String path)
Saves the specifies buffer.
|
public static final int READ_CAP
public static final int WRITE_CAP
public static final int BROWSE_CAP
browser.actions.xml
file in your plugin JAR, and
define plugin.class.browser-menu-item
or plugin.class.browser-menu
properties.
See EditPlugin
for details.public static final int DELETE_CAP
public static final int RENAME_CAP
public static final int MKDIR_CAP
public static final int LOW_LATENCY_CAP
public static final int CASE_INSENSITIVE_CAP
public static final int NON_AWT_SESSION_CAP
createVFSSession
is called on edt.
All systems that do not implement createVFSSession
should set it, but others may too.public static final java.lang.String EA_TYPE
public static final java.lang.String EA_STATUS
public static final java.lang.String EA_SIZE
public static final java.lang.String EA_MODIFIED
public static int IOBUFSIZE
protected VFS(java.lang.String name, int caps)
name
- The namecaps
- The capabilitiesprotected VFS(java.lang.String name, int caps, java.lang.String[] extAttrs)
name
- The namecaps
- The capabilitiesextAttrs
- The extended attributespublic java.lang.String getName()
vfs.name.label
property.public int getCapabilities()
public boolean isMarkersFileSupported()
true
.public java.lang.String[] getExtendedAttributes()
public java.lang.String getFileName(java.lang.String path)
path
- The pathpublic java.lang.String getFilePath(java.lang.String vfsPath)
super.getFilePath()
.vfsPath
- The VFS pathpublic java.lang.String getParentOfPath(java.lang.String path)
path
- The pathpublic java.lang.String constructPath(java.lang.String parent, java.lang.String path)
Unless you are writing a VFS, this method should not be called
directly. To ensure correct behavior, you must call
MiscUtilities.constructPath(String,String)
instead.
parent
- The parent directorypath
- The pathpublic char getFileSeparator()
public java.lang.String getTwoStageSaveName(java.lang.String path)
#name#save#
and then renames it to the original file. However some virtual file
systems might not support the #
character in filenames,
so this method permits the VFS to override this behavior.
If this method returns null
, two stage save will not
be used for that particular file (introduced in jEdit 4.3pre1).path
- The path namepublic void reloadDirectory(java.lang.String path)
public java.lang.Object createVFSSession(java.lang.String path, java.awt.Component comp)
NON_AWT_SESSION_CAP
capability. When set,
sessions may be obtained from any thread.path
- The path in questioncomp
- The component that will parent any dialog boxes shownpublic java.lang.Object createVFSSessionSafe(java.lang.String path, java.awt.Component comp)
createVFSSession(java.lang.String, java.awt.Component)
, but may be called fromy any
thread. It first checks the NON_AWT_SESSION_CAP
capability and enters EDT thread if necessary.public boolean load(View view, Buffer buffer, java.lang.String path)
view
- The viewbuffer
- The bufferpath
- The pathpublic boolean save(View view, Buffer buffer, java.lang.String path)
view
- The viewbuffer
- The bufferpath
- The pathpublic static boolean copy(ProgressObserver progress, VFS sourceVFS, java.lang.Object sourceSession, java.lang.String sourcePath, VFS targetVFS, java.lang.Object targetSession, java.lang.String targetPath, java.awt.Component comp, boolean canStop) throws java.io.IOException
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 WorkThreadsourceVFS
- the source VFSsourceSession
- the VFS sessionsourcePath
- the source path. It must be a file and must existstargetVFS
- the target VFStargetSession
- the target sessiontargetPath
- the target path.
If it is a path, it must exists, if it is a file, the parent must
existscomp
- comp The component that will parent error dialog boxescanStop
- could this copy be stopped ?java.io.IOException
- IOException If an I/O error occurspublic static boolean copy(ProgressObserver progress, VFS sourceVFS, java.lang.Object sourceSession, java.lang.String sourcePath, VFS targetVFS, java.lang.Object targetSession, java.lang.String targetPath, java.awt.Component comp, boolean canStop, boolean sendVFSUpdate) throws java.io.IOException
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 WorkThreadsourceVFS
- the source VFSsourceSession
- the VFS sessionsourcePath
- the source path. It must be a file and must existstargetVFS
- the target VFStargetSession
- the target sessiontargetPath
- the target path.
If it is a path, it must exists, if it is a file, the parent must
existscomp
- comp The component that will parent error dialog boxescanStop
- could this copy be stopped ?sendVFSUpdate
- true if you want to send a VFS update after the copy. False otherwise (if you do a lot
of copy)java.io.IOException
- IOException If an I/O error occurspublic static boolean copy(ProgressObserver progress, java.lang.String sourcePath, java.lang.String targetPath, java.awt.Component comp, boolean canStop, boolean sendVFSUpdate) throws java.io.IOException
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 WorkThreadsourcePath
- the source pathtargetPath
- the target pathcomp
- comp The component that will parent error dialog boxescanStop
- if true the copy can be stoppedsendVFSUpdate
- true if you want to send a VFS update after the copy. False otherwise (if you do a lot
of copy)java.io.IOException
- IOException If an I/O error occurspublic static boolean copy(ProgressObserver progress, java.lang.String sourcePath, java.lang.String targetPath, java.awt.Component comp, boolean canStop) throws java.io.IOException
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 WorkThreadsourcePath
- the source pathtargetPath
- the target pathcomp
- comp The component that will parent error dialog boxescanStop
- if true the copy can be stoppedjava.io.IOException
- IOException If an I/O error occurspublic boolean insert(View view, Buffer buffer, java.lang.String path)
view
- The viewbuffer
- The bufferpath
- The pathpublic java.lang.String _canonPath(java.lang.Object session, java.lang.String path, java.awt.Component comp) throws java.io.IOException
~
might be expanded to the user's home directory.session
- The sessionpath
- The pathcomp
- The component that will parent error dialog boxesjava.io.IOException
- if an I/O error occurredpublic java.lang.String[] _listDirectory(java.lang.Object session, java.lang.String directory, java.lang.String glob, boolean recursive, java.awt.Component comp) throws java.io.IOException
session
- The sessiondirectory
- The directory. Note that this must be a full
URL, including the host name, path name, and so on. The
username and password (if needed by the VFS) is obtained from the
session instance.glob
- Only file names matching this glob will be returnedrecursive
- If true, subdirectories will also be listed.comp
- The component that will parent error dialog boxesjava.io.IOException
- if an I/O error occurredpublic java.lang.String[] _listDirectory(java.lang.Object session, java.lang.String directory, java.lang.String glob, boolean recursive, java.awt.Component comp, boolean skipBinary, boolean skipHidden) throws java.io.IOException
session
- The sessiondirectory
- The directory. Note that this must be a full
URL, including the host name, path name, and so on. The
username and password (if needed by the VFS) is obtained from the
session instance.glob
- Only file names matching this glob will be returnedrecursive
- If true, subdirectories will also be listed.comp
- The component that will parent error dialog boxesskipBinary
- ignore binary files (do not return them).
This will slow down the process since it will open the filesskipHidden
- skips hidden files, directories, and
backup files. Ignores any file beginning with . or #, or ending with ~
or .bakjava.io.IOException
- if an I/O error occurredpublic java.lang.String[] _listDirectory(java.lang.Object session, java.lang.String directory, VFSFileFilter filter, boolean recursive, java.awt.Component comp, boolean skipBinary, boolean skipHidden) throws java.io.IOException
session
- The sessiondirectory
- The directory. Note that this must be a full
URL, including the host name, path name, and so on. The
username and password (if needed by the VFS) is obtained from the
session instance.filter
- The VFSFileFilter
to use for filtering.recursive
- If true, subdirectories will also be listed.comp
- The component that will parent error dialog boxesskipBinary
- ignore binary files (do not return them).
This will slow down the process since it will open the filesskipHidden
- skips hidden files, directories, and
backup files. Ignores any file beginning with . or #, or ending with ~
or .bakjava.io.IOException
- if an I/O error occurredpublic VFSFile[] _listFiles(java.lang.Object session, java.lang.String directory, java.awt.Component comp) throws java.io.IOException
session
- The sessiondirectory
- The directory. Note that this must be a full
URL, including the host name, path name, and so on. The
username and password (if needed by the VFS) is obtained from the
session instance.comp
- The component that will parent error dialog boxesjava.io.IOException
- if an I/O error occurredpublic VFSFile _getFile(java.lang.Object session, java.lang.String path, java.awt.Component comp) throws java.io.IOException
session
- The session get it with createVFSSession(String, Component)
path
- The pathcomp
- The component that will parent error dialog boxesjava.io.IOException
- if an I/O error occurredpublic boolean _delete(java.lang.Object session, java.lang.String path, java.awt.Component comp) throws java.io.IOException
session
- The VFS sessionpath
- The pathcomp
- The component that will parent error dialog boxesjava.io.IOException
- if an I/O error occurspublic boolean _rename(java.lang.Object session, java.lang.String from, java.lang.String to, java.awt.Component comp) throws java.io.IOException
session
- The VFS sessionfrom
- The old pathto
- The new pathcomp
- The component that will parent error dialog boxesjava.io.IOException
- if an I/O error occurspublic boolean _mkdir(java.lang.Object session, java.lang.String directory, java.awt.Component comp) throws java.io.IOException
session
- The VFS sessiondirectory
- The directorycomp
- The component that will parent error dialog boxesjava.io.IOException
- if an I/O error occurspublic void _backup(java.lang.Object session, java.lang.String path, java.awt.Component comp) throws java.io.IOException
session
- The VFS sessionpath
- The pathcomp
- The component that will parent error dialog boxesjava.io.IOException
- if an I/O error occurspublic java.io.InputStream _createInputStream(java.lang.Object session, java.lang.String path, boolean ignoreErrors, java.awt.Component comp) throws java.io.IOException
session
- the VFS sessionpath
- The pathignoreErrors
- If true, file not found errors should be
ignoredcomp
- The component that will parent error dialog boxesnull
if there was a problemjava.io.IOException
- If an I/O error occurspublic java.io.OutputStream _createOutputStream(java.lang.Object session, java.lang.String path, java.awt.Component comp) throws java.io.IOException
session
- the VFS sessionpath
- The pathcomp
- The component that will parent error dialog boxesjava.io.IOException
- If an I/O error occurspublic void _saveComplete(java.lang.Object session, Buffer buffer, java.lang.String path, java.awt.Component comp) throws java.io.IOException
session
- The VFS sessionbuffer
- The bufferpath
- The path the buffer was saved to (can be different from
Buffer.getPath()
if the user invoked the
Save a Copy As command, for example).comp
- The component that will parent error dialog boxesjava.io.IOException
- If an I/O error occurspublic void _finishTwoStageSave(java.lang.Object session, Buffer buffer, java.lang.String path, java.awt.Component comp) throws java.io.IOException
session
- The VFS sessionbuffer
- The bufferpath
- The path the buffer was saved to (can be different from
Buffer.getPath()
if the user invoked the
Save a Copy As command, for example).comp
- The component that will parent error dialog boxesjava.io.IOException
- If an I/O error occurspublic void _endVFSSession(java.lang.Object session, java.awt.Component comp) throws java.io.IOException
session
- The VFS sessioncomp
- The component that will parent error dialog boxesjava.io.IOException
- if an I/O error occurredpublic static java.awt.Color getDefaultColorFor(java.lang.String name)