%@ page language="java" import="java.util.*,java.text.*,java.io.*" %>
<%@page import="org.apache.xerces.parsers.*" %>
<%@page import="org.w3c.dom.*" %>
<%@page import="org.xml.sax.SAXException" %>
<%!
/***********************************************UNWANTED LINES **********************************************************************************/
final static int DETAIL = 2;
final static int CLEAN = 1;
final static int NO = 0;
int debug = NO; // change this debug flag value to have different debugging levels
// the StringTokenizer delimiter
String delimiter = " \t\n\r\f~`!@#$%^&*()_-+={}[]|\\:;\"',.?>";
String str_error_detail = "";
Vector parseFields(String str_fields) {
Vector fields = null;
if(str_fields != null && str_fields.length() > 0) {
StringTokenizer t_fields = new StringTokenizer( str_fields, ", " );
fields = new Vector();
while(t_fields.hasMoreTokens()) {
String key = t_fields.nextToken().toString();
fields.add(key);
}
}
// if(debug >= DETAIL) System.out.println("parse fields:" + fields);
return fields;
}
void setError(String msg)
{
if ( !str_error_detail.equals("") )
str_error_detail += "
";
str_error_detail += msg;
}
boolean findExact(String line, String key) {
boolean found = false;
line=removeHTMLTags(line);
StringTokenizer words = new StringTokenizer(line, delimiter);
while(words.hasMoreTokens()) {
String word = words.nextToken();
if(line.indexOf("href")!=-1)
return found;
if(indexOf(line, "src=",true) != -1)
return found;
if(indexOf(line, "title",true) != -1)
return found;
if(indexOf(line, "window.",true) != -1)
return found;
if(word.equalsIgnoreCase(key)) {
found = true;
break;
}
}
return found;
}
boolean fileFind(String fileName, String key) throws Exception {
boolean found = false;
BufferedReader file = new BufferedReader(new FileReader(fileName));
try {
String line = null;
while((line = file.readLine())!= null) {
found = find(line, key);
if(found == true)
break;
}
} catch (IOException ioe) {
throw new Exception("IOException: " + ioe.getMessage());
} finally {
file.close();
}
return found;
}
int count(String line, String key) {
int count = 0;
StringTokenizer words = new StringTokenizer(line, delimiter);
while(words.hasMoreTokens()) {
String word = words.nextToken();
if(word.equalsIgnoreCase(key))
count++;
}
return count;
}
int fileCount(String fileName, String key) throws Exception {
int count = 0;
BufferedReader file = new BufferedReader(new FileReader(fileName));
try {
String line = null;
while((line = file.readLine())!= null) {
count += count(line, key);
}
} catch (IOException ioe) {
throw new Exception("IOException: " + ioe.getMessage());
} finally {
file.close();
}
return count;
}
String getHead(String fileName) throws Exception {
StringBuffer entireHead = new StringBuffer();
BufferedReader file = new BufferedReader(new FileReader(fileName));
try {
String line = null;
boolean startHead = false;
boolean endHead = false;
while(!endHead && (line = file.readLine())!= null ) {
int start = 0;
int end = line.length();
int headIndex = indexOf(line, "
", true);
if( headIndex != -1 ) {
start = headIndex + 6;
startHead = true;
}
int endHeadIndex = indexOf(line, "", true);
if(endHeadIndex != -1) {
end = endHeadIndex;
endHead = true;
}
if(startHead)
entireHead.append(line.substring(start, end));
}
// if(debug >= DETAIL) System.out.println("head is:" + entireHead);
} catch (IOException ioe) {
throw new Exception("IOException: " + ioe.getMessage());
} finally {
file.close();
}
return entireHead.toString();
}
String getTitle(String head) {
String title = "";
int start = indexOf(head, "
 |
|
|
|
|
| |
|
|
| Site Search |
|
| |
<%
int matchingCount = 0;
String matches = "";
for (int i = 0; i < sortedMatchings.size(); i++) {
HashMap entry = (HashMap)sortedMatchings.get(i);
//entry is a HashMap with one item in it
String fileLocation = (String)entry.keySet().iterator().next();
HashMap values = (HashMap)entry.values().iterator().next();
Integer percentage = (Integer)values.get("PERCENTAGE");
boolean show = !"AND".equals(searchOption) || percentage.intValue() == 100;
if (show) {
matchingCount ++;
matches += " " + (String)values.get("TITLE") + " ";
String searchDescription = (String)values.get("DESCRIPTION");
searchDescription = (searchDescription == null || searchDescription.trim().equals("") || searchDescription.trim().equals("/") ? "" : searchDescription + " ");
matches += searchDescription;
}
}
/*iterate over collection sortedMatchings
key is fileLocation, value is HashMap
of which keys are
TITLE
DESCRIPTION
PERCENTAGE (value is of type Integer)
URL
Available variables:
str_keywords
str_error_detail
processTime
int_count
*/
%>
<%="Number of matching results: " + matchingCount%>
<%=matches%>
|
|
|
|
|
| |
| |
Copyright © 2006, Welcome to the City of Dothan, Alabama |
|
|