/** * Reads information from form and searches web documents.
*/ publicvoid doPost(HttpServletRequest req,
HttpServletResponse res) throws ServletException, IOException {
// first, set the "content type" header of the response
res.setContentType("text/html");
// Get the response's PrintWriter to return text to the client.
out = res.getWriter();
File file = new File(OSSearchConstants.SERVLET_DIR,OSSearchConstants.TEMPLATE);
StringBuffer text = new StringBuffer();
results = new Vector();
try { // Get the keywords
String kw=req.getParameterValues("keywords")[0];
StringTokenizer tok = new StringTokenizer(kw," -\t~!@#$%^&*()_+=[{]};:'\",.<>?/|\\",false);
int len = tok.countTokens();
Vector kwv = new Vector(); for(int i=0;i<len;i++) {
kw = tok.nextToken(); if(isValidKeyword(kw)) {
kwv.addElement(kw);
}
}
len = kwv.size();
keywords = new String[len]; for(int i=0;i<len;i++) {
keywords[i] = kwv.elementAt(i).toString();
}
// Search web files and order into a list. int sz = files.size();
String url; for(int i=0;i<sz;i++) {
url = (String) urls.elementAt(i); try {
HTMLRankObj rank = new HTMLRankObj((File) files.elementAt(i),keywords,url);
insertResult(rank);
} catch(RankException e) {
error(e,e.getMessage()); return;
}
}
// Open template document.
StringBuffer word = new StringBuffer();
FileInputStream fis = new FileInputStream(file);
BufferedInputStream bis = new BufferedInputStream(fis,1024);
/** * List the files in the given directory * @param filter GenericFileFilter to use * @param dir Directory to list * @param rel Relative path from the root directory * @param exclude Directories to exclude * @param recursive True, if directories should be recursively listed.
*/ publicvoid list(GenericFileFilter filter, File dir, String rel, Vector exclude, boolean recursive) throws IOException { // Add to files and urls list
String [] ls = dir.list(filter); int sz = ls.length; for(int i=0;i<sz;i++) {
files.addElement(new File(dir,ls[i]));
urls.addElement(rootUrl + rel + ls[i]);
}
/** * Returns an error message back to the web browser * @param ex Exception for printing the stack (passing null will cause the stack not to be printed) * @param error Message to display in error message.
*/ publicvoid error(Exception ex, String error) {
String text = "<html><head><title>Error</title></head><body>Error occured!";
text += "<br><br>Please report error to <a href=\"mailto:keith@nebulais.com?subject=Quote-a-Price Error\">";
text += "keith@nebulais.com</a>.<br><br>Use \"Back\" arrow to continue\n";
text += "<br><br>";
text += error;
out.println(text); if(ex!=null) {
ex.printStackTrace(out);
}
text = "</body></html>";
out.println(text);
}
/** * Insert a search result into the results list * @param obj HTMLRankObj to insert into the results list.
*/ publicvoid insertResult(HTMLRankObj obj) { double score = obj.getScore(); double test; int sz = results.size(); boolean inserted=false; if(score>0.0) { for(int i=0;i<sz;i++) {
test = ((HTMLRankObj) results.elementAt(i)).getScore(); if(score>test) {
results.insertElementAt(obj,i);
inserted=true; break;
}
} if(!inserted) {
results.addElement(obj);
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.