/* this belongs to the WebRaveler package */ package webraveler.vurl; import java.util.*; import webraveler.http.HTTPRequest; import webraveler.http.HTTPResponse; import webraveler.ravel.Raveler; /** * A VURL that displays the errors and warnings reported while raveling a page * * @author The Web Raveler Development Squad * @version 1.0 */ public class ErrorsVURL implements VURL { Hashtable errors; Hashtable warnings; /** * Contructs a VURL with an empty page */ public ErrorsVURL () { errors = new Hashtable(); warnings = new Hashtable(); } // ErrorsVURL() /** * */ public HTTPResponse resolveVURL(String username, String query, HTTPRequest request,Raveler ravel) { String responseString = "
"+Raveler.ravelerCSS+""; responseString += "Raveled page: "+query+"
"; /* Check if errors occurred */ if (errors.containsKey(query)) { /* Display the errors */ responseString += "Errors
"; String err = (String) errors.get(query); responseString += err; } //if /* Check if warnings occurred */ else if (warnings.containsKey(query)) { /* Display the warnings */ responseString += "Warnings
"; String warn = (String) warnings.get(query); responseString += warn; } //else if /* Otherwise, display a message reporting that no errors/warnings occurred */ else responseString += "No errors or warnings were reported.
"; return new HTTPResponse("HTTP/1.0",200,"OK",responseString.getBytes(),new Hashtable()); } // resolveVURL /** * Adds an error message * * @param error A string containing the error message to display * @param url A string containing the url where the error occurred */ public void addError (String error, String url) { if (errors.containsKey(url)) { /* Add the error message to error string */ String err = (String) errors.get(url); err += error; errors.put(url,err); } //if else { /* Add an entry in the hash table for the url */ errors.put(url,error); } //else } //addError(String,String) /** * Adds an warning message * * @param warning A string containing the error message to display * @param url A string containing the url where the error occurred */ public void addWarning (String warning, String url) { if (warnings.containsKey(url)) { /* Add the error message to error string */ String warn = (String) warnings.get(url); warn += warning; warnings.put(url,warn); } //if else { /* Add an entry in the hash table for the url */ warnings.put(url,warning); } //else } //addError(String,String) } // class ErrorsVURL