///////////////////////////////////////////////////////// // Module ClientSearch.java // Version 2.0 // Language Java // Author Sudhakar Chandrasekaran (thaths@netscape.com) // History // 05/17/97 Housekeeping - cleaned up // 05/16/97 Implemted JavaWorld article's crawler // Removed the old page-description pairs // Added code to search CD-ROM // 05/14/97 Plan to fix performance issues // 04/21/97 Fixed parsing problem with getDocumentBase // 04/20/97 Long promised improvements put in. Have not optimized yet // AND/OR/string searches implemented // Case sesitivity added // Help added // 12/03/97 Am attempting dramatic improvements long promised. Added // options panel (GUI) for case sensitive searches and bolean // seraches // 12/01/97 Added MenuBar and menu items. Still experimental. Changed // Copyright to GNU General Public License. // 11/21/96 Added ability to search (theoretically) any number of pages, // a primitive HTML parser and bug fixes // 11/05/96 Added code to pop up a seperate window // 11/02/96 Added multithreading for the process of searching // // Legalese // Copyright (C) 1996-1997 Sudhakar Chandrasekharan // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the // Free Software Foundation; either version 2 of the license, or (at your // option) any later version. // // This program is distributed in the hope that it will be useful, but // WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. Writers of free software // cannot afford getting sued! // // You should have received a copy of the GNU General Public License along // with this program; if not, write to the Free Software Foundation, Inc., // 675 Mass Ave., Cambridge, MA 02139, USA. // // Sudhakar "Thaths" Chandrasekharan, 20 Apr 1997. //////////////////////////////////////////////////////// // First import the standard classes we need import java.applet.Applet; import java.applet.AppletContext; import java.awt.*; import java.io.DataInputStream; import java.io.FilterInputStream; import java.io.InputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.StringTokenizer; import java.util.Vector; import java.util.Hashtable; // Import all the custom classes that we need import MyFrame; public class ClientSearch extends Applet { // Data members MyFrame myFrame; String topPage; // Top most page to which to send the crawler String server; // Document base boolean isLocal; // Flag to indicate CD-ROM style searching String openingPage; Hashtable pageDB = new Hashtable(); int totalPages; int wid, heig; // Width and height of the pop-up window // Mommy! I want my momeee! Component f = getParent(); // Initialize the search engine public void init() { System.out.println("ClientSearch: Loaded. Initializing ..."); // Find the applet's frame while (f!= null) { f = f.getParent(); } // Get the PARAMs for the applet getParameters(); // The cralwler would start here openingPage = new String(server + topPage); setLayout(new FlowLayout(FlowLayout.CENTER)); Button b = new Button("Open Search Engine"); add(b); validate(); System.gc(); System.out.println("ClientSearch: Initialized. Running ..."); } public void getParameters() { // Get the parameters from APPLET tag. // If a parameter is not specified // in the applet tag then set it to a default value // How many pages must an applet search // before you can call it an applet ;-) String num = getParameter("totalPages"); if (num == null) { // searchQueue.ensureCapacity(10); totalPages = 30; // Default } else { // System.out.println("Total Pages is = " + Integer.parseInt(num)); totalPages = Integer.parseInt(num); } // Find out if the top page has been specified if ((topPage = getParameter("topPage")) == null) { System.err.println("ClientSearch: Unrecoverable Error! No top page specified. Applet cannot run"); } // Find out if CD-ROM style search is specified String locl = getParameter("isLocal"); if (locl == null) { // Not a CD-ROM style search. Must get a server // PARAMeter if ((server = getParameter("server")) == null) { System.err.println("ClientSearch: Unrecoverable Error! No server specified. Applet cannot run"); } isLocal = false; } else { // CD-ROM style search. Construct a 'server' // from documentBase isLocal = true; String docBase = this.getDocumentBase().toString(); int endIndex = docBase.lastIndexOf("/"); server = new String(docBase.substring(0,endIndex) + "/"); } // Get the width of the pop-up window String w = getParameter("wid"); if (w == null) { wid = 450; // Default } else { wid = Integer.parseInt(w); } // Get the height of the pop-up window String h = getParameter("heig"); if (h == null) { heig = 450; // Default } else { heig = Integer.parseInt(h); } // Get the font String fnt = getParameter("font"); if (fnt == null) { fnt= "TimesRoman"; // Default } // Get the font size int fontSize; String fs = getParameter("fontsize"); if (fs == null) { fontSize = 10; // Default } else { fontSize = Integer.parseInt(fs); } // Set the painting font to the specified value setFont(new Font(fnt, Font.PLAIN, fontSize)); // Get the background color String bg = getParameter("bgcolor"); if (bg == null) { setBackground(new Color(255,255,255)); // Default - white } else { // Parse out the RGB values StringTokenizer st = new StringTokenizer(bg, ","); String red = new String(st.nextToken()); String green = new String(st.nextToken()); String blue = new String(st.nextToken()); setBackground(new Color(Integer.parseInt(red), Integer.parseInt(green), Integer.parseInt(blue))); } // Get the foreground color String fg = getParameter("fgcolor"); if (fg == null) { setForeground(new Color(0,0,0)); // Default - black } else { // Parse out the RGB values StringTokenizer st = new StringTokenizer(fg, ","); String red = new String(st.nextToken()); String green = new String(st.nextToken()); String blue = new String(st.nextToken()); setForeground(new Color(Integer.parseInt(red), Integer.parseInt(green), Integer.parseInt(blue))); } } // Event Handler // When button is clicked // pop-up myFrame public boolean action(Event e, Object o) { // Button has been clicked. Open the search window myFrame = new MyFrame(this, (Frame)f, "ClientSearch v2.0"); myFrame.resize(wid,heig); myFrame.show(); return true; } public void start() { // myFrame.show(); } public void stop() { // myFrame.hide(); } // It's all over! public void destroy() { if (myFrame != null) { System.out.println("ClientSearch: Goodbye cruel world, it's over!"); myFrame.dispose(); myFrame = null; } } }