/* this belongs to the WebRaveler package */ package webraveler.ravel; import java.io.IOException; import java.util.Enumeration; import java.util.Hashtable; import java.util.Random; import webraveler.html.HTMLPage2; import webraveler.http.HTTPRequest; import webraveler.http.HTTPResponse; import webraveler.proxy.ProxyClient; import webraveler.vurl.UnravelVURL; import webraveler.vurl.VURL; /** * Implementation of Web Raveler * * @author The Web Raveler Development Squad * @version 1.0 */ public class Raveler { /* variables */ // public static String WEBRAVELER_HOME = "/home/schmitzc/Summer_2004/WR_v3/WebRaveler2/"; public static String WEBRAVELER_HOME = "/home/rebelsky/public_html/Glimmer/WebRaveler/WR/WR_v3/WebRaveler2/"; private UserStack userStack; private PluginStack pluginStack; private VURLStack vurlStack; public static final String ravelerCSS = ""; String bannerHTML; private String bannerCSS; String bannerScript; Hashtable bannerImages; boolean error; private int requestCnt; Random rng; //private Vector loggedIn; //private static int port; //private int realmCount; /* constructors */ public Raveler() { /* Initialize the plugin vector*/ System.out.println("Raveler: Loading the plugins."); pluginStack = new PluginStack(this); /* Initialize the virtual URL Hashtable */ System.out.println("Raveler: Loading Virtual URLs"); vurlStack = new VURLStack(this); /* Initialize the plugins */ System.out.println("Raveler: Initializing the plugins"); pluginStack.initializePlugins(); /* Initialize the users vector */ userStack = new UserStack(this); error = false; requestCnt = 0; rng = new Random(); } // Raveler /* methods */ /** * Gets an HTTPResponse directly from the server * * @param request an HTTPRequest * @param response an HTTPResponse containing the unraveled response from the server */ public HTTPResponse getOriginResponse(HTTPRequest request) { HTTPResponse response; ProxyClient proxy = new ProxyClient(request); /* try to get the response from a ProxyClient */ try { response = proxy.getResponse(); }catch(IOException ioe) { System.out.println("GetUnframedDocumentVURL: error getting response from ProxyClient."); response = Raveler.generateErrorResponse(); } //catch return response; } /** * Process the given HTTP Request, and return the * HTTP Response that results * * @return the resulting HTTPResponse */ public HTTPResponse handleRequest(RavelerUser user,HTTPRequest request) { if ( getVurlStack().isVirtualURL(request.uriString() ) ) { return processVirtualURL(user,request); } else { return framedResponse(user,request); } }//HTTPResponse handleRequest(HTTPRequest) public HTTPResponse framedResponse( RavelerUser currentUser, HTTPRequest request ) { HTTPResponse response = new HTTPResponse(); System.out.println("RavelerManager: Generating Raveler Banner"); String frameHTML = new String(""); String bannerHTML = new String("
Web Raveler";
errorPage += " encountered an error processing your request.
";
errorPage += "
Please check the URL and try again."; errorPage += "
"; errorPage += "(Web Raveler v1.0. The Web Raveler Development Squad, 2004.)"; errorPage += "
"; //put the response together response = new HTTPResponse( httpVersion, statusCode, reasonPhrase, new HTMLPage2(errorPage), headers ); //make the content-length header accurate response.correctContentLength(); return response; }//generateErrorResponse /** * */ public HTTPResponse handleErrors(HTTPResponse response, String url) { if (error) { System.out.println("Raveler: Handling errors..."); response.getHtmlPage().insertAtTop("Error(s)/Warning(s) were reported while raveling this page.
"); response.correctContentLength(); error=false; //old stuff // HTMLPage2 htmlpage = new HTMLPage2(pageHTML); // htmlpage.insertAtTop(); // response.entityText = htmlpage.toString(); // // // /* Change the entityBytes of the passed HTTPResponse to the HTML page w/inserted text // * at the top */ // response.entityBytes = response.entityText.getBytes(); // response.setHeader("content-length", new String(""+response.entityBytes.length)); } //error return response; } //handleErrors(String) /** * Return true if the proposed username and password match * those we read from the users.txt file. * */ public boolean checkCredentials(String username, String password) { boolean DEBUG = false; String realPass = userStack.getUserPassword(username); if ( realPass != null ) { if ( DEBUG ) { System.out.println("username = "+username); System.out.println("password = "+password); System.out.println("realpass = "+realPass); } return realPass.equals(password); }//if return false; }//boolean checkCredentials(String,String) public HTTPRequest passThroughPlugins(RavelerUser user, HTTPRequest request) throws PluginCallbackException { return pluginStack.passThroughPlugins(user,request); } public HTTPResponse passThroughPlugins(RavelerUser user, HTTPResponse response,String url) { return pluginStack.passThroughPlugins(user,response,url); } public HTTPResponse getVURL(String username,String vurlString, HTTPRequest request, String queryString) { return getVurlStack().getVURLResponse(username,vurlString,request,queryString); } /** * Inserts the Raveler Banner at the top of the HTML page * * @param currentUser the RavelerUser requesting the page * @param pageHTML a string containing the HTML page * @param pageURL a string containing the location of the page * @param request an HTTPRequest containing the unmodified request * @return a string containing the modified HTML */ public String insertRavelerBanner(RavelerUser currentUser, String pageHTML, HTTPRequest request) { /* Set a vurl to get the unraveled page */ UnravelVURL unravel = new UnravelVURL(request); String unravelVURL = getVurlStack().addTemporaryVirtualURL(".unravel/"+request.uriString()+requestCnt,unravel); requestCnt++; System.out.println("Raveler: insertRavelerBanner: unravel URL = '"+request.uriString()+"'"); String additions = new String(""); additions += "