Introduction

This assignment is in two parts, using SAX and DOM to parse and print a computer folder listing in HTML form.

You are provided with a small folder listing in the file Folder.xml. The top-level folder element has an attribute giving its name. Within this are files and subsidiary folders. Each has a name element and an optional attribute giving its extension (i.e. suffix). For example, the file analyser.exe has name analyser and extension .exe. A file has a size element, but a subsidiary folder omits this. A file or subsidiary folder has optional permission elements for who may use it. Each permission has a user attribute and a selection of permission values: r (read), w (write), x (execute).

Your goal is to use both SAX and DOM to create HTML output that looks like the following in a web browser. Data and Private are subsidiary folders and so have no size field. Folder Private and file test are not accessible and so have no permissions. See image.

Note that you are expected to create neatly indented and tabulated HTML. Also note that you will get no credit for code that literally outputs the HTML for this table. Your code must work with any input file in the style of Folder.xml. During development, you may find it helpful to temporarily set the value of variable writer (which prints HTML output) to System.out so you can immediately see what your code is doing. When your code is working, replace this with output to an HTML file.

The SAX Solution

Start by looking at the sax folder as supplied. Open the BlueJ project and study the Java files you are given. Also open Folder.xml in a text editor to see what you will have to read and output as HTML.

The SAX practical is rather similar to this part of the assignment, except that there is only one handler (for HTML). FolderSAX.java is complete and should not be changed. Look at the parse method in FolderSAX. You will see that it reads and parses Folder.xml. FolderHTML is registered as the handler for this, so you will get events as various XML elements are found.

FolderHTML.java is very incomplete and is the file you should work on. See the code provided for some hints about doing this. The total count is for all folder entries, while the file count is for those with size values. You will need take care over the following:

  • As well as elements and their contents you need to handle attributes. The heading and table start cannot be output until you start the top-level folder element and get its name. The extension attribute of a file needs to be saved for printing after the file name has been printed.
  • Because both size and permission elements are optional, empty cells must be created as necessary.
  • Zero or more permission elements need to be amalgamated into a single table cell.

The DOM Solution

Now look at the dom folder as supplied. Open the BlueJ project and study the Java file you are given. Note that Folder.xml is the same as for the SAX part of the assignment.

The DOM practical is rather similar to this part of the assignment. The structure of FolderDOM is given, but a number of methods are currently empty. Some you can fill in by adapting code from the DOM practical, but some you will need to write from scratch. In a number of cases you can use code that is similar to the SAX part of the assignment.

Start by looking at the main method. You will see that this loads Folder.xml. Computer folders implicitly contain a link to their parent folder. The DOM part of the assignment therefore differs in that the parent folder (name empty, extension ‘..’) is appended to the folder list after it has been read. The DOM tree you read must therefore be modified to append this entry. An HTML header is then output, followed by the body of the table and the HTML trailer. When your code is working, you should see the parent folder as the last entry in the table.

The file and total counts must be handled by XPath for this part of the assignment. The first needs to count all size children of the root node. The second needs to count all file children of the root node.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.