import java.io.*; import java.net.*; import java.util.*; class WebPage { public WebPage(String url) { this.url = url; } public boolean isBad() throws IOException { return isBad(this.url); } // return a set of all the HTTP HREFs in this web page public Set getLinks() throws IOException { Set links = new Set(); HttpReader hr = new HttpReader(url); String link = new String(); link = hr.readLine(); System.out.println(" in WebPage::getLinks"); while (link!=null) { System.out.println(" link : " + link); links.addElement(link); link = hr.readLine(); } return links; } // return a set of all the HTTP HREFs in this web page that are bad links public Set getBadLinks() throws IOException { Set links = new Set(); HttpReader hr = new HttpReader(url); String link = hr.readLine(); while (link!=null) { if (isBad(link)) links.addElement(link); link = hr.readLine(); } return links; } public String getURL() { return url; } private boolean isBad(String url) throws IOException { WebReader wr = new WebReader(url); String s = wr.readLine().toUpperCase(); return s.indexOf("404")!=-1 || s.indexOf("403")!=-1 || s.indexOf("NOT FOUND")!=-1 || s.indexOf("FORBIDDEN")!=-1; } private String url; public static void main(String[] a) throws Exception { WebPage wp = new WebPage(a[0]); Set links = wp.getLinks(); Enumeration e = links.elements(); while (e.hasMoreElements()) System.out.println(wp.getURL()+"has this link:"+e.nextElement()); } } // class WebPage