Carnegie Mellon University 95-702 Organizational Communications and Distributed Object Technologies Lab 2 Due: Midnight, Tuesday October 10, 2006 There are four schedules found under the directory www.andrew.cmu.edu/~mm6/95-702/McCarthysSchedule. These schedules are named schedule1.xml, schedule2.xml and so on. There is also an XSDL document called schedule.xsd that contains the grammar for the schedule language. Write a program in Java called Scheduler. Scheduler will read a list of URL's from a local urlList.xml file and read n schedules from the web. It will build n DOM trees holding the schedules and attempt to find a common meeting time for each day of the week. You do not need to find every possible meeting time, simply try to find one meeting time for each day. For some days, it will be impossible to find a common meeting time. Your search should be an exhaustive one. As soon as you find a common time, your search for that day is complete. The amount of time for the meeting will depend on the data in the schedules. When running my solution on the first two schedules I get the following results: Checking for a Monday meeting Meeting scheduled for 13:0:0:14:0:0 Schedule for Monday found Checking for a Tuesday meeting Meeting scheduled for 19:0:0:19:30:0 Schedule for Tuesday found Checking for a Wednesday meeting Meeting scheduled for 9:0:0:10:0:0 Schedule for Wednesday found Checking for a Thursday meeting Meeting scheduled for 9:0:0:10:0:0 Schedule for Thursday found Checking for a Friday meeting Meeting scheduled for 9:0:0:12:0:0 Schedule for Friday found Checking for a Saturday meeting Meeting scheduled for 9:0:0:10:0:0 Schedule for Saturday found Checking for a Sunday meeting Meeting scheduled for 9:0:0:10:0:0 Schedule for Sunday found You are responsible for creating your own grammar for your URLList language. It should be simple but allow for many URL's to be listed. There will be partial credit assigned for serious attempts that do not quite work. Here is an approach along with some deliverables. These deliverables are not required but they will earn you some points if your final solution is incomplete. 1. Using the schedule.xsd and schedule.xml files as a guide, create a new language defined in URLList.xsd and validate your URLLIst.xml document against this grammar. Submit the xsd file and the xml file and a program that shows you have checked for validation. 2. Write a program that reads the list of URL's (into a single DOM tree) and fetches each document from the web. Your program would then display a schedule for each URL. 3. For a top grade, traverse these DOM trees and try to find a schedule for every day of the week. My solution is recursive but other approaches are possible. 4. For a full 100%, you must add something cool to this project. We will not define 'cool' but we know it when we see it. The following is a Java program that validates an XML instance against its schema. The schema document (.xsd) should be in the Same directory as the document. // Validate.java using Xerces import org.xml.sax.InputSource; import org.xml.sax.SAXParseException; import org.xml.sax.XMLReader; import org.xml.sax.helpers.DefaultHandler; import org.xml.sax.helpers.XMLReaderFactory; public class Validate extends DefaultHandler { public static boolean valid = true; public void error(SAXParseException exception) { System.out.println("Received notification of a recoverable error." + exception); valid = false; } public void fatalError(SAXParseException exception) { System.out.println("Received notification of a non-recoverable error."+ exception); valid = false; } public void warning(SAXParseException exception) { System.out.println("Received notification of a warning."+ exception); } public static void main (String argv []) { if (argv.length != 1) { System.err.println ("Usage: java Validate filename.xml"); System.exit (1); } try { // get a parser XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); // request validation reader.setFeature("http://xml.org/sax/features/validation",true); reader.setFeature("http://apache.org/xml/features/validation/schema",true); reader.setErrorHandler(new Validate()); // associate an InputSource object with the file name InputSource inputSource = new InputSource(argv[0]); // go ahead and parse reader.parse(inputSource); } catch(org.xml.sax.SAXException e) { System.out.println("Error in parsing " + e); valid = false; } catch(java.io.IOException e) { System.out.println("Error in I/O " + e); System.exit(0); } System.out.println("Valid Document is " + valid); } }