Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java only - THROUGH SERVLETS using eclipse Implement the folder functions: - Dis

ID: 3848848 • Letter: J

Question

Java only - THROUGH SERVLETS using eclipse

Implement the folder functions:

- Display the content of a folder (including folder navigation)

- Create a folder

- Edit a folder

- Delete a folder

Do not make a file on the disk, instead make a data model class like the following:

public class Folder {

Integer id;

String name;

Folder parent;

}

Then creating a new folder is simply creating a new object of this class, and all the other folder operations become operations on the objects of this class as well. For example, displaying the content of a folder is simply displaying the objects whose parent is the current folder object. Again, this is supposed to display on a webpage via servlets.

Specifically, when requested without any parameter, the main page of the application should display all the top-level folders. For example: [New Folder] I My Files Documents Temp A user may click on a folder to enter that folder, in which case the application displays the subfolders inside the selected folder. For example: My Files New Folder l Edit Folder l Delete Folderl Folder A Folder B Clicking on should take the user to the parent folder, and clicking on Delete Folder should delete the current folder and all its subfolders, and take the user back to the parent folder. Clicking on New Folder should let the user enter the name for a new folder, e.g New folder: Create And the new folder should be created inside the current folder Clicking Edit Folder should let the user change the name of the current folder, e.g. Edit folder: My Files Save Note that the edit form should be pre-filled with the name of the current folder

Explanation / Answer

public final void test() throws IOException, InterruptedException { final Path rootDir = Paths.get("path to your directory where the walk starts"); // Walk thru mainDir directory Files.walkFileTree(rootDir, new FileVisitor() { // First (minor) speed up. Compile regular expression pattern only one time. private Pattern pattern = Pattern.compile("^(.*?)"); @Override public FileVisitResult preVisitDirectory(Path path, BasicFileAttributes atts) throws IOException { boolean matches = pattern.matcher(path.toString()).matches(); // TODO: Put here your business logic when matches equals true/false return (matches)? FileVisitResult.CONTINUE:FileVisitResult.SKIP_SUBTREE; } @Override public FileVisitResult visitFile(Path path, BasicFileAttributes mainAtts) throws IOException { boolean matches = pattern.matcher(path.toString()).matches(); // TODO: Put here your business logic when matches equals true/false return FileVisitResult.CONTINUE; } @Override public FileVisitResult postVisitDirectory(Path path, IOException exc) throws IOException { // TODO Auto-generated method stub return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path path, IOException exc) throws IOException { exc.printStackTrace(); // If the root directory has failed it makes no sense to continue return path.equals(rootDir)? FileVisitResult.TERMINATE:FileVisitResult.CONTINUE; } }); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote