package org.greenstone.gatherer.file; import java.io.File; import javax.swing.filechooser.FileSystemView; import org.greenstone.gatherer.Dictionary; import org.greenstone.gatherer.file.FileNode; import org.greenstone.gatherer.util.ArrayTools; public class FileSystem { static public FileNode getLocalFileSystem(FileSystemModel model) // static public FileNode getLocalFileSystem() { FileNode file_system_root = null; // Get all the available roots mounted on the filesystem File[] roots = File.listRoots(); if (roots == null) { return null; } // If there is just one root use it as the tree root (Linux) if (roots.length == 1) { file_system_root = new FileNode(roots[0], Dictionary.get("Tree.Root")); } // Otherwise build a dummy node which has the roots as children else { file_system_root = new FileNode(Dictionary.get("Tree.Root")); file_system_root.setModel(model); // Sort the roots into alphabetical order ArrayTools.sort(roots); for (int i = 0; i < roots.length; i++) { // Only add root if it isn't a floppy drive if (!FileSystemView.getFileSystemView().isFloppyDrive(roots[i])) { file_system_root.insert(new FileNode(roots[i])); } } } return file_system_root; } static public FileNode getUserHomeMapping() { // Generate a special mapping to the user home folder String home_folder_str = System.getProperty("user.home"); if (home_folder_str == null || home_folder_str.length() == 0) { return null; } File home_folder = new File(home_folder_str); String[] args = new String[1]; args[0] = home_folder.getName(); return new FileNode(home_folder, Dictionary.get("Tree.Home", args)); } }