Prev | Current Page 559 | Next

Frank Zammetti

"Practical DWR 2 Projects"


public List listDirectories(final String inStartDirectory) throws Exception {
directory = inStartDirectory;
List results = new ArrayList();
try {
// Walk the directory tree, starting at inStartDirectory. The results
// list will be populated as the walking is done.
walk(new File(inStartDirectory), results);
} catch (Exception e) {
e.printStackTrace();
throw new Exception("Exception occurred: " + e);
}
return results;
} // End listDirectories().
First, the directory to list subdirectories for is stored in the class-level directories field.
This is necessary because the handleDirectory() method will need this information, but we
have no other way to pass it directly to it. (A ThreadLocal might have been another answer,
perhaps even a better one, but it also complicates the code a little more than I??™d like.) Next, a
new List is instantiated, which will be what gets returned ultimately from this method. Then,
the walk() method is called, which is inherited from the DirectoryWalker class. Its execution
triggers the calls to handleDirectory() that we??™ve discussed before. Finally, the List is
returned, and our job here is done!
listRoots() Method
The listRoots() method is called from the client during execution of the init() method of
the Fileman JavaScript class:
public List listRoots() throws Exception {
try {
File[] roots = File.


Pages:
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571