34 |
import org.nongnu.storm.pointers.*; |
import org.nongnu.storm.pointers.*; |
35 |
import java.io.*; |
import java.io.*; |
36 |
import java.net.*; |
import java.net.*; |
37 |
import java.util.Iterator; |
import java.util.*; |
|
import java.util.NoSuchElementException; |
|
38 |
import java.security.*; |
import java.security.*; |
39 |
|
|
40 |
/** An HTTP server serving blocks from a Storm pool. When started from command |
/** An HTTP server serving blocks from a Storm pool. When started from command |
51 |
protected String REWRITE; |
protected String REWRITE; |
52 |
protected String URNPAC; |
protected String URNPAC; |
53 |
protected String BACKLINKS; |
protected String BACKLINKS; |
54 |
|
protected String QUERY = "search?q="; |
55 |
protected HTTPServer server; |
protected HTTPServer server; |
56 |
|
|
57 |
protected boolean acceptPut = false; |
protected boolean acceptPut = false; |
108 |
|
|
109 |
if(uri.equals(URNPAC)) |
if(uri.equals(URNPAC)) |
110 |
return makePAC(req, resf); |
return makePAC(req, resf); |
111 |
|
if(uri.startsWith(QUERY)) |
112 |
|
return query(req, resf, uri); |
113 |
|
|
114 |
String element; |
String element; |
115 |
while(!uri.startsWith("urn:")) { |
while(!uri.startsWith("urn:")) { |
330 |
return s; |
return s; |
331 |
} |
} |
332 |
|
|
333 |
|
protected HTTPResponse query(HTTPRequest req, |
334 |
|
HTTPResponse.Factory resf, |
335 |
|
String uri) throws IOException { |
336 |
|
String query = uri.substring(QUERY.length()); |
337 |
|
|
338 |
|
TitleIndex idx = |
339 |
|
(TitleIndex)pool.getIndex(TitleIndex.uri); |
340 |
|
|
341 |
|
HTTPResponse resp = resf.makeResponse(200, "Ok"); |
342 |
|
resp.setField("Content-Type", "text/html;charset=UTF-8"); |
343 |
|
|
344 |
|
Writer w = new OutputStreamWriter(resp.getOutputStream(), |
345 |
|
"US-ASCII"); |
346 |
|
w.write("<html><head><title>"+query+"</title></head><body>\n"); |
347 |
|
w.write("<h1>Results for '"+query+"'</h1>\n\n"); |
348 |
|
|
349 |
|
Set pBlocks = idx.getPointers(query); |
350 |
|
|
351 |
|
if(pBlocks.isEmpty()) w.write("<p>No results.</p>\n\n"); |
352 |
|
|
353 |
|
for(Iterator i=pBlocks.iterator(); i.hasNext();) { |
354 |
|
PointerBlock p = (PointerBlock)i.next(); |
355 |
|
w.write("<p><b><a href=\""+p.getPointer().getURI()+"\">"); |
356 |
|
w.write(p.getName()+"</a></b><br />\n"); |
357 |
|
w.write("<small>"+p.getPointer().getURI()+"</small></p>\n\n"); |
358 |
|
} |
359 |
|
|
360 |
|
w.write("</body></html>\n"); |
361 |
|
w.close(); |
362 |
|
return resp; |
363 |
|
} |
364 |
|
|
365 |
protected HTTPResponse makePAC(HTTPRequest req, |
protected HTTPResponse makePAC(HTTPRequest req, |
366 |
HTTPResponse.Factory resf) |
HTTPResponse.Factory resf) |
367 |
throws IOException { |
throws IOException { |
463 |
public static void main(String[] args) throws Exception { |
public static void main(String[] args) throws Exception { |
464 |
dbg = true; |
dbg = true; |
465 |
IndexedPool pool; |
IndexedPool pool; |
466 |
java.util.Set indexTypes = |
Set indexTypes = new HashSet(); |
467 |
java.util.Collections.singleton(PointerIndex.type); |
indexTypes.add(HtmlLinkIndex.type); |
468 |
|
indexTypes.add(PointerIndex.type); |
469 |
|
indexTypes.add(TitleIndex.type); |
470 |
pool = new DirPool(new File(args[0]), indexTypes); |
pool = new DirPool(new File(args[0]), indexTypes); |
471 |
|
|
472 |
if(args.length == 1) |
if(args.length == 1) |