/*
Copyright 2002 Catalin Stefan Samfirescu mdsa@lycos.co.uk
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.awt.*;
import java.awt.event.*;
import java.net.*;
import java.applet.*;
import java.io.*;
import java.util.*;
public class MyDomainSearch extends Applet implements ActionListener, Runnable{
URL codeBase, userURL, documentBase;
BufferedReader index;
String buf, key, ind, title, param, start, stop, labelText,curFile;
Vector URLVector;
Hashtable filetitle;
char ch;
java.awt.List list;
TextField tf;
Button b;
Label lb;
boolean needLine ,search, titlefound, keyfound, reg, comment, flag;
GridBagLayout gridbag;
GridBagConstraints cons;
Thread runner;
public void init()
{
codeBase=getCodeBase();
flag=false;
try{
setBackground(new Color(Integer.parseInt(param()),Integer.parseInt(param()),Integer.parseInt(param())));
}catch (NullPointerException e){setBackground(new Color(255,255,255));}
catch(NumberFormatException e){setBackground(new Color(255,255,255));}
catch(IllegalArgumentException e){setBackground(new Color(255,255,255));}
gridbag=new GridBagLayout();
cons=new GridBagConstraints();
setLayout(gridbag);
build (cons,0,0,1,1,90,10);
cons.fill=GridBagConstraints.HORIZONTAL;
tf=new TextField();
gridbag.setConstraints(tf,cons);
add(tf);
build (cons,1,0,1,1,10,0);
cons.fill=GridBagConstraints.NONE;
cons.anchor=GridBagConstraints.CENTER;
try{
start=param();
}catch (StringIndexOutOfBoundsException e) {start="Search";}
catch (NullPointerException e) {start="Search";}
b=new Button(start);
gridbag.setConstraints(b,cons);
add(b);
try{
stop=param();
}catch (StringIndexOutOfBoundsException e) {stop="Stop";}
catch (NullPointerException e) {stop="Stop";}
build (cons,0,1,2,1,0,80);
cons.fill=GridBagConstraints.BOTH;
list=new java.awt.List();
list.addActionListener(this);
list.setCursor(new Cursor(Cursor.HAND_CURSOR));
gridbag.setConstraints(list,cons);
add(list);
build (cons,0,2,2,1,0,10);
cons.fill=GridBagConstraints.HORIZONTAL;
try{
labelText=param();
}catch (StringIndexOutOfBoundsException e) {labelText="Enter keyword";}
catch (NullPointerException e) {labelText="Enter keyword";}
lb=new Label(labelText, Label.CENTER);
gridbag.setConstraints(lb,cons);
add(lb);
needLine=false;
search=false;
comment=false;
filetitle=new Hashtable(30,(float)0.5);
try{
ind=getParameter ("index");
}catch(NullPointerException e) { ind="index.html"; }
curFile=ind;
URLVector=new Vector (30,15);
}
public void parseHLink (String str) throws StringIndexOutOfBoundsException
{
int m;
/*it is true when quotes are present*/
boolean flag=false;
int i=0, j=0, k=0;
/*We have a frameset page*/
while ((k=str.toUpperCase().indexOf("' && (ch!=' ' || flag==true) && ch!='"' && ch!='#');
/*Now we have a page*/
buf=str.substring(i,j);
/*We want only relative URLs*/
if (buf.indexOf(codeBase.toString())!=-1)
buf=buf.substring(codeBase.toString().length(),j);
/*Check to see if it is a link to the exterior or a link to a non-html file*/
if ((buf.toUpperCase().indexOf("NEWS")==-1) && (buf.toUpperCase().indexOf("WWW.")==-1) && (buf.indexOf("@")==-1) && (buf.toUpperCase().indexOf("HTTP:")==-1) && (buf.toUpperCase().indexOf("FILE:")==-1) && (buf.toUpperCase().indexOf("HTTPS:")==-1) && (buf.indexOf("#")==-1) && (buf.toUpperCase().indexOf("MAILTO")==-1) && (buf.toUpperCase().indexOf("FTP:")==-1) && (buf.toUpperCase().indexOf(".GIF")==-1) && (buf.toUpperCase().indexOf(".JPG")==-1) && (buf.toUpperCase().indexOf(".JPEG")==-1) && (buf.toUpperCase().indexOf(".PNG")==-1) && (buf.toUpperCase().indexOf(".SWF")==-1) && (buf.toUpperCase().indexOf("JAVASCRIPT:")==-1))
{
if (buf.startsWith("/"))
{
if (buf.length()==1)
{
if (URLVector.contains(ind)==false)
buf=ind;
}
else buf=buf.substring(1);
}
else
{
if (curFile.endsWith("/")==true)
{
curFile=curFile.substring(0,curFile.length()-1);
if (curFile.lastIndexOf('/')!=-1)
{
if (buf.startsWith("../"))
{
if ((m=curFile.substring(0,curFile.lastIndexOf('/')).lastIndexOf('/'))!=-1)
buf=curFile.substring(0,m).concat(buf.substring(3));
else buf=buf.substring(3);
}
else
buf=curFile.substring(0,curFile.lastIndexOf('/')+1).concat(buf);
}
}
else if (curFile.lastIndexOf('/')!=-1)
{
if (buf.startsWith("../"))
{
if ((m=curFile.substring(0,curFile.lastIndexOf('/')).lastIndexOf('/'))!=-1)
buf=curFile.substring(0,m).concat(buf.substring(3));
else buf=buf.substring(3);
}
else
buf=curFile.substring(0,curFile.lastIndexOf('/')+1).concat(buf);
}
}
if (URLVector.contains (buf)==false && buf!=ind)
{
URLVector.addElement (buf);
}
}
}
str=str.substring(k+6);
}
while ((k=str.toUpperCase().indexOf("' && (ch!=' ' || flag==true) && ch!='"' && ch!='#');
buf=str.substring(i,j);
if (buf.indexOf(codeBase.toString())!=-1)
buf=buf.substring(codeBase.toString().length(),j);
if ((buf.toUpperCase().indexOf("NEWS")==-1) && (buf.toUpperCase().indexOf("WWW")==-1) && (buf.indexOf("@")==-1) && (buf.toUpperCase().indexOf("HTTP:")==-1) && (buf.toUpperCase().indexOf("FILE:")==-1) && (buf.toUpperCase().indexOf("HTTPS:")==-1) && (buf.indexOf("#")==-1) && (buf.toUpperCase().indexOf("MAILTO")==-1) && (buf.toUpperCase().indexOf("FTP:")==-1) && (buf.toUpperCase().indexOf(".GIF")==-1) && (buf.toUpperCase().indexOf(".JPG")==-1) && (buf.toUpperCase().indexOf(".JPEG")==-1) && (buf.toUpperCase().indexOf(".PNG")==-1) && (buf.toUpperCase().indexOf(".SWF")==-1) && (buf.toUpperCase().indexOf("JAVASCRIPT:")==-1))
{
if (buf.startsWith("/"))
{
if (buf.length()==1)
{
if (URLVector.contains(ind)==false)
buf=ind;
}
else buf=buf.substring(1);
}
else
{
if (curFile.endsWith("/")==true)
{
curFile=curFile.substring(0,curFile.length()-1);
if (curFile.lastIndexOf('/')!=-1)
{
if (buf.startsWith("../"))
{
if ((m=curFile.substring(0,curFile.lastIndexOf('/')).lastIndexOf('/'))!=-1)
buf=curFile.substring(0,m).concat(buf.substring(3));
else buf=buf.substring(3);
}
else
buf=curFile.substring(0,curFile.lastIndexOf('/')+1).concat(buf);
}
}
else if (curFile.lastIndexOf('/')!=-1)
{
if (buf.startsWith("../"))
{
if ((m=curFile.substring(0,curFile.lastIndexOf('/')).lastIndexOf('/'))!=-1)
buf=curFile.substring(0,m).concat(buf.substring(3));
else buf=buf.substring(3);
}
else
buf=curFile.substring(0,curFile.lastIndexOf('/')+1).concat(buf);
}
}
if (URLVector.contains (buf)==false && buf!=ind)
URLVector.addElement (buf);
}
}
str=str.substring(k+2);
}
}
public void parseKeyword (String str, String keyword)
{
int i=0;
boolean tag=false;
StringBuffer buffer=new StringBuffer();
if (comment==false)
{
if (str.indexOf("<")!=-1)
{
if (str.indexOf(">")!=-1 && (str.indexOf(">")");
}
else if (str.indexOf(">")!=-1)
i=str.indexOf(">");
}
for (;i')
{
tag=false;
comment=false;
}
else if (tag==false && comment==false)
{
if (i>1 && str.charAt(i-1)=='>')
{
buffer.append (' ');
buffer.append (ch);
}
else buffer.append (ch);
}
}
if (buffer!=null)
buf=buffer.toString().trim();
if (buffer!=null && (i=buf.toUpperCase().indexOf(keyword.toUpperCase()))!=-1 && comment==false)
{
if (buf.length()==keyword.length())
{
keyfound=true;
list.addItem(title);
}
else
{
if (i==0)
{
if (Character.isLetter(buf.charAt(i+keyword.length()))==false)
{
keyfound=true;
list.addItem(title);
}
}
else
{
if ((i+keyword.length())==buf.length())
{
if (Character.isLetter(buf.charAt(i-1))==false)
{
keyfound=true;
list.addItem(title);
}
}
else if (Character.isLetter(buf.charAt(i-1))==false && Character.isLetter(buf.charAt(i+keyword.length()))==false)
{
keyfound=true;
list.addItem(title);
}
}
}
}
}
public void parseTitle (String str, String file)
{
int i=0, j=0;
if (needLine==true)
{
if ((j=str.toUpperCase().indexOf(""))!=-1)
{
title=title.concat(" "+str.substring(0,j));
filetitle.put (title, file);
titlefound=true;
needLine=false;
}
else
title=title.concat(" "+str);
}
else if ((i=str.toUpperCase().indexOf(""))!=-1)
{
i+=7;
if ((j=str.toUpperCase().indexOf(""))!=-1)
{
title=str.substring(i,j);
filetitle.put (title, file);
titlefound=true;
}
else
{
needLine=true;
title=str.substring(i,str.length());
}
}
if ((str.toUpperCase().indexOf("")!=-1 || str.toUpperCase().indexOf("