45 46 protected ShellFolder parent; 47 48 /** 49 * Create a file system shell folder from a file 50 */ 51 ShellFolder(ShellFolder parent, String pathname) { 52 super((pathname != null) ? pathname : "ShellFolder"); 53 this.parent = parent; 54 } 55 56 /** 57 * @return Whether this is a file system shell folder 58 */ 59 public boolean isFileSystem() { 60 return (!getPath().startsWith("ShellFolder")); 61 } 62 63 /** 64 * This method must be implemented to make sure that no instances 65 * of <code>ShellFolder</code> are ever serialized. If <code>isFileSystem()</code> returns 66 * <code>true</code>, then the object should be representable with an instance of 67 * <code>java.io.File</code> instead. If not, then the object is most likely 68 * depending on some internal (native) state and cannot be serialized. 69 * 70 * @return a java.io.File replacement object, or null 71 * if no suitable replacement can be found. 72 */ 73 protected abstract Object writeReplace() throws java.io.ObjectStreamException; 74 75 /** 76 * Returns the path for this object's parent, 77 * or <code>null</code> if this object does not name a parent 78 * folder. 79 * 80 * @return the path as a String for this object's parent, 81 * or <code>null</code> if this object does not name a parent 82 * folder 83 * 84 * @see java.io.File#getParent() 85 * @since 1.4 86 */ 87 public String getParent() { 88 if (parent == null && isFileSystem()) { 89 return super.getParent(); 90 } 91 if (parent != null) { 92 return (parent.getPath()); 93 } else { 94 return null; 95 } 96 } 97 98 /** 99 * Returns a File object representing this object's parent, 100 * or <code>null</code> if this object does not name a parent 101 * folder. 102 * 103 * @return a File object representing this object's parent, 104 * or <code>null</code> if this object does not name a parent 105 * folder 106 * 107 * @see java.io.File#getParentFile() 108 * @since 1.4 109 */ 110 public File getParentFile() { 111 if (parent != null) { 112 return parent; 113 } else if (isFileSystem()) { 114 return super.getParentFile(); 115 } else { 116 return null; 117 } 118 } 119 120 public File[] listFiles() { 121 return listFiles(true); 122 } 123 124 public File[] listFiles(boolean includeHiddenFiles) { 233 } 234 235 invoker = shellFolderManager.createInvoker(); 236 } 237 238 /** 239 * Return a shell folder from a file object 240 * @exception FileNotFoundException if file does not exist 241 */ 242 public static ShellFolder getShellFolder(File file) throws FileNotFoundException { 243 if (file instanceof ShellFolder) { 244 return (ShellFolder)file; 245 } 246 if (!file.exists()) { 247 throw new FileNotFoundException(); 248 } 249 return shellFolderManager.createShellFolder(file); 250 } 251 252 /** 253 * @param key a <code>String</code> 254 * @return An Object matching the string <code>key</code>. 255 * @see ShellFolderManager#get(String) 256 */ 257 public static Object get(String key) { 258 return shellFolderManager.get(key); 259 } 260 261 /** 262 * Does <code>dir</code> represent a "computer" such as a node on the network, or 263 * "My Computer" on the desktop. 264 */ 265 public static boolean isComputerNode(File dir) { 266 return shellFolderManager.isComputerNode(dir); 267 } 268 269 /** 270 * @return Whether this is a file system root directory 271 */ 272 public static boolean isFileSystemRoot(File dir) { 273 return shellFolderManager.isFileSystemRoot(dir); 274 } 275 276 /** 277 * Canonicalizes files that don't have symbolic links in their path. 278 * Normalizes files that do, preserving symbolic links from being resolved. 279 */ 280 public static File getNormalizedFile(File f) throws IOException { 281 File canonical = f.getCanonicalFile(); 282 if (f.equals(canonical)) { | 45 46 protected ShellFolder parent; 47 48 /** 49 * Create a file system shell folder from a file 50 */ 51 ShellFolder(ShellFolder parent, String pathname) { 52 super((pathname != null) ? pathname : "ShellFolder"); 53 this.parent = parent; 54 } 55 56 /** 57 * @return Whether this is a file system shell folder 58 */ 59 public boolean isFileSystem() { 60 return (!getPath().startsWith("ShellFolder")); 61 } 62 63 /** 64 * This method must be implemented to make sure that no instances 65 * of {@code ShellFolder} are ever serialized. If {@code isFileSystem()} returns 66 * {@code true}, then the object should be representable with an instance of 67 * {@code java.io.File} instead. If not, then the object is most likely 68 * depending on some internal (native) state and cannot be serialized. 69 * 70 * @return a java.io.File replacement object, or null 71 * if no suitable replacement can be found. 72 */ 73 protected abstract Object writeReplace() throws java.io.ObjectStreamException; 74 75 /** 76 * Returns the path for this object's parent, 77 * or {@code null} if this object does not name a parent 78 * folder. 79 * 80 * @return the path as a String for this object's parent, 81 * or {@code null} if this object does not name a parent 82 * folder 83 * 84 * @see java.io.File#getParent() 85 * @since 1.4 86 */ 87 public String getParent() { 88 if (parent == null && isFileSystem()) { 89 return super.getParent(); 90 } 91 if (parent != null) { 92 return (parent.getPath()); 93 } else { 94 return null; 95 } 96 } 97 98 /** 99 * Returns a File object representing this object's parent, 100 * or {@code null} if this object does not name a parent 101 * folder. 102 * 103 * @return a File object representing this object's parent, 104 * or {@code null} if this object does not name a parent 105 * folder 106 * 107 * @see java.io.File#getParentFile() 108 * @since 1.4 109 */ 110 public File getParentFile() { 111 if (parent != null) { 112 return parent; 113 } else if (isFileSystem()) { 114 return super.getParentFile(); 115 } else { 116 return null; 117 } 118 } 119 120 public File[] listFiles() { 121 return listFiles(true); 122 } 123 124 public File[] listFiles(boolean includeHiddenFiles) { 233 } 234 235 invoker = shellFolderManager.createInvoker(); 236 } 237 238 /** 239 * Return a shell folder from a file object 240 * @exception FileNotFoundException if file does not exist 241 */ 242 public static ShellFolder getShellFolder(File file) throws FileNotFoundException { 243 if (file instanceof ShellFolder) { 244 return (ShellFolder)file; 245 } 246 if (!file.exists()) { 247 throw new FileNotFoundException(); 248 } 249 return shellFolderManager.createShellFolder(file); 250 } 251 252 /** 253 * @param key a {@code String} 254 * @return An Object matching the string {@code key}. 255 * @see ShellFolderManager#get(String) 256 */ 257 public static Object get(String key) { 258 return shellFolderManager.get(key); 259 } 260 261 /** 262 * Does {@code dir} represent a "computer" such as a node on the network, or 263 * "My Computer" on the desktop. 264 */ 265 public static boolean isComputerNode(File dir) { 266 return shellFolderManager.isComputerNode(dir); 267 } 268 269 /** 270 * @return Whether this is a file system root directory 271 */ 272 public static boolean isFileSystemRoot(File dir) { 273 return shellFolderManager.isFileSystemRoot(dir); 274 } 275 276 /** 277 * Canonicalizes files that don't have symbolic links in their path. 278 * Normalizes files that do, preserving symbolic links from being resolved. 279 */ 280 public static File getNormalizedFile(File f) throws IOException { 281 File canonical = f.getCanonicalFile(); 282 if (f.equals(canonical)) { |