/* this belongs to the WebRaveler package */ package webraveler.plugin; import java.util.*; import webraveler.http.HTTPResponse; import webraveler.ravel.PluginAPI; import webraveler.vurl.PluginChangePref; import webraveler.vurl.PluginConfig; import webraveler.vurl.TextReplaceVURL; /** * A Web Raveler plugin to replace text (by matching a regular * expression) in the entity of any HTTPMessage with content-type * text/* (that is, any content-type which starts with "text/", not * the content-type that equals "text/*") * * @author The Web Raveler Development Squad * @version 1.0 */ public class GlossaryPlugin extends webraveler.ravel.RavelerPlugin { /* variables */ String fullURL; /* constructors */ /** * The default constructor, called from WebRaveler2.Raveler */ public GlossaryPlugin() { name = "GlossaryPlugin"; mimeTypes.add("text/html"); } /* methods */ /** * Start executing the plugin when given a response * * @param response an HTTPResponse with the response to be modified * @return an HTTPResponse object, the result of running the plugin on the input response */ public HTTPResponse execute(HTTPResponse response, Hashtable attributes) { /* get the attributes from the hash table */ String pattern = (String) attributes.get("pattern"); String replacement = (String) attributes.get("link"); response.getHtmlPage().replaceText(pattern,""+pattern+""); response.correctContentLength(); return response; } /** * Do the setup stuff with Raveler - banner setup, etc. * Put the plugin on Raveler's "plugin vector" */ public boolean initialize() { /* Add virtual urls for configuration */ String fullURL1; Vector attributes = new Vector(); attributes.add("pattern"); attributes.add("link"); PluginChangePref changePref = new webraveler.vurl.PluginChangePref("GlossaryPlugin"); fullURL1 = PluginAPI.addPermanentVirtualURL(ravel,name,"changePref",changePref); PluginConfig config = new PluginConfig("GlossaryPlugin",attributes,fullURL1); fullURL = PluginAPI.addConfigVirtualURL(ravel,name,config); TextReplaceVURL textReplace = new TextReplaceVURL(); fullURL = PluginAPI.addPluginVirtualURL(ravel,name,textReplace); return true; } /** * Terminate the Plugin - Hasta la vista, BABY! */ public void terminate() { } /** * Return the default configuration for this plugin as a hash table. * */ public void setDefaultAttributes() { attributes = new Hashtable(); attributes.put("pattern","Grinnell"); attributes.put("link","http://www.grinnell.edu"); } } //class RavelerPlugin