package webraveler.plugin; import java.util.*; import webraveler.html.HTMLPage2; import webraveler.http.HTTPRequest; import webraveler.ravel.PluginAPI; import webraveler.ravel.RavelerError; import webraveler.ravel.RavelerErrorException; import webraveler.ravel.RavelerWarning; /** * @author Web Raveler2 Development Squad * * A simple plugin to test RavelerError and RavelerWarning */ public class ErrorPlugin extends webraveler.ravel.RavelerPlugin { String uriString; /** * */ public ErrorPlugin() { name = "ErrorPlugin"; mimeTypes.add("text/html"); } /** * */ public boolean initialize() { return true; } /** * */ public void setDefaultAttributes() { attributes = new Hashtable(); } /** * */ public HTTPRequest execute(HTTPRequest request, Hashtable attributes) { uriString = request.uriString(); return request; } public webraveler.http.HTTPResponse execute(webraveler.http.HTTPResponse response, Hashtable configuration) throws webraveler.ravel.RavelerWarningException, webraveler.ravel.RavelerErrorException { //Just test error/warning handling abilities HTMLPage2 htmlpage = response.getHtmlPage(); htmlpage.insertAtTop("
ErrorPlugin: Trying to modify response...
"); Hashtable headers = new Hashtable(); headers.put("content-type","text/html"); webraveler.http.HTTPResponse modResponse = new webraveler.http.HTTPResponse("HTTP/1.0",200,"OK",htmlpage,headers); /* Construct a RavelerError */ RavelerError err = new RavelerError(100); PluginAPI.printError(ravel,name,err,uriString); throw new RavelerErrorException(err); // /* Construct a RavelerWarning */ // webraveler.ravel.RavelerWarning warn = new RavelerWarning(100); // PluginAPI.printWarning(ravel,name,warn,uriString); // throw new webraveler.ravel.RavelerWarningException(warn,modResponse); } /** * */ public void terminate() { } }