|
From: Robert E. <sky...@us...> - 2006-04-05 20:34:50
|
Update of /cvsroot/jcommander/plugins/org.jcommander.vfsextensions/src/org/jcommander/vfsextensions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13666/src/org/jcommander/vfsextensions Modified Files: VfsManagerExtension.java Log Message: Fixed bug [ 1465312 ] Display user friendly VFS URLs Index: VfsManagerExtension.java =================================================================== RCS file: /cvsroot/jcommander/plugins/org.jcommander.vfsextensions/src/org/jcommander/vfsextensions/VfsManagerExtension.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** VfsManagerExtension.java 28 Mar 2006 08:23:50 -0000 1.18 --- VfsManagerExtension.java 5 Apr 2006 20:34:43 -0000 1.19 *************** *** 2,5 **** --- 2,6 ---- import java.io.File; + import java.util.regex.*; import org.apache.commons.vfs.*; *************** *** 7,10 **** --- 8,12 ---- import org.apache.commons.vfs.provider.sftp.SftpFileSystemConfigBuilder; import org.apache.commons.vfs.provider.smb.*; + import org.eclipse.core.runtime.*; import org.jcommander.vfsextensions.copy.*; import org.jcommander.vfsextensions.listener.*; *************** *** 13,16 **** --- 15,19 ---- public class VfsManagerExtension { + protected static final String LOCAL_FILE_URI = "file:/"; protected static VfsManagerExtension instance; protected FileSystemManager fileSystemManager; *************** *** 236,238 **** --- 239,281 ---- return fileName.getRootURI() + fileName.getPath(); } + + /** + * This method makes a Commons VFS URL safe and more readable. + * Passwords are cleared as well as local file name prefixes (file:///). + * Note that the resulting string might not be a valid VFS URL. + * + * TODO Improve the algorithm. + * + * @param file + * @return The processed file path. + */ + public static String getDisplayablePath(FileObject file) { + String path = getFullPath(file); + boolean localFile = false; + + /* Clean up local file prefixes */ + if(path.startsWith(LOCAL_FILE_URI)) { + path = path.substring(LOCAL_FILE_URI.length()); + localFile = true; + } + + while(path.startsWith("/")) { + path = path.substring(1); + } + + /* Remove passwords */ + path = path.replaceAll(":([^@:]*)@", "@"); + + /* Remove duplicate path separators */ + if(localFile) { + path = path.replaceAll("//", "/"); + } + + /* Make directory separators uniform */ + if(localFile && Platform.getOS().equals(Platform.OS_WIN32)) { + path = path.replaceAll("/", "\\\\"); + } + + return path; + } } |