Java Reference
In-Depth Information
e.printStackTrace();
}
}
/**
* This method is called by main to check a link. After
* spidering through the site, the final list of bad links
* is displayed.
*
* @param url
* The URL to check for bad links.
* @throws WorkloadException
* @throws ClassNotFoundException
* @throws IllegalAccessException
* @throws InstantiationException
*
*/
public void check(URL url) throws InstantiationException,
IllegalAccessException,
ClassNotFoundException, WorkloadException {
SpiderOptions options = new SpiderOptions();
options.workloadManager =
MemoryWorkloadManager.class.getCanonicalName();
LinkReport report = new LinkReport();
Spider spider = new Spider(options, report);
spider.addURL(url, null, 1);
spider.process();
System.out.println(spider.getStatus());
if (report.getBad().size() > 0) {
System.out.println("Bad Links Found:");
for (String str : report.getBad()) {
System.out.println(str);
}
} else {
System.out.println("No bad links were found.");
}
}
}
All of the work performed by this recipe is accomplished inside of the checkLink
method. This method begins by creating a SpiderOptions object named options .
Then a MemoryWorkloadManager is specified. A MemoryWorkloadManager
will work with relatively large sites; however, if you are going to check an extremely large
site, you may want to use an SQLWorkloadManager .
Search WWH ::




Custom Search