package webraveler.plugin; import java.util.*; import webraveler.html.HTMLPage2; import webraveler.http.HTTPRequest; import webraveler.http.HTTPResponse; import webraveler.ravel.PluginAPI; import webraveler.vurl.PluginChangePref; import webraveler.vurl.PluginConfig; /** * * Stephane's attempt to write a plugin * **/ public class InsertAtTopPlugin extends webraveler.ravel.RavelerPlugin { /* variables */ /*constructors*/ public InsertAtTopPlugin () { name = "InsertAtTopPlugin"; mimeTypes.add("text/html"); } /*methods*/ public void setDefaultAttributes () { attributes = new Hashtable(); attributes.put("InsertHtml","

I am taking over the Web! From the top!

"); } public boolean initialize () { String fullURL; Vector attributes = new Vector(); attributes.add("InsertHtml"); PluginChangePref changePref = new webraveler.vurl.PluginChangePref("InsertAtTopPlugin"); fullURL = PluginAPI.addPermanentVirtualURL(ravel,name,"changePref",changePref); PluginConfig config = new PluginConfig("InsertAtTopPlugin",attributes,fullURL); fullURL = PluginAPI.addConfigVirtualURL(ravel,name,config); return true; }//initialize() public HTTPRequest execute (HTTPRequest request, Hashtable attributes) { return request; }//execute() public HTTPResponse execute (HTTPResponse response, Hashtable attributes){ System.out.println("Executing InsertAtTop: "); String InsertHtml = (String) attributes.get("InsertHtml"); System.out.println("InsertAtTopPlugin: InsertHtml = '"+InsertHtml+"'"); response.getHtmlPage().insertAtTop(InsertHtml); /* Change the entityBytes of the passed HTTPResponse to the HTML page w/inserted text * at the top */ response.correctContentLength(); System.out.println("InsertAtTop: DONE"); return response; } //execute(HTTPResponse) public void terminate() { } // terminate() }//InsertAtTop