I need an html-based directory chooser which should have access to the file system.
For now we can't use JSF, we can't use applet
(jfileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY)),
there is no way in struts taglibs or JSP because of security concerns, I couldn't
find any component for it on internet.
So I mixed a recursive function for browsing the file system and struts layout
MenuComponent to create a tree view component as the following:
The following snippet comes in action
menu = new MenuComponent();
roots= File.listRoots();
menu.setName("treeview");
dirProcessor(roots,menu);
LayoutUtils.addMenuIntoSession(request, menu);
//--------------------
And here is the recursive method:
File[] children;
FileFilter fileFilter;
File dir;
fileFilter = new FileFilter(){
public boolean accept(File file){
return file.isDirectory();
}
} ;
if(list!=null){
for(int i=1;i<list.length;i++){
MenuComponent child = new MenuComponent();
child.setTitle(list[i].getName());
parent.addMenuComponent(child);
dir = new File(""+list[i]);
children = dir.listFiles(fileFilter);
if(children!=null){
for(int j=0;j<children.length;j++){
dirProcessor(children[j].listFiles(fileFilter),child) ;
}
}
}
}
It works correctly, but the recursive call is SO slow! It takes a very long time to process all the nested directories and the treeview displayed after 2 minutes,
Do you know a better way than this or any other way for speeding up?