Revision 373
Added by berkley over 24 years ago
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
198 | 198 |
} |
199 | 199 |
if (name.endsWith(".x")) { |
200 | 200 |
name = "xpos"; |
201 |
} |
|
201 |
}
|
|
202 | 202 |
|
203 | 203 |
//out.println(name + " => " + value[0]); |
204 |
params.put(name,value); |
|
205 |
} |
|
204 |
params.put(name,value);
|
|
205 |
}
|
|
206 | 206 |
|
207 | 207 |
//if the user clicked on the input images, decode which image |
208 | 208 |
//was clicked then set the action. |
... | ... | |
237 | 237 |
// session expired or has not been stored b/w user requests |
238 | 238 |
// redirect to default page for query only access |
239 | 239 |
|
240 |
|
|
241 | 240 |
// response.sendRedirect(htmlpath + "/sexpire.html"); |
242 | 241 |
|
243 | 242 |
} |
... | ... | |
247 | 246 |
if(action.equals("query")) |
248 | 247 |
{ |
249 | 248 |
handleQuery(out, params, response); |
250 |
} |
|
249 |
}
|
|
251 | 250 |
else if(action.equals("squery")) |
252 | 251 |
{ |
253 |
handleSQuery(out, params, response); |
|
254 |
} |
|
252 |
if(params.containsKey("query")) |
|
253 |
{ |
|
254 |
handleSQuery(((String[])params.get("query"))[0]); |
|
255 |
} |
|
256 |
else |
|
257 |
{ |
|
258 |
out.println("Illegal action squery without \"query\" parameter"); |
|
259 |
} |
|
260 |
} |
|
255 | 261 |
else if (action.equals("getdocument")) { |
256 | 262 |
try { |
257 | 263 |
handleGetDocumentAction(out, params, response); |
... | ... | |
399 | 405 |
} |
400 | 406 |
} |
401 | 407 |
|
402 |
/** |
|
408 |
/**
|
|
403 | 409 |
*Create the squery xml, execute it and display it |
404 | 410 |
* @param out is the output stream to the client |
405 | 411 |
* @param params is the Hashtable of parameters that should be included |
... | ... | |
407 | 413 |
* @param response is the response object linked to the client |
408 | 414 |
* @param conn the database connection |
409 | 415 |
*/ |
410 |
private void handleSQuery(PrintWriter out, Hashtable params, |
|
411 |
HttpServletResponse response) |
|
412 |
{ |
|
413 |
//create the squery and return it to be processed |
|
414 |
String doctype = null; |
|
415 |
String xmlquery = null; |
|
416 |
String[] doctypeArr = null; |
|
417 |
Connection conn = null; |
|
418 |
doctypeArr = (String[])params.get("doctype"); |
|
419 |
doctype = null; |
|
420 |
if (doctypeArr != null) |
|
421 |
{ |
|
422 |
doctype = ((String[])params.get("doctype"))[0]; |
|
423 |
} |
|
424 |
else |
|
425 |
{ |
|
426 |
doctype="ANY"; |
|
427 |
} |
|
428 |
if(params.containsKey("query")) |
|
429 |
{ //handles the case where the client creates the pathquery |
|
430 |
//document itself (i.e. for DMan) |
|
431 |
String query = ((String[])params.get("query"))[0]; |
|
432 |
if(!query.equals("")) |
|
433 |
{ |
|
434 |
xmlquery = DBQuery.createQuery(query, doctype); |
|
435 |
} |
|
436 |
} |
|
437 |
else |
|
438 |
{ |
|
439 |
//Creates a squery from the CGI parameters |
|
440 |
xmlquery = DBQuery .createSQuery(params, doctype); |
|
441 |
} |
|
416 |
private String handleSQuery(String xmlquery) |
|
417 |
{ |
|
442 | 418 |
Hashtable doclist = runQuery(xmlquery); |
443 |
String qformat = ((String[])params.get("qformat"))[0]; |
|
444 |
String resultdoc = createResultDocument(doclist, qformat, xmlquery, |
|
445 |
out, response); |
|
446 |
if(qformat.equals("html")) |
|
447 |
{ |
|
448 |
transformResultset(resultdoc, response, out); |
|
449 |
} |
|
450 |
else if(qformat.equals("xml")) |
|
451 |
{ |
|
452 |
response.setContentType("text/xml"); |
|
453 |
out.println(resultdoc); |
|
454 |
} |
|
455 |
else |
|
456 |
{ |
|
457 |
out.println("invalid qformat: " + qformat); |
|
458 |
} |
|
459 |
//conn.close(); |
|
419 |
String resultdoc = createResultDocument(doclist, xmlquery); |
|
420 |
return resultdoc; |
|
460 | 421 |
} |
461 | 422 |
|
462 | 423 |
/** |
... | ... | |
469 | 430 |
private void handleQuery(PrintWriter out, Hashtable params, |
470 | 431 |
HttpServletResponse response) |
471 | 432 |
{ |
472 |
String doctype=null; |
|
473 |
String[] doctypeArr=null; |
|
474 |
String query=null; |
|
475 |
Connection conn = null; |
|
476 | 433 |
|
477 |
if(params.containsKey("query")) |
|
478 |
{ //get the query parameter |
|
479 |
query = ((String[])params.get("query"))[0]; |
|
480 |
} |
|
481 |
else |
|
482 |
{ |
|
483 |
query = ""; |
|
484 |
} |
|
485 | 434 |
|
486 |
if(params.containsKey("doctype")) |
|
487 |
{ //check for the doctype |
|
488 |
doctypeArr = (String[])params.get("doctype"); |
|
489 |
doctype = null; |
|
490 |
} |
|
491 |
else |
|
492 |
{ |
|
493 |
doctype = "ANY"; |
|
494 |
} |
|
495 |
|
|
496 |
if (doctypeArr != null) |
|
497 |
{ |
|
498 |
doctype = ((String[])params.get("doctype"))[0]; |
|
499 |
} |
|
500 |
else |
|
501 |
{ |
|
502 |
doctype="ANY"; |
|
503 |
} |
|
504 |
|
|
505 | 435 |
//create the query and run it |
506 |
String xmlquery = DBQuery.createQuery(query, doctype);
|
|
436 |
String xmlquery = DBQuery.createSQuery(params);
|
|
507 | 437 |
Hashtable doclist = runQuery(xmlquery); |
508 | 438 |
String qformat = ((String[])params.get("qformat"))[0]; |
509 |
String resultdoc = createResultDocument(doclist, qformat, xmlquery, |
|
510 |
out, response); |
|
439 |
String resultdoc = createResultDocument(doclist, xmlquery); |
|
511 | 440 |
//format and transform the results |
512 | 441 |
if(qformat.equals("html")) |
513 | 442 |
{ |
... | ... | |
522 | 451 |
{ |
523 | 452 |
out.println("invalid qformat: " + qformat); |
524 | 453 |
} |
525 |
//conn.close(); |
|
526 | 454 |
} |
527 | 455 |
|
528 | 456 |
/** |
... | ... | |
580 | 508 |
util.returnConnection(conn); |
581 | 509 |
} |
582 | 510 |
} |
583 |
//conn.close(); |
|
584 | 511 |
} |
585 | 512 |
|
586 | 513 |
/** |
587 | 514 |
* Transforms a hashtable of documents to an xml or html result. |
588 | 515 |
* @param doclist- the hashtable to transform |
589 |
* @param qformat- the format to transform the results into |
|
590 | 516 |
* @param xmlquery- the query that returned the dolist result |
591 |
* @param out- the printwriter object used to write to the client |
|
592 |
* @param response- the response stream to write back to the client. |
|
593 | 517 |
*/ |
594 |
private String createResultDocument(Hashtable doclist, String qformat, |
|
595 |
String xmlquery, PrintWriter out, |
|
596 |
HttpServletResponse response) |
|
518 |
private String createResultDocument(Hashtable doclist, String xmlquery) |
|
597 | 519 |
{ |
598 | 520 |
// Create a buffer to hold the xml result |
599 | 521 |
StringBuffer resultset = new StringBuffer(); |
... | ... | |
603 | 525 |
String document = null; |
604 | 526 |
resultset.append("<?xml version=\"1.0\"?>\n"); |
605 | 527 |
resultset.append("<resultset>\n"); |
528 |
//the following should work but it doesn't because the parser doesn't |
|
529 |
//like the <?xml?> tag inside the <query> tag. This is supposed to be |
|
530 |
//the way that the query itself is sent back to the client. |
|
606 | 531 |
//resultset.append(" <query>" + xmlquery + "</query>"); |
607 | 532 |
Enumeration doclistkeys = doclist.keys(); |
608 | 533 |
while (doclistkeys.hasMoreElements()) |
... | ... | |
610 | 535 |
docid = (String)doclistkeys.nextElement(); |
611 | 536 |
document = (String)doclist.get(docid); |
612 | 537 |
resultset.append(" <document>" + document + "</document>"); |
613 |
} |
|
538 |
}
|
|
614 | 539 |
resultset.append("</resultset>"); |
615 | 540 |
return resultset.toString(); |
616 |
/* |
|
617 |
if(qformat.equals("xml")) |
|
618 |
{ |
|
619 |
// set content type and other response header fields first |
|
620 |
response.setContentType("text/xml"); |
|
621 |
out.println(resultset.toString()); |
|
622 |
} |
|
623 |
else if(qformat.equals("html")) |
|
624 |
{ |
|
625 |
// set content type and other response header fields first |
|
626 |
response.setContentType("text/html"); |
|
627 |
XMLDocumentFragment htmldoc = null; |
|
628 |
try |
|
629 |
{ |
|
630 |
XSLStylesheet style = new XSLStylesheet( |
|
631 |
new URL(resultStyleURL), null); |
|
632 |
htmldoc = (new XSLProcessor()).processXSL(style, |
|
633 |
(Reader)(new StringReader(resultset.toString())),null); |
|
634 |
htmldoc.print(out); |
|
635 |
} |
|
636 |
catch (Exception e) |
|
637 |
{ |
|
638 |
out.println("Error transforming document:\n" + e.getMessage()); |
|
639 |
} |
|
640 |
} |
|
641 |
*/ |
|
642 | 541 |
} |
643 | 542 |
|
644 | 543 |
/** |
... | ... | |
1006 | 905 |
|
1007 | 906 |
/** |
1008 | 907 |
* '$Log$ |
908 |
* 'Revision 1.73 2000/08/16 20:08:20 berkley |
|
909 |
* 'fixed bug with handleSQuery() that kept DMan from access the squery functionality |
|
910 |
* ' |
|
1009 | 911 |
* 'Revision 1.72 2000/08/16 18:48:57 berkley |
1010 | 912 |
* '- created transformResultset() which transforms an xml resultset document and displays it to the client useing DBTransform |
1011 | 913 |
* '- renamed transformDocument() to createResultDocument() and modified its functionality to only return a restultset xml document |
Also available in: Unified diff
Changed the flow of query and SQuery. SQuery now only handles a preformatted pathquery document as input (in the "query" parameter).
HandleQuery now handles all structured queries derived by CGI parameters.