|
From: Robert E. <sky...@us...> - 2006-11-20 06:01:31
|
Update of /cvsroot/jcommander/plugins/org.jcommander.vfsextensions/src/org/jcommander/vfsextensions In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv13158/src/org/jcommander/vfsextensions Modified Files: VfsManagerExtension.java Log Message: Handling potential FileUtil initialization errors Index: VfsManagerExtension.java =================================================================== RCS file: /cvsroot/jcommander/plugins/org.jcommander.vfsextensions/src/org/jcommander/vfsextensions/VfsManagerExtension.java,v retrieving revision 1.21 retrieving revision 1.22 diff -C2 -d -r1.21 -r1.22 *** VfsManagerExtension.java 6 Aug 2006 10:33:34 -0000 1.21 --- VfsManagerExtension.java 20 Nov 2006 06:01:24 -0000 1.22 *************** *** 14,47 **** public class VfsManagerExtension { ! protected static Logger logger = Logger.getLogger(VfsManagerExtension.class); ! protected static final String LOCAL_FILE_URI = "file:/"; protected static VfsManagerExtension instance; protected FileSystemManager fileSystemManager; ! protected static FileUtil fileUtil = new FileUtil(); protected static FileSystemOptions defaultFsOpts; ! public static VfsManagerExtension getInstance() { if(instance == null) { instance = new VfsManagerExtension(); ! defaultFsOpts = new FileSystemOptions(); ! try { ! SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(defaultFsOpts, "no"); ! } catch (FileSystemException ex) { logger.error(ex,ex); ! } } ! return instance; } ! /** * Abstraction layer for getting the VFS file system manager. ! * * @return the file system manager to use ! * * @throws FileSystemException */ --- 14,55 ---- public class VfsManagerExtension { ! protected static Logger logger = Logger.getLogger(VfsManagerExtension.class); ! protected static final String LOCAL_FILE_URI = "file:/"; protected static VfsManagerExtension instance; protected FileSystemManager fileSystemManager; ! protected static FileUtil fileUtil; protected static FileSystemOptions defaultFsOpts; ! ! static { ! try { ! fileUtil = new FileUtil(); ! } catch(Exception ex) { ! logger.warn("Exception while initializing FileUtils", ex); ! } ! } ! public static VfsManagerExtension getInstance() { if(instance == null) { instance = new VfsManagerExtension(); ! defaultFsOpts = new FileSystemOptions(); ! try { ! SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(defaultFsOpts, "no"); ! } catch (FileSystemException ex) { logger.error(ex,ex); ! } } ! return instance; } ! /** * Abstraction layer for getting the VFS file system manager. ! * * @return the file system manager to use ! * * @throws FileSystemException */ *************** *** 49,60 **** return VFS.getManager(); } ! public FileObject resolveFile(String url) throws FileSystemException { return getManager().resolveFile(url,defaultFsOpts); } ! /** * Use this method instead of FileObject.getChildren() to bypass the VFS 1.0 caching issues. ! * * @param parent the directory for which to list its children * @return the updated list of children file objects --- 57,68 ---- return VFS.getManager(); } ! public FileObject resolveFile(String url) throws FileSystemException { return getManager().resolveFile(url,defaultFsOpts); } ! /** * Use this method instead of FileObject.getChildren() to bypass the VFS 1.0 caching issues. ! * * @param parent the directory for which to list its children * @return the updated list of children file objects *************** *** 65,72 **** return parent.getChildren(); } ! /** * Recursively computes statistics about the specified files. ! * * @param sourceFiles * @return --- 73,80 ---- return parent.getChildren(); } ! /** * Recursively computes statistics about the specified files. ! * * @param sourceFiles * @return *************** *** 76,80 **** return FileStats.computeStats(files); } ! /** * @param file The file to work with. --- 84,88 ---- return FileStats.computeStats(files); } ! /** * @param file The file to work with. *************** *** 83,110 **** public static String getExecutableName(FileObject file) { String executableName = null; ! if(file.getName() instanceof WindowsFileName) { executableName = ((WindowsFileName)file.getName()).getRootFile() + file.getName().getPath(); executableName = executableName.replace('/','\\'); ! } else if(file.getName() instanceof SmbFileName){ // TODO This is more like a hack. Check if a more elegant solution can be provided ! executableName = file.getName().toString().substring("smb:".length()); } else { executableName = file.getName().toString(); } ! return executableName; } ! public static boolean delete(FileObject file) throws FileSystemException { return delete(file, false); } ! public static boolean delete(FileObject file, boolean moveToTrash) throws FileSystemException { try { FileObject parent = file.getParent(); ! ! if(moveToTrash && (file instanceof LocalFile)) { fileUtil.recycle(new File(getExecutableName(file))); } --- 91,118 ---- public static String getExecutableName(FileObject file) { String executableName = null; ! if(file.getName() instanceof WindowsFileName) { executableName = ((WindowsFileName)file.getName()).getRootFile() + file.getName().getPath(); executableName = executableName.replace('/','\\'); ! } else if(file.getName() instanceof SmbFileName){ // TODO This is more like a hack. Check if a more elegant solution can be provided ! executableName = file.getName().toString().substring("smb:".length()); } else { executableName = file.getName().toString(); } ! return executableName; } ! public static boolean delete(FileObject file) throws FileSystemException { return delete(file, false); } ! public static boolean delete(FileObject file, boolean moveToTrash) throws FileSystemException { try { FileObject parent = file.getParent(); ! ! if(fileUtil != null && moveToTrash && (file instanceof LocalFile)) { fileUtil.recycle(new File(getExecutableName(file))); } *************** *** 112,120 **** file.delete(); } ! // TODO Hack to overcome the VFS architectural refresh bug file.close(); parent.close(); ! return true; } --- 120,128 ---- file.delete(); } ! // TODO Hack to overcome the VFS architectural refresh bug file.close(); parent.close(); ! return true; } *************** *** 124,132 **** } } ! public static boolean delete(FileObject file, DeleteListener deleteListener, boolean moveToTrash) throws FileSystemException { // TODO Add notifications try{ ! if(moveToTrash && (file instanceof LocalFile)) { fileUtil.recycle(new File(getExecutableName(file))); } --- 132,140 ---- } } ! public static boolean delete(FileObject file, DeleteListener deleteListener, boolean moveToTrash) throws FileSystemException { // TODO Add notifications try{ ! if(fileUtil != null && moveToTrash && (file instanceof LocalFile)) { fileUtil.recycle(new File(getExecutableName(file))); } *************** *** 135,142 **** } deleteListener.updateStatus(file, null, -1); ! // TODO Hack to overcome the VFS architectural refresh bug file.close(); ! return true; } --- 143,150 ---- } deleteListener.updateStatus(file, null, -1); ! // TODO Hack to overcome the VFS architectural refresh bug file.close(); ! return true; } *************** *** 157,166 **** for (int i = 0; i < sourceFiles.length; i++) { boolean success0 = delete(sourceFiles[i], deleteListener, moveToTrash); ! if(success) { success = success0; } } ! return success; } --- 165,174 ---- for (int i = 0; i < sourceFiles.length; i++) { boolean success0 = delete(sourceFiles[i], deleteListener, moveToTrash); ! if(success) { success = success0; } } ! return success; } *************** *** 169,173 **** copy(sourceFiles, targetDir, false, copyListener); } ! public static void copy(FileObject[] source, FileObject target, boolean deleteSourceFiles, CopyListener listener) throws FileSystemException{ // for each file to be copied --- 177,181 ---- copy(sourceFiles, targetDir, false, copyListener); } ! public static void copy(FileObject[] source, FileObject target, boolean deleteSourceFiles, CopyListener listener) throws FileSystemException{ // for each file to be copied *************** *** 180,189 **** /** * Duplicates the specified file or directory. ! * * @param sourceFiles * @param predefinedTargetFile * @param copyListener ! * ! * @throws FileSystemException */ public static void duplicate(FileObject sourceFile, FileObject predefinedTargetFile, CopyListener copyListener) throws FileSystemException { --- 188,197 ---- /** * Duplicates the specified file or directory. ! * * @param sourceFiles * @param predefinedTargetFile * @param copyListener ! * ! * @throws FileSystemException */ public static void duplicate(FileObject sourceFile, FileObject predefinedTargetFile, CopyListener copyListener) throws FileSystemException { *************** *** 192,198 **** } else { predefinedTargetFile.createFolder(); ! FileObject[] sourceFiles = VfsManagerExtension.getChildren(sourceFile); ! for(int i=0;i<sourceFiles.length;i++) { DefaultCopier.getInstance().copy(sourceFiles[i], predefinedTargetFile, false, copyListener); --- 200,206 ---- } else { predefinedTargetFile.createFolder(); ! FileObject[] sourceFiles = VfsManagerExtension.getChildren(sourceFile); ! for(int i=0;i<sourceFiles.length;i++) { DefaultCopier.getInstance().copy(sourceFiles[i], predefinedTargetFile, false, copyListener); *************** *** 208,212 **** try { FileObject[] children = currentParent.getChildren(); ! if(children.length > 0) { for(int i=0;i<children.length;i++) { --- 216,220 ---- try { FileObject[] children = currentParent.getChildren(); ! if(children.length > 0) { for(int i=0;i<children.length;i++) { *************** *** 221,228 **** return false; } ! return false; } ! /** * @param file --- 229,236 ---- return false; } ! return false; } ! /** * @param file *************** *** 232,236 **** return getFullPath(file.getName()); } ! /** * @param file --- 240,244 ---- return getFullPath(file.getName()); } ! /** * @param file *************** *** 240,251 **** 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. --- 248,259 ---- 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. *************** *** 254,258 **** String path = getFullPath(file); boolean localFile = false; ! /* Clean up local file prefixes */ if(path.startsWith(LOCAL_FILE_URI)) { --- 262,266 ---- String path = getFullPath(file); boolean localFile = false; ! /* Clean up local file prefixes */ if(path.startsWith(LOCAL_FILE_URI)) { *************** *** 260,281 **** 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; } --- 268,289 ---- 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; } |