ࡱ > [@ T" bjbj44 :8 Vi Vi * * * 8 b ~ 4 Ep " L
" , , , k k k }i i i i ' i l o $ gr R t o S g k S S o , , ; o " " " S D , , }i " S }i " j " /# " }a d @ 1i , P'~< * e v ii p 0 Ep Wf 9u '" 9u 1i 9u 1i 8 k > , " $ Z k k k o o $ * " * Homework 1 Due Wednesday, May 26, 2004
A Web Interface To XML Validation
In this lab you will write a web interface for XML document validation. The result will be similar to the web application found on a Brown University web site: HYPERLINK "http://www.stg.brown.edu/service/xmlvalid" http://www.stg.brown.edu/service/xmlvalid. That application was written a number of years ago and due to the advances in XML tools your problem will be a good deal simpler to solve than was theirs.
The index.html file
There will be exactly one HTML file in this application. It will be called index.html and will be placed under the directory ValidationApp/web. When your Tomcat site is accessed by a browser, the index.html file will request either a URL (from which your servlet application will fetch an XML document) or the text of an XML document with an imbedded DTD. If the XML document is fetched from a URL then the server that provides that document must also provide the DTD referenced within the document. In either case, your servlet will receive a document and a DTD.
The index.html document will contain HTML code that allows the user to click one of two buttons. These buttons allow the user to select the input source of the XML document. You will need to work with the HTML form tag. It is important that you use the HTTP POST method from both of these forms. So, your servlet will need to distinguish between the two forms. To do this, you are required to use hidden form fields. Feel free to consult any text on HTML for help.
Your HTML document need not contain Java script to validate the fields. We will assume that we have a friendly user and that they enter a correct URL and that they are able to copy and paste XML documents to the text areas on the screen.
The user, however, may present you with an invalid document. Its important that your application reports on these errors and does not crash.
The XMLHandler.java servlet
There will be exactly one servlet in this application. It will be called XMLHandler.java and will process all data from the browser with a doPost method.
The doPost method will use the getParameter method of the HTTP request object to determine if it should fetch the document from a URL or already has a copy of the document within the request. In either case, the servlet will build an InputSource object (see the course text, page 27, for more on the InputSource class). It will then create a Java object of class ValidateBean. ValidateBean will take the InputSource object, perform validation, and return a String object to the servlet. The servlet will embed this string in HTML and send it back to the browser.
ValidateBean.java
There will be one class that handles validation and it will be called ValidateBean.java. It is required that ValidateBean.java implements the org.xml.sax.ErrorHandler interface. It is also important that this class does not crash when reading an invalid XML document. All of its error handling will be written so that a string is returned to the XMLHandler servlet. ValidateBean.java will use JAXP to build a DOM tree and perform validation.
Test Cases
Your solution will be tested against the following documents:
HYPERLINK "http://dewdney.heinz.cmu.edu:8080/fpml2.0/example_1.xml" http://www.andrew.cmu.edu/~mm6/fpml2.0/example_1.xml a valid document
HYPERLINK "http://dewdney.heinz.cmu.edu:8080/fpml2.0/example_1A.xml" http://www.andrew.cmu.edu/~mm6/fpml2.0/example_1A.xml an invalid document
HYPERLINK "http://dewdney.heinz.cmu.edu:8080/fpml2.0/example_1B.xml" http://www.andrew.cmu.edu/~mm6/fpml2.0/example_1B.xml another invalid document
In the text box, your code will be tested against the following valid document:
]>
John Doe
John.Doe@foo.com
Bob Smith
Bob.Smith@foo.com
Alice Miller
And, in the text area, your code will be tested against the following invalid document:
]>
John Doe
John.Doe@foo.com
Bob Smith
Bob.Smith@foo.com
Alice Miller
Submission Requirements
In order for the grading effort to go smoothly, you must submit your solution in the following format. The points listed are for format issues. That is, if the format is not correct the grader will be able to deduct these points from your score.
A large envelope with your name, course, and assignment number on the front. (1 Point)
Within the envelope, a printout of three files: index.html, XMLHandler.java, ValidateBean.java. (6 Points)
An otherwise blank floppy disk containing exactly two directories: src and web. (2 points)
The src directory will contain ValidateBean.java and XMLHandler.java, (2 Points)
The web directory will contain the index.html file and the WEB-INF subdirectory. (2 Points)
The WEB-INF subdirectory will contain your web.xml file. (2 Points)
The remaining 85 points will be distributed as follows:
The index.html file contains two working forms, uses doPost for both and calls XMLHandler.java. (25 Points)
XMLHandler.java uses doPost for all of its work, fetches documents from anywhere on the web, is able to work with text being sent by the browser, is documented and calls ValidateBean to perform parsing and validation. XMLHandler generates appropriate HTML as a response. (25 Points)
ValidateBean.java is documented and implements the ErrorHandler interface in such a way as not to crash when parsing an invalid document. (35 Points)
An example execution:
95-733 Internet Technologies Carnegie Mellon University
PAGE
PAGE 2
& I L $ % & O P
w L W 8 9 б¥ИИИИvfS $h9^ h$ 0J CJ OJ QJ mHsH h*g 0J CJ OJ QJ mHsH !j h$ CJ OJ QJ U h9^ h$ CJ OJ QJ mHsH h$ 5CJ OJ QJ \ h$ 0J CJ OJ QJ !j h$ CJ OJ QJ Uj h$ CJ OJ QJ Uh$ CJ OJ QJ h$ OJ QJ h9^ CJ OJ QJ h$ CJ OJ QJ h# CJ OJ QJ ' J K L
7 8
A B v w E F $a$ $
&