@Override public Property getItemProperty(Object id) { return getContainerProperty(file, id); }
@Override public Collection<String> getItemPropertyIds() { return getContainerPropertyIds(); }
/** * Constructs a new <code>FileSystemContainer</code> with the specified root * and recursivity status. * * @param root * the root file for the new file-system container. * @param filter * the Filename filter to limit the files in container. * @param recursive * should the container recursively contain subdirectories. */ public FilesystemContainer(File root, FilenameFilter filter, boolean recursive) { this(root); this.setFilter(filter); setRecursive(recursive); }
/** * Internal method to recursively calculate the number of files under a root * directory. * * @param directory * the root to start counting from. */ private int getFileCounts(File directory) { File[] l; if (filter != null) { l = directory.listFiles(filter); } else { l = directory.listFiles(); } if (l == null) { return 0; } int ret = l.length; for (File f : l) { if (f.isDirectory()) { ret += getFileCounts(f); } } return ret; }
/** * Internal recursive method to add the files under the specified directory * to the collection. * * @param col * the collection where the found items are added * @param f * the root file where to start adding files */ private void addItemIds(Collection<File> col, File f) { File[] l; if (filter != null) { l = f.listFiles(filter); } else { l = f.listFiles(); } if (l == null) { // File.listFiles returns null if File does not exist or if there // was an IO error (permission denied) return; } final List<File> ll = Arrays.asList(l); Collections.sort(ll); for (final File lf : ll) { col.add(lf); if (lf.isDirectory()) { addItemIds(col, lf); } } }
/** * Constructs a new <code>FileSystemContainer</code> with the specified file * as the root of the filesystem. The files are included recursively. * * @param root * the root file for the new file-system container. * @param recursive * should the container recursively contain subdirectories. */ public FilesystemContainer(File root, boolean recursive) { this(root); setRecursive(recursive); }
@Override public Collection<File> getItemIds() { Collection<File> files = new ArrayList<File>(super.getItemIds()); Iterator<File> it = files.iterator(); while (it.hasNext()) { File f = it.next(); if (f.isDirectory() || excludeList.contains(f.getName())) { it.remove(); } } return Collections.unmodifiableCollection(files); }
return new MethodProperty<Object>(getType(propertyId), new FileItem((File) itemId), FILEITEM_NAME, null); return new MethodProperty<Object>(getType(propertyId), new FileItem((File) itemId), FILEITEM_ICON, null); return new MethodProperty<Object>(getType(propertyId), new FileItem((File) itemId), FILEITEM_SIZE, null); return new MethodProperty<Object>(getType(propertyId), new FileItem((File) itemId), FILEITEM_LASTMODIFIED, null);
int counts = 0; for (File f : roots) { counts += getFileCounts(f);
@Override public Collection<File> getItemIds() { if (recursive) { final Collection<File> col = new ArrayList<File>(); for (File root : roots) { addItemIds(col, root); } return Collections.unmodifiableCollection(col); } else { File[] f; if (roots.length == 1) { if (filter != null) { f = roots[0].listFiles(filter); } else { f = roots[0].listFiles(); } } else { f = roots; } if (f == null) { return Collections .unmodifiableCollection(new LinkedList<File>()); } final List<File> l = Arrays.asList(f); Collections.sort(l); return Collections.unmodifiableCollection(l); } }
/** * Constructs a new <code>FileSystemContainer</code> with the specified file * as the root of the filesystem. * * @param root * the root file for the new file-system container. * @param extension * the Filename extension (w/o separator) to limit the files in * container. * @param recursive * should the container recursively contain subdirectories. */ public FilesystemContainer(File root, String extension, boolean recursive) { this(root); this.setFilter(extension); setRecursive(recursive); }