// CSE 143, Winter 2010, Marty Stepp // Homework 3: HTML Validator // // Instructor-provided code. // This program tests your HTML validator object on any file or URL you want. // // When it prompts you for a file name, if you type a simple string such // as "test1.html" (without the quotes) it will just look on your hard disk // in the same directory as your code or Eclipse project. // // If you type a string such as "http://www.google.com/index.html", it will // connect to that URL and download the HTML content from it. import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.io.IOException; import java.net.URL; import java.net.MalformedURLException; import java.util.Scanner; import java.util.Queue; public class ValidatorMain { public static void main(String[] args) throws IOException { HtmlValidator validator = new HtmlValidator(); String pageText = ""; Scanner console = new Scanner(System.in); String choice = "s"; while (true) { if (choice.startsWith("s")) { // prompt for page, then download it if it's a URL System.out.print("Page URL or file name (blank for empty): "); String url = console.nextLine().trim(); if (url.length() > 0) { if (isURL(url)) { System.out.println("Downloading from " + url + " ..."); } try { pageText = readCompleteFileOrURL(url); Queue tags = HtmlTag.tokenize(pageText); // create the HTML validator validator = new HtmlValidator(tags); } catch (MalformedURLException mfurle) { System.out.println("Badly formatted URL: " + url); } catch (FileNotFoundException fnfe) { System.out.println("Web page or file not found: " + url); } catch (IOException ioe) { System.out.println("I/O error: " + ioe.getMessage()); } } else { pageText = "No page text (starting from empty queue)"; validator = new HtmlValidator(); } } else if (choice.startsWith("a")) { System.out.print("What tag (such as or

)? "); String tagText = console.nextLine().trim(); boolean isOpenTag = !tagText.contains("