⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vfs.java

📁 开源的java 编辑器源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		throws IOException	{		Log.log(Log.DEBUG,this,"Listing " + directory);		ArrayList files = new ArrayList(100);		RE filter;		try		{			filter = new RE(MiscUtilities.globToRE(glob),				RE.REG_ICASE);		}		catch(REException e)		{			Log.log(Log.ERROR,this,e);			return null;		}		_listDirectory(session,new ArrayList(),files,directory,filter,			recursive,comp);		String[] retVal = (String[])files.toArray(new String[files.size()]);		Arrays.sort(retVal,new MiscUtilities.StringICaseCompare());		return retVal;	} //}}}	//{{{ _listDirectory() method	/**	 * Lists the specified directory. 	 * @param session The session	 * @param directory 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.	 * @param comp The component that will parent error dialog boxes	 * @exception IOException if an I/O error occurred	 * @since jEdit 2.7pre1	 */	public DirectoryEntry[] _listDirectory(Object session, String directory,		Component comp)		throws IOException	{		VFSManager.error(comp,directory,"vfs.not-supported.list",new String[] { name });		return null;	} //}}}	//{{{ _getDirectoryEntry() method	/**	 * Returns the specified directory entry.	 * @param session The session	 * @param path The path	 * @param comp The component that will parent error dialog boxes	 * @exception IOException if an I/O error occurred	 * @return The specified directory entry, or null if it doesn't exist.	 * @since jEdit 2.7pre1	 */	public DirectoryEntry _getDirectoryEntry(Object session, String path,		Component comp)		throws IOException	{		return null;	} //}}}	//{{{ DirectoryEntry class	/**	 * A directory entry.	 * @since jEdit 2.6pre2	 */	public static class DirectoryEntry implements Serializable	{		//{{{ File types		public static final int FILE = 0;		public static final int DIRECTORY = 1;		public static final int FILESYSTEM = 2;		//}}}		//{{{ Instance variables		public String name;		public String path;		/**		 * @since jEdit 4.2pre5		 */		public String symlinkPath;		public String deletePath;		public int type;		public long length;		public boolean hidden;		public boolean canRead;		public boolean canWrite;		//}}}		//{{{ DirectoryEntry constructor		/**		 * @since jEdit 4.2pre2		 */		public DirectoryEntry()		{		} //}}}		//{{{ 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);			}		} //}}}		protected boolean colorCalculated;		protected Color color;		//{{{ getExtendedAttribute() method		/**		 * Returns the value of an extended attribute. Note that this		 * returns formatted strings (eg, "10 Mb" for a file size of		 * 1048576 bytes). If you need access to the raw data, access		 * fields and methods of this class.		 * @param name The extended attribute name		 * @since jEdit 4.2pre1		 */		public String getExtendedAttribute(String name)		{			if(name.equals(EA_TYPE))			{				switch(type)				{				case FILE:					return jEdit.getProperty("vfs.browser.type.file");				case DIRECTORY:					return jEdit.getProperty("vfs.browser.type.directory");				case FILESYSTEM:					return jEdit.getProperty("vfs.browser.type.filesystem");				default:					throw new IllegalArgumentException();				}			}			else if(name.equals(EA_STATUS))			{				if(canRead)				{					if(canWrite)						return jEdit.getProperty("vfs.browser.status.rw");					else						return jEdit.getProperty("vfs.browser.status.ro");				}				else				{					if(canWrite)						return jEdit.getProperty("vfs.browser.status.append");					else						return jEdit.getProperty("vfs.browser.status.no");				}			}			else if(name.equals(EA_SIZE))			{				if(type != FILE)					return null;				else					return MiscUtilities.formatFileSize(length);			}			else				return null;		} //}}}		//{{{ getColor() method		public Color getColor()		{			if(!colorCalculated)			{				colorCalculated = true;				color = getDefaultColorFor(name);			}			return color;		} //}}}		//{{{ toString() method		public String toString()		{			return name;		} //}}}	} //}}}	//{{{ _delete() method	/**	 * Deletes the specified URL.	 * @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 boolean _delete(Object session, String path, Component comp)		throws IOException	{		return false;	} //}}}	//{{{ _rename() method	/**	 * Renames the specified URL. Some filesystems might support moving	 * URLs between directories, however others may not. Do not rely on	 * this behavior.	 * @param session The VFS session	 * @param from The old path	 * @param to The new path	 * @param comp The component that will parent error dialog boxes	 * @exception IOException if an I/O error occurs	 * @since jEdit 2.7pre1	 */	public boolean _rename(Object session, String from, String to,		Component comp) throws IOException	{		return false;	} //}}}	//{{{ _mkdir() method	/**	 * Creates a new directory with the specified URL.	 * @param session The VFS session	 * @param directory The directory	 * @param comp The component that will parent error dialog boxes	 * @exception IOException if an I/O error occurs	 * @since jEdit 2.7pre1	 */	public boolean _mkdir(Object session, String directory, Component comp)		throws IOException	{		return false;	} //}}}	//{{{ _backup() method	/**	 * Backs up the specified file. This should only be overriden by	 * the local filesystem VFS.	 * @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 3.2pre2	 */	public void _backup(Object session, String path, Component comp)		throws IOException	{	} //}}}	//{{{ _createInputStream() method	/**	 * 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	 * @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;	} //}}}	//{{{ _createOutputStream() method	/**	 * 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;	} //}}}	//{{{ _saveComplete() method	/**	 * Called after a file has been saved.	 * @param session The VFS session	 * @param buffer The buffer	 * @param path The path the buffer was saved to (can be different from	 * {@link org.gjt.sp.jedit.Buffer#getPath()} if the user invoked the	 * <b>Save a Copy As</b> command, for example).	 * @param comp The component that will parent error dialog boxes	 * @exception IOException If an I/O error occurs	 * @since jEdit 4.1pre9	 */	public void _saveComplete(Object session, Buffer buffer, String path,		Component comp) throws IOException {} //}}}	//{{{ _endVFSSession() method	/**	 * Finishes the specified VFS session. This must be called	 * after all I/O with this VFS is complete, to avoid leaving	 * stale network connections and such.	 * @param session The VFS session	 * @param comp The component that will parent error dialog boxes	 * @exception IOException if an I/O error occurred	 * @since jEdit 2.7pre1	 */	public void _endVFSSession(Object session, Component comp)		throws IOException	{	} //}}}	//{{{ getDefaultColorFor() method	/**	 * Returns color of the specified file name, by matching it against	 * user-specified regular expressions.	 * @since jEdit 4.0pre1	 */	public static Color getDefaultColorFor(String name)	{		synchronized(lock)		{			if(colors == null)				loadColors();			for(int i = 0; i < colors.size(); i++)			{				ColorEntry entry = (ColorEntry)colors.elementAt(i);				if(entry.re.isMatch(name))					return entry.color;			}			return null;		}	} //}}}	//{{{ DirectoryEntryCompare class	/**	 * Implementation of {@link org.gjt.sp.jedit.MiscUtilities.Compare}	 * interface that compares {@link VFS.DirectoryEntry} instances.	 * @since jEdit 4.2pre1	 */	public static class DirectoryEntryCompare implements MiscUtilities.Compare	{		private boolean sortIgnoreCase, sortMixFilesAndDirs;		/**		 * Creates a new <code>DirectoryEntryCompare</code>.		 * @param sortMixFilesAndDirs If false, directories are		 * put at the top of the listing.		 * @param sortIgnoreCase If false, upper case comes before		 * lower case.		 */		public DirectoryEntryCompare(boolean sortMixFilesAndDirs,			boolean sortIgnoreCase)		{			this.sortMixFilesAndDirs = sortMixFilesAndDirs;			this.sortIgnoreCase = sortIgnoreCase;		}		public int compare(Object obj1, Object obj2)		{			VFS.DirectoryEntry file1 = (VFS.DirectoryEntry)obj1;			VFS.DirectoryEntry file2 = (VFS.DirectoryEntry)obj2;			if(!sortMixFilesAndDirs)			{				if(file1.type != file2.type)					return file2.type - file1.type;			}			return MiscUtilities.compareStrings(file1.name,				file2.name,sortIgnoreCase);		}	} //}}}	//{{{ Private members	private String name;	private int caps;	private String[] extAttrs;	private static Vector colors;	private static Object lock = new Object();	//{{{ Class initializer	static	{		EditBus.addToBus(new EBComponent()		{			public void handleMessage(EBMessage msg)			{				if(msg instanceof PropertiesChanged)				{					synchronized(lock)					{						colors = null;					}				}			}		});	} //}}}	//{{{ _listDirectory() method	private void _listDirectory(Object session, ArrayList stack,		ArrayList files, String directory, RE glob, boolean recursive,		Component comp) throws IOException	{		if(stack.contains(directory))		{			Log.log(Log.ERROR,this,				"Recursion in _listDirectory(): "				+ directory);			return;		}		else			stack.add(directory);		VFS.DirectoryEntry[] _files = _listDirectory(session,directory,			comp);		if(_files == null || _files.length == 0)			return;		for(int i = 0; i < _files.length; i++)		{			VFS.DirectoryEntry file = _files[i];			if(file.type == VFS.DirectoryEntry.DIRECTORY				|| file.type == VFS.DirectoryEntry.FILESYSTEM)			{				if(recursive)				{					// resolve symlinks to avoid loops					String canonPath = _canonPath(session,file.path,comp);					if(!MiscUtilities.isURL(canonPath))						canonPath = MiscUtilities.resolveSymlinks(canonPath);					_listDirectory(session,stack,files,						canonPath,glob,recursive,						comp);				}			}			else			{				if(!glob.isMatch(file.name))					continue;				Log.log(Log.DEBUG,this,file.path);				files.add(file.path);			}		}	} //}}}	//{{{ loadColors() method	private static void loadColors()	{		synchronized(lock)		{			colors = new Vector();			if(!jEdit.getBooleanProperty("vfs.browser.colorize"))				return;			String glob;			int i = 0;			while((glob = jEdit.getProperty("vfs.browser.colors." + i + ".glob")) != null)			{				try				{					colors.addElement(new ColorEntry(						new RE(MiscUtilities.globToRE(glob)),						jEdit.getColorProperty(						"vfs.browser.colors." + i + ".color",						Color.black)));				}				catch(REException e)				{					Log.log(Log.ERROR,VFS.class,"Invalid regular expression: "						+ glob);					Log.log(Log.ERROR,VFS.class,e);				}				i++;			}		}	} //}}}	//{{{ ColorEntry class	static class ColorEntry	{		RE re;		Color color;		ColorEntry(RE re, Color color)		{			this.re = re;			this.color = color;		}	} //}}}	//}}}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -