Autor ist ein Windows-Programm zur Erstellung multimedialer Artikel für eine zugehörige Internetseite. OSSearchServlet.java
Sie kann an beliebige HTML- oder XML-Formate angepaßt werden.JAVA
/** * 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 = "ErrorError occured!";
text += "
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 ist noch experimentell.