views:

45

answers:

1

Hello

i am trying to create a web application that will allow users to upload files online, i am using gwt while using hibernate for database communication, i am able to upload file to a server , and store them on the server. but what i want is to associate the files with a user.

i want the user to be able to create folders and store a file in sub folders. my logic was to use the composite pattern to store folders and fileLocations with a user but i am am finding it difficult to implement this so i can show the files and folders within a gwt tree.

what would be the best way to implement a hierarchy of folders and information of the location of a file so it could be displayed in a gwt tree?

what i did have was a User would hold a reference to a root folder and then each sub folder could hold folders or fileLocations. i used the composite pattern to implement the file hierarchy, but when i want to display a the contents of a folder i need a for loop for each list. so i could a folder within a folder within a folder that would need 3 for loops to show the contents of my folders.

What is the best way to implement this file management system. so what do you guys think?

i would like something like this

Image of what i would like

A: 

I assume you aren't actually storing the directories and subdirectores as actual, real-life directories and subdirectories on the server? If you are, I would just have Java iterate the filesystem on the server and return a lightweight client-side representation of the files and folders it found to your GWT front-end for display. Apache Commons IO (specifically FileUtils.iterateFiles, or FileUtils.listFiles, just below it) can help you here.

If you're trying to emulate a file system in a database, you will probably want to do some research on how modern file systems store and look up files and how to implement and iterate over such data structures (you'll need some sort of loop or recursion). Some research into B-trees may help, as may this database of data structures (trees will be most helpful).

BinaryMuse