Revision 351
Added by berkley over 24 years ago
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
241 | 241 |
if (sess.isNew()) { |
242 | 242 |
// session expired or has not been stored b/w user requests |
243 | 243 |
// redirect to default page for query only access |
244 |
// response.sendRedirect("/xmltodb/sexpire.html"); |
|
244 |
|
|
245 |
// response.sendRedirect("/xmltodb/sexpire.html"); |
|
245 | 246 |
} |
246 | 247 |
} |
247 | 248 |
// End of Jivka added |
... | ... | |
307 | 308 |
return; |
308 | 309 |
} else { |
309 | 310 |
response.sendRedirect( |
310 |
response.encodeRedirectUrl("/xmltodb/index.html"));
|
|
311 |
response.encodeRedirectUrl("/berkley/index.html"));
|
|
311 | 312 |
} |
312 | 313 |
} catch ( java.io.IOException ioe) { |
313 | 314 |
sess.disconnect(); |
... | ... | |
331 | 332 |
out.println("</success>"); |
332 | 333 |
} else { |
333 | 334 |
response.sendRedirect( |
334 |
response.encodeRedirectUrl("/xmltodb/metacat.html")); |
|
335 |
|
|
336 |
response.encodeRedirectUrl("/berkley/metacat.html")); |
|
335 | 337 |
} |
336 | 338 |
} catch ( java.io.IOException ioe) { |
337 | 339 |
sess.disconnect(); |
... | ... | |
343 | 345 |
out.println("</error>"); |
344 | 346 |
} |
345 | 347 |
|
346 |
} else { |
|
348 |
} else {
|
|
347 | 349 |
sess.disconnect(); |
348 | 350 |
out.println("<?xml version=\"1.0\"?>"); |
349 | 351 |
out.println("<error>"); |
... | ... | |
362 | 364 |
} |
363 | 365 |
} |
364 | 366 |
|
365 |
/** |
|
367 |
/**
|
|
366 | 368 |
*Create the squery xml and return it as a String. |
367 | 369 |
* @param params is the Hashtable of parameters that should be included |
368 | 370 |
* in the squery. |
369 | 371 |
*/ |
370 |
private String handleSQuery(Hashtable params) |
|
372 |
private String handleSQuery(Hashtable params)
|
|
371 | 373 |
{ |
372 | 374 |
//create the squery and return it to be processed |
373 | 375 |
String doctype = null; |
... | ... | |
393 | 395 |
*/ |
394 | 396 |
private String handleQuery(Hashtable params) |
395 | 397 |
{ |
396 |
String doctype=null; |
|
397 |
String[] doctypeArr=null; |
|
398 |
String query = ((String[])params.get("query"))[0]; |
|
399 |
doctypeArr = (String[])params.get("doctype"); |
|
400 |
doctype = null; |
|
398 |
String doctype=null; |
|
399 |
String[] doctypeArr=null; |
|
400 |
String query=null; |
|
401 |
if(params.containsKey("query")) |
|
402 |
{ |
|
403 |
query = ((String[])params.get("query"))[0]; |
|
404 |
} |
|
405 |
else |
|
406 |
{ |
|
407 |
query = ""; |
|
408 |
} |
|
409 |
|
|
410 |
if(params.containsKey("doctype")) |
|
411 |
{ |
|
412 |
doctypeArr = (String[])params.get("doctype"); |
|
413 |
doctype = null; |
|
414 |
} |
|
415 |
else |
|
416 |
{ |
|
417 |
doctype = "ANY"; |
|
418 |
} |
|
419 |
|
|
401 | 420 |
if (doctypeArr != null) |
402 | 421 |
{ |
403 | 422 |
doctype = ((String[])params.get("doctype"))[0]; |
... | ... | |
412 | 431 |
/** |
413 | 432 |
* Run the query and return a hashtable of results. |
414 | 433 |
*/ |
415 |
private Hashtable runQuery(Reader xmlquery)
|
|
434 |
private Hashtable runQuery(StringBuffer xmlquery)
|
|
416 | 435 |
{ |
417 | 436 |
Hashtable doclist=null; |
418 | 437 |
Connection conn = null; |
... | ... | |
420 | 439 |
{ |
421 | 440 |
conn = util.getConnection(); |
422 | 441 |
DBQuery queryobj = new DBQuery(conn, saxparser); |
423 |
doclist = queryobj.findDocuments(xmlquery);
|
|
442 |
doclist = queryobj.findDocuments(new StringReader(xmlquery.toString()));
|
|
424 | 443 |
util.returnConnection(conn); |
425 | 444 |
return doclist; |
426 | 445 |
} |
... | ... | |
448 | 467 |
String document = null; |
449 | 468 |
resultset.append("<?xml version=\"1.0\"?>\n"); |
450 | 469 |
resultset.append("<resultset>\n"); |
451 |
resultset.append(" <query>" + xmlquery + "</query>"); |
|
470 |
//resultset.append(" <query>" + xmlquery + "</query>");
|
|
452 | 471 |
Enumeration doclistkeys = doclist.keys(); |
453 | 472 |
while (doclistkeys.hasMoreElements()) |
454 | 473 |
{ |
... | ... | |
477 | 496 |
(Reader)(new StringReader(resultset.toString())),null); |
478 | 497 |
htmldoc.print(out); |
479 | 498 |
} |
480 |
catch (Exception e) |
|
499 |
catch (Exception e)
|
|
481 | 500 |
{ |
482 | 501 |
out.println("Error transforming document:\n" + e.getMessage()); |
483 | 502 |
} |
... | ... | |
487 | 506 |
/** |
488 | 507 |
* Handle the database query request and return a result set, possibly |
489 | 508 |
* transformed from XML into HTML |
490 |
*/ |
|
509 |
*/
|
|
491 | 510 |
private void handleQueryAction(PrintWriter out, Hashtable params, |
492 |
HttpServletResponse response) |
|
511 |
HttpServletResponse response)
|
|
493 | 512 |
{ |
494 | 513 |
String action = ((String[])params.get("action"))[0]; |
495 | 514 |
Hashtable doclist = null; |
496 | 515 |
String[] doctypeArr = null; |
497 | 516 |
String doctype = null; |
498 |
Reader xmlquery = null;
|
|
517 |
StringBuffer xmlquery = null;
|
|
499 | 518 |
Connection conn = null; |
500 | 519 |
|
501 | 520 |
if(action.equals("query")) |
502 | 521 |
{ |
503 |
xmlquery = new StringReader(handleQuery(params));
|
|
522 |
xmlquery = new StringBuffer(handleQuery(params));
|
|
504 | 523 |
} |
505 | 524 |
else if(action.equals("squery")) |
506 | 525 |
{ |
507 |
xmlquery = new StringReader(handleSQuery(params));
|
|
526 |
xmlquery = new StringBuffer(handleSQuery(params));
|
|
508 | 527 |
} |
528 |
//System.out.println("Query is: "); |
|
529 |
//System.out.println(xmlquery.toString()); |
|
509 | 530 |
|
510 | 531 |
doclist = runQuery(xmlquery); |
511 |
|
|
532 |
//System.out.println("result is: " ); |
|
533 |
//System.out.println(doclist.toString()); |
|
512 | 534 |
String qformat = ((String[])params.get("qformat"))[0]; |
513 | 535 |
transformDocument(doclist, qformat, xmlquery.toString(), out, response); |
514 | 536 |
} |
... | ... | |
878 | 900 |
|
879 | 901 |
/** |
880 | 902 |
* '$Log$ |
903 |
* 'Revision 1.67 2000/08/14 20:43:27 jones |
|
904 |
* 'Updated build process to now use a copy of the source files so that keyword |
|
905 |
* 'substitution can ocur before the build. This allows for substitution of |
|
906 |
* 'hardcoded values into the source before the compile. Currently, I am |
|
907 |
* 'using this feature to do the following: |
|
908 |
* ' |
|
909 |
* ' 1) Substitute a "Release" number into the code |
|
910 |
* ' 2) Substitute a hardcoded servlet path into the code and html files |
|
911 |
* ' |
|
912 |
* 'By changing the value of "servlet-path" and "installdir" properties in |
|
913 |
* 'build.xml, one can now easily install a new version of the servlet in a |
|
914 |
* 'different location by simply using "ant install". |
|
915 |
* ' |
|
881 | 916 |
* 'Revision 1.66 2000/08/14 18:27:37 bojilova |
882 | 917 |
* 'added Logout handling |
883 | 918 |
* ' |
Also available in: Unified diff
Broke up handleQueryAction into handleQuery, handleSQuery, runQuery and transformDocument. handleQueryAction is now a base function which makes calls to each of these functions to create, run and transform a query from CGI parameters.