222 |
|
|
223 |
writeRewriteLinks(w, rewrite); |
writeRewriteLinks(w, rewrite); |
224 |
|
|
225 |
|
w.write("<h2>New pointer</h2>\n\n"); |
226 |
|
|
227 |
|
w.write("<FORM action=\"/new-pointer\" method=\"post\">\n"); |
228 |
|
w.write("<P>\n"); |
229 |
|
w.write("Title: <INPUT type=\"text\" name=\"title\">"); |
230 |
|
w.write("<SELECT name=\"target\">\n"); |
231 |
|
w.write("<OPTION selected value=\"urn:x-storm:1.0:text/plain,3i42h3s6nnfq2msvx7xzkyayscx5qbyj.lwpnacqdbzryxw3vhjvcj64qbznghohhhzwclnq\">Text file</OPTION>\n"); |
232 |
|
w.write("<OPTION value=\"urn:x-storm:1.0:application/vnd.kde.kword,ly3m5evqznmuxnuxyduv43ikvor2dkze.gxeygfionykrrizvwkoyevkdysdnrksw4t5i2yi\">KWord file</OPTION>\n"); |
233 |
|
w.write("</SELECT>\n"); |
234 |
|
w.write("<INPUT type=\"submit\" value=\"Create\">\n"); |
235 |
|
w.write("</P>\n"); |
236 |
|
w.write("</FORM>\n\n"); |
237 |
|
|
238 |
|
w.write("<h2>Pointers</h2>\n\n"); |
239 |
|
|
240 |
PointerIndex pIndex = |
PointerIndex pIndex = |
241 |
(PointerIndex)pool.getIndex(PointerIndex.uri); |
(PointerIndex)pool.getIndex(PointerIndex.uri); |
242 |
|
|
268 |
} |
} |
269 |
} |
} |
270 |
|
|
271 |
w.write("<p>"); |
w.write("<h2>Blocks</h2>\n\n"); |
272 |
|
|
273 |
synchronized(ids) { |
synchronized(ids) { |
274 |
for(Iterator i=ids.iterator(); i.hasNext();) { |
for(Iterator i=ids.iterator(); i.hasNext();) { |
407 |
return resp; |
return resp; |
408 |
} |
} |
409 |
|
|
410 |
|
/** PUTting to a pointer creates a new block |
411 |
|
* and points the pointer to it. |
412 |
|
*/ |
413 |
protected HTTPResponse doPut(HTTPRequest req, HTTPResponse.Factory resf) |
protected HTTPResponse doPut(HTTPRequest req, HTTPResponse.Factory resf) |
414 |
throws IOException { |
throws IOException { |
415 |
|
|
464 |
if(dbg) p("Return response"); |
if(dbg) p("Return response"); |
465 |
return resp; |
return resp; |
466 |
} |
} |
467 |
|
|
468 |
|
/** POSTing to /new-pointer creates a new pointer. |
469 |
|
* Options are <code>title</code>, the title of the |
470 |
|
* new pointer, and <code>target</code>, the URI |
471 |
|
* of the block the new pointer will point to first. |
472 |
|
*/ |
473 |
|
protected HTTPResponse doPost(HTTPRequest req, HTTPResponse.Factory resf) |
474 |
|
throws IOException { |
475 |
|
|
476 |
|
String uri = req.getRequestURI(); |
477 |
|
System.out.println("POST: "+uri); |
478 |
|
|
479 |
|
if(!acceptPut) |
480 |
|
return doUnknown(req, resf); |
481 |
|
|
482 |
|
if(!uri.equals("/new-pointer")) |
483 |
|
return resf.makeError(404, "Not found"); |
484 |
|
|
485 |
|
String formdata = |
486 |
|
CopyUtil.readString(req.getInputStream()); |
487 |
|
if(dbg) p("Form data: "+formdata); |
488 |
|
|
489 |
|
int i = formdata.indexOf("title=") + "title=".length(); |
490 |
|
int j = formdata.indexOf('&', i); |
491 |
|
if(j < 0) j = formdata.length(); |
492 |
|
String title = |
493 |
|
java.net.URLDecoder.decode(formdata.substring(i,j)); |
494 |
|
|
495 |
|
i = formdata.indexOf("target=") + "target=".length(); |
496 |
|
j = formdata.indexOf('&', i); |
497 |
|
if(j < 0) j = formdata.length(); |
498 |
|
String targetURI = |
499 |
|
java.net.URLDecoder.decode(formdata.substring(i,j)); |
500 |
|
p(targetURI); |
501 |
|
BlockId target = new BlockId(targetURI); |
502 |
|
|
503 |
|
PointerId id; |
504 |
|
PointerIndex idx = |
505 |
|
(PointerIndex)pool.getIndex(PointerIndex.uri); |
506 |
|
|
507 |
|
try { |
508 |
|
id = new PointerId(keyPair.getPublic()); |
509 |
|
if(title.trim().equals("")) |
510 |
|
idx.set(id, target, keyPair, null); |
511 |
|
else |
512 |
|
idx.set(id, target, keyPair, title); |
513 |
|
} catch(Exception _) { |
514 |
|
_.printStackTrace(); |
515 |
|
throw new Error("Exception while creating pointer XXX"); |
516 |
|
} |
517 |
|
|
518 |
|
HTTPResponse resp = resf.makeResponse(203, "Created"); |
519 |
|
resp.setField("Content-Type", "text/html"); |
520 |
|
resp.setField("Location", target.getURI()); |
521 |
|
Writer w = new OutputStreamWriter(resp.getOutputStream(), |
522 |
|
"US-ASCII"); |
523 |
|
w.write("<html><head><title>Created</title></head><body>"); |
524 |
|
w.write("New pointer created at: \n"); |
525 |
|
w.write("<a href=\""+id.getURI()+"\">"+id.getURI()+"</a>\n"); |
526 |
|
w.write("<p><a href=\"/\">Back to the home page.</a>\n"); |
527 |
|
w.write("</body></html>"); |
528 |
|
w.close(); |
529 |
|
|
530 |
|
if(dbg) p("Return response"); |
531 |
|
return resp; |
532 |
|
} |
533 |
} |
} |
534 |
|
|
535 |
protected BlockId getBlockId(String uri) { |
protected BlockId getBlockId(String uri) { |