source: trunk/gli/src/org/greenstone/gatherer/file/FileSystem.java@ 8576

Last change on this file since 8576 was 8243, checked in by mdewsnip, 20 years ago

Removed all occurrences of classes explicitly importing other classes in the same package.

  • Property svn:keywords set to Author Date Id Revision
File size: 2.2 KB
Line 
1package org.greenstone.gatherer.file;
2
3import java.io.File;
4import javax.swing.filechooser.FileSystemView;
5import org.greenstone.gatherer.DebugStream;
6import org.greenstone.gatherer.Dictionary;
7import org.greenstone.gatherer.util.ArrayTools;
8import org.greenstone.gatherer.util.Utility;
9
10
11public class FileSystem
12{
13 static public FileNode getLocalFilespaceNode(FileSystemModel model)
14 {
15 FileNode file_system_root = null;
16
17 // Get all the available roots mounted on the filesystem
18 File[] roots = File.listRoots();
19 if (roots == null) {
20 return null;
21 }
22
23 // If there is just one root use it as the tree root (Linux)
24 if (roots.length == 1) {
25 file_system_root = new FileNode(roots[0], Dictionary.get("Tree.Root"));
26 }
27
28 // Otherwise build a dummy node which has the roots as children
29 else {
30 file_system_root = new FileNode(Dictionary.get("Tree.Root"));
31 file_system_root.setModel(model);
32
33 // Sort the roots into alphabetical order
34 ArrayTools.sort(roots);
35 for (int i = 0; i < roots.length; i++) {
36 // Only add root if it isn't a floppy drive
37 if (!FileSystemView.getFileSystemView().isFloppyDrive(roots[i])) {
38 file_system_root.insert(new FileNode(roots[i]));
39 }
40 }
41 }
42
43 return file_system_root;
44 }
45
46
47 static public FileNode getHomeFolderNode()
48 {
49 // Get the name of the OS we're running on
50 String os_name = System.getProperty("os.name");
51 if (os_name == null) {
52 return null;
53 }
54
55 // Make sure we're running on a multiuser OS where the idea of a "user home" is valid
56 DebugStream.println("Property os.name: " + os_name);
57 String os_name_lc = os_name.toLowerCase();
58 if (os_name_lc.equals("windows 95") || os_name_lc.equals("windows 98") || os_name_lc.equals("windows me")) {
59 return null;
60 }
61
62 // Get the user's home folder
63 String home_folder_str = System.getProperty("user.home");
64 if (home_folder_str == null || home_folder_str.length() == 0) {
65 return null;
66 }
67
68 // Generate a special mapping to the user home folder
69 File home_folder = new File(home_folder_str);
70 return new FileNode(home_folder, Dictionary.get("Tree.Home", home_folder.getName()));
71 }
72
73
74 static public FileNode getDownloadedFilesNode()
75 {
76 return new FileNode(Utility.getCacheDir(), "Downloaded Files");
77 }
78}
Note: See TracBrowser for help on using the repository browser.