Revision 380
Added by Matt Jones over 24 years ago
src/edu/ucsb/nceas/metacat/MetaCatServlet.java | ||
---|---|---|
87 | 87 |
private String saxparser = null; |
88 | 88 |
private String defaultdatapath = null; |
89 | 89 |
private String servletpath = null; |
90 |
private PropertyResourceBundle options = null; |
|
91 |
private MetaCatUtil util = null; |
|
92 |
|
|
93 |
// path to directory where data files |
|
94 |
// that can be downloaded will be stored |
|
90 | 95 |
private String htmlpath = null; |
91 |
// path to directory where data files
|
|
92 |
// that can be downloaded will be stored
|
|
96 |
// script to get data file and put it
|
|
97 |
// in defaultdocpath dir
|
|
93 | 98 |
private String executescript = null; |
94 |
// script to get data file and put it |
|
95 |
// in defaultdocpath dir |
|
96 |
private PropertyResourceBundle options = null; |
|
97 | 99 |
|
98 |
private MetaCatUtil util = null; |
|
99 | 100 |
|
100 | 101 |
/** |
101 | 102 |
* Initialize the servlet by creating appropriate database connections |
... | ... | |
212 | 213 |
action = ((String[])params.get("action"))[0]; |
213 | 214 |
} |
214 | 215 |
|
215 |
// Jivka added |
|
216 |
// This block handles session management for the servlet |
|
217 |
// by looking up the current session information for all actions |
|
218 |
// other than "Login" and "Logout" |
|
216 | 219 |
// handle login action |
217 | 220 |
if (action.equals("Login") || action.equals("Login Client")) { |
218 | 221 |
handleLoginAction(out, params, request, response); |
... | ... | |
241 | 244 |
|
242 | 245 |
} |
243 | 246 |
} |
244 |
// End of Jivka added |
|
245 | 247 |
|
248 |
// Now that we know the session is valid, we can delegate the request |
|
249 |
// to a particular action handler |
|
246 | 250 |
if(action.equals("query")) |
247 | 251 |
{ |
248 | 252 |
handleQuery(out, params, response); |
... | ... | |
251 | 255 |
{ |
252 | 256 |
if(params.containsKey("query")) |
253 | 257 |
{ |
254 |
handleSQuery(((String[])params.get("query"))[0]); |
|
258 |
handleSQuery(out, params, response); |
|
259 |
//handleSQuery(((String[])params.get("query"))[0]); |
|
255 | 260 |
} |
256 | 261 |
else |
257 | 262 |
{ |
... | ... | |
314 | 319 |
} |
315 | 320 |
return action; |
316 | 321 |
} catch (Exception npe) { |
322 |
// |
|
323 |
// MBJ -- NOTE that this should be handled more gracefully with |
|
324 |
// the new exception infrastructure -- this "error" return |
|
325 |
// value is inappropriate |
|
317 | 326 |
//out.println("<P>Caught exception looking for Y value."); |
318 | 327 |
return "error"; |
319 | 328 |
} |
320 | 329 |
} |
321 | 330 |
|
322 |
// Jivka added |
|
323 | 331 |
/** |
324 | 332 |
* Handle the Login request. Create a new session object. |
325 | 333 |
* Make a user authentication through SRB RMI Connection. |
326 | 334 |
*/ |
327 |
|
|
328 | 335 |
private void handleLoginAction(PrintWriter out, Hashtable params, |
329 | 336 |
HttpServletRequest request, HttpServletResponse response) { |
330 | 337 |
|
... | ... | |
406 | 413 |
} |
407 | 414 |
|
408 | 415 |
/** |
409 |
*Create the squery xml, execute it and display it |
|
410 |
* @param out is the output stream to the client |
|
411 |
* @param params is the Hashtable of parameters that should be included |
|
412 |
* in the squery. |
|
413 |
* @param response is the response object linked to the client |
|
414 |
* @param conn the database connection |
|
415 |
*/ |
|
416 |
protected String handleSQuery(String xmlquery) |
|
416 |
* Retreive the squery xml, execute it and display it |
|
417 |
* |
|
418 |
* @param out the output stream to the client |
|
419 |
* @param params the Hashtable of parameters that should be included |
|
420 |
* in the squery. |
|
421 |
* @param response the response object linked to the client |
|
422 |
* @param conn the database connection |
|
423 |
*/ |
|
424 |
protected void handleSQuery(PrintWriter out, Hashtable params, |
|
425 |
HttpServletResponse response) |
|
417 | 426 |
{ |
427 |
String xmlquery = ((String[])params.get("query"))[0]; |
|
428 |
String qformat = ((String[])params.get("qformat"))[0]; |
|
418 | 429 |
Hashtable doclist = runQuery(xmlquery); |
419 | 430 |
String resultdoc = createResultDocument(doclist, xmlquery); |
420 |
return resultdoc; |
|
431 |
|
|
432 |
//format and transform the results |
|
433 |
if(qformat.equals("html")) { |
|
434 |
transformResultset(resultdoc, response, out); |
|
435 |
} else if(qformat.equals("xml")) { |
|
436 |
response.setContentType("text/xml"); |
|
437 |
out.println(resultdoc); |
|
438 |
} else { |
|
439 |
out.println("invalid qformat: " + qformat); |
|
440 |
} |
|
421 | 441 |
} |
422 | 442 |
|
423 | 443 |
/** |
424 |
*Create the xml query, execute it and display the results. |
|
425 |
* @param out is the output stream to the client |
|
426 |
* @param params is the Hashtable of parameters that should be included |
|
444 |
* Create the xml query, execute it and display the results. |
|
445 |
* |
|
446 |
* @param out the output stream to the client |
|
447 |
* @param params the Hashtable of parameters that should be included |
|
427 | 448 |
* in the squery. |
428 |
* @param response is the response object linked to the client
|
|
449 |
* @param response the response object linked to the client |
|
429 | 450 |
*/ |
430 | 451 |
protected void handleQuery(PrintWriter out, Hashtable params, |
431 | 452 |
HttpServletResponse response) |
432 | 453 |
{ |
433 |
|
|
434 |
|
|
435 | 454 |
//create the query and run it |
436 | 455 |
String xmlquery = DBQuery.createSQuery(params); |
437 | 456 |
Hashtable doclist = runQuery(xmlquery); |
438 | 457 |
String qformat = ((String[])params.get("qformat"))[0]; |
439 | 458 |
String resultdoc = createResultDocument(doclist, xmlquery); |
459 |
|
|
440 | 460 |
//format and transform the results |
441 |
if(qformat.equals("html")) |
|
442 |
{ |
|
461 |
if(qformat.equals("html")) { |
|
443 | 462 |
transformResultset(resultdoc, response, out); |
444 |
} |
|
445 |
else if(qformat.equals("xml")) |
|
446 |
{ |
|
463 |
} else if(qformat.equals("xml")) { |
|
447 | 464 |
response.setContentType("text/xml"); |
448 | 465 |
out.println(resultdoc); |
449 |
} |
|
450 |
else |
|
451 |
{ |
|
466 |
} else { |
|
452 | 467 |
out.println("invalid qformat: " + qformat); |
453 | 468 |
} |
454 | 469 |
} |
455 | 470 |
|
456 | 471 |
/** |
457 |
* Run the query and return a hashtable of results. |
|
458 |
* @param xmlquery the query to run |
|
459 |
*/ |
|
472 |
* Run the query and return a hashtable of results. |
|
473 |
* |
|
474 |
* @param xmlquery the query to run |
|
475 |
*/ |
|
460 | 476 |
protected Hashtable runQuery(String xmlquery) |
461 | 477 |
{ |
462 | 478 |
Hashtable doclist=null; |
... | ... | |
481 | 497 |
} |
482 | 498 |
} |
483 | 499 |
|
484 |
/**
|
|
500 |
/** |
|
485 | 501 |
* Transorms an xml resultset document to html and sends it to the browser |
502 |
* |
|
486 | 503 |
* @param resultdoc the string representation of the document that needs |
487 | 504 |
* to be transformed. |
488 | 505 |
* @param response the HttpServletResponse object bound to the client. |
489 | 506 |
* @param out the output stream to the client |
490 | 507 |
*/ |
491 | 508 |
protected void transformResultset(String resultdoc, |
492 |
HttpServletResponse response, |
|
493 |
PrintWriter out) |
|
509 |
HttpServletResponse response,
|
|
510 |
PrintWriter out)
|
|
494 | 511 |
{ |
495 | 512 |
Connection conn = null; |
496 |
try |
|
497 |
{ |
|
513 |
try { |
|
498 | 514 |
conn = util.getConnection(); |
499 | 515 |
DBTransform trans = new DBTransform(conn); |
500 | 516 |
response.setContentType("text/html"); |
501 | 517 |
trans.transformXMLDocument(resultdoc, "-//NCEAS//resultset//EN", |
502 | 518 |
"-//W3C//HTML//EN", out); |
503 |
} |
|
504 |
catch(Exception e) |
|
505 |
{ |
|
506 |
if (conn != null) |
|
507 |
{ |
|
519 |
} catch(Exception e) { |
|
520 |
if (conn != null) { |
|
508 | 521 |
util.returnConnection(conn); |
509 | 522 |
} |
510 | 523 |
} |
... | ... | |
512 | 525 |
|
513 | 526 |
/** |
514 | 527 |
* Transforms a hashtable of documents to an xml or html result. |
528 |
* |
|
515 | 529 |
* @param doclist- the hashtable to transform |
516 | 530 |
* @param xmlquery- the query that returned the dolist result |
517 | 531 |
*/ |
... | ... | |
525 | 539 |
String document = null; |
526 | 540 |
resultset.append("<?xml version=\"1.0\"?>\n"); |
527 | 541 |
resultset.append("<resultset>\n"); |
542 |
|
|
528 | 543 |
//the following should work but it doesn't because the parser doesn't |
529 | 544 |
//like the <?xml?> tag inside the <query> tag. This is supposed to be |
530 | 545 |
//the way that the query itself is sent back to the client. |
... | ... | |
722 | 737 |
} |
723 | 738 |
|
724 | 739 |
/** |
725 |
* Handle the validtion request and return the results to the requestor |
|
740 |
* Handle the validation request and return the results to the requestor
|
|
726 | 741 |
*/ |
727 | 742 |
private void handleValidateAction(PrintWriter out, Hashtable params, |
728 | 743 |
HttpServletResponse response) { |
... | ... | |
750 | 765 |
response.setContentType("text/xml"); |
751 | 766 |
out.println("<error>Error getting document ID: " + docid + "</error>"); |
752 | 767 |
if ( conn != null ) { util.returnConnection(conn); } |
753 |
return; // Jivka added
|
|
768 |
return; |
|
754 | 769 |
} catch (Exception e) { |
755 | 770 |
response.setContentType("text/html"); |
756 | 771 |
out.println(e.getMessage()); |
... | ... | |
783 | 798 |
} |
784 | 799 |
|
785 | 800 |
/** |
786 |
* Handle the document request and return the results |
|
787 |
* to the requestor |
|
801 |
* Handle the document request and return the results to the requestor |
|
788 | 802 |
*/ |
789 | 803 |
private void handleGetDataDocumentAction(PrintWriter out, Hashtable params, |
790 | 804 |
HttpServletResponse response) { |
... | ... | |
841 | 855 |
* Handle the getdoctypes Action. |
842 | 856 |
* Read all doctypes from db connection in XML format |
843 | 857 |
*/ |
844 |
|
|
845 | 858 |
private void handleGetDoctypesAction(PrintWriter out, Hashtable params, |
846 | 859 |
HttpServletResponse response) { |
847 | 860 |
|
... | ... | |
870 | 883 |
* Handle the getdataguide Action. |
871 | 884 |
* Read Data Guide for a given doctype from db connection in XML format |
872 | 885 |
*/ |
873 |
|
|
874 | 886 |
private void handleGetDataGuideAction(PrintWriter out, Hashtable params, |
875 | 887 |
HttpServletResponse response) { |
876 | 888 |
|
... | ... | |
904 | 916 |
} |
905 | 917 |
|
906 | 918 |
} |
907 |
|
|
908 |
/** |
|
909 |
* '$Log$ |
|
910 |
* 'Revision 1.74 2000/08/17 16:04:20 berkley |
|
911 |
* 'Changed the flow of query and SQuery. SQuery now only handles a preformatted pathquery document as input (in the "query" parameter). |
|
912 |
* 'HandleQuery now handles all structured queries derived by CGI parameters. |
|
913 |
* ' |
|
914 |
* 'Revision 1.73 2000/08/16 20:08:20 berkley |
|
915 |
* 'fixed bug with handleSQuery() that kept DMan from access the squery functionality |
|
916 |
* ' |
|
917 |
* 'Revision 1.72 2000/08/16 18:48:57 berkley |
|
918 |
* '- created transformResultset() which transforms an xml resultset document and displays it to the client useing DBTransform |
|
919 |
* '- renamed transformDocument() to createResultDocument() and modified its functionality to only return a restultset xml document |
|
920 |
* '- changed handleSQuery() and handleQuery() to use the new methods |
|
921 |
* ' |
|
922 |
* 'Revision 1.71 2000/08/15 20:48:05 berkley |
|
923 |
* 'remove handleQueryAction() in favor of directly calling handleQuery() and handleSQuery() from doGetOrPost() |
|
924 |
* ' |
|
925 |
* 'Revision 1.70 2000/08/15 20:02:15 bojilova |
|
926 |
* 'Cleared hardcoded paths for the location of .html files and use |
|
927 |
* 'the new "htmlpath" property from metacat.properties file |
|
928 |
* ' |
|
929 |
* 'Revision 1.69 2000/08/15 15:58:03 berkley |
|
930 |
* 'Added decodeMouseAction(Hashtable) to decode the mouse click action outside of handleGetOrPost to allow for easy modification of images in a different application. |
|
931 |
* ' |
|
932 |
* 'Revision 1.68 2000/08/14 21:28:54 berkley |
|
933 |
* '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. |
|
934 |
* ' |
|
935 |
* 'Revision 1.67 2000/08/14 20:43:27 jones |
|
936 |
* 'Updated build process to now use a copy of the source files so that keyword |
|
937 |
* 'substitution can ocur before the build. This allows for substitution of |
|
938 |
* 'hardcoded values into the source before the compile. Currently, I am |
|
939 |
* 'using this feature to do the following: |
|
940 |
* ' |
|
941 |
* ' 1) Substitute a "Release" number into the code |
|
942 |
* ' 2) Substitute a hardcoded servlet path into the code and html files |
|
943 |
* ' |
|
944 |
* 'By changing the value of "servlet-path" and "installdir" properties in |
|
945 |
* 'build.xml, one can now easily install a new version of the servlet in a |
|
946 |
* 'different location by simply using "ant install". |
|
947 |
* ' |
|
948 |
* 'Revision 1.66 2000/08/14 18:27:37 bojilova |
|
949 |
* 'added Logout handling |
|
950 |
* ' |
|
951 |
* 'Revision 1.64 2000/08/11 22:20:04 jones |
|
952 |
* 'Changed exception handling mechanisms for DBReader |
|
953 |
* ' |
|
954 |
* 'Revision 1.63 2000/08/11 18:25:26 berkley |
|
955 |
* 'broke up handleQueryAction into handleQuery, handleSQuery, runQuery and transformDocument |
|
956 |
* ' |
|
957 |
* 'Revision 1.61 2000/08/10 18:56:48 bojilova |
|
958 |
* 'added "anonymous" user connection |
|
959 |
* ' |
|
960 |
* 'Revision 1.60 2000/08/09 00:39:47 jones |
|
961 |
* '-Reorganized xmltodb module to support new install process for the new |
|
962 |
* 'linux server (dev.nceas.ucsb.edu). Added "build.sh" shell script that |
|
963 |
* 'calls ant withthe proper umask set for installation. Use: |
|
964 |
* ' |
|
965 |
* ' ./build.sh install |
|
966 |
* ' |
|
967 |
* 'to post a new copy of the servlet and its supporting files to the install |
|
968 |
* 'directory defined in build.xml. |
|
969 |
* ' |
|
970 |
* '-Updated the servlet to use a new servlet prefix that we'll use with the |
|
971 |
* 'Tomcat servlet engine. |
|
972 |
* ' |
|
973 |
* '-Update bin dir shell scripts to reflect new locations of relevant jar files. |
|
974 |
* ' |
|
975 |
* 'Revision 1.59 2000/08/08 00:31:20 bojilova |
|
976 |
* 'rearrange html pages for login and metacat access |
|
977 |
* ' |
|
978 |
* 'Revision 1.58 2000/08/04 23:34:09 bojilova |
|
979 |
* 'more precise handling of the Connection Pool |
|
980 |
* ' |
|
981 |
* 'Revision 1.57 2000/08/03 23:20:31 bojilova |
|
982 |
* 'Changes related to "getdataguide" action |
|
983 |
* ' |
|
984 |
* 'Revision 1.55 2000/08/01 18:26:50 bojilova |
|
985 |
* 'added Pool of Connections |
|
986 |
* 'DBQuery, DBReader, DBTransform, DBUtil are created on every request and use the connections from the Pool |
|
987 |
* 'same with DBWriter and DBValidate |
|
988 |
* ' |
|
989 |
* 'Revision 1.54 2000/07/27 23:12:21 bojilova |
|
990 |
* 'Added "getdoctypes" and "getdataguide" action handlers |
|
991 |
* ' |
|
992 |
* 'Revision 1.53 2000/07/26 20:48:29 bojilova |
|
993 |
* 'Added "Login Client" action for login from the Desktop Client |
|
994 |
* ' |
|
995 |
* 'Revision 1.52 2000/07/26 20:38:40 higgins |
|
996 |
* 'no message |
|
997 |
* ' |
|
998 |
* 'Revision 1.51 2000/07/01 01:09:44 jones |
|
999 |
* 'MetaCatServlet.java |
|
1000 |
* ' |
|
1001 |
* 'Revision 1.50 2000/06/30 23:42:33 bojilova |
|
1002 |
* 'finished user auth & session tracking |
|
1003 |
* ' |
|
1004 |
* 'Revision 1.49 2000/06/29 23:27:08 jones |
|
1005 |
* 'Fixed bug in DBEntityResolver so that it now properly delegates to |
|
1006 |
* 'the system id found inthe database. |
|
1007 |
* 'Changed DBValidate to use DBEntityResolver, rather than the OASIS |
|
1008 |
* 'catalog, and to return validation results in XML format. |
|
1009 |
* ' |
|
1010 |
* 'Revision 1.48 2000/06/29 20:04:51 bojilova |
|
1011 |
* 'testing login |
|
1012 |
* ' |
|
1013 |
* 'Revision 1.36 2000/06/28 02:36:26 jones |
|
1014 |
* 'Added feature to now ouput COMMENTs and PIs when the document is |
|
1015 |
* 'read from the database with DBReader. |
|
1016 |
* ' |
|
1017 |
* 'Revision 1.35 2000/06/28 00:00:47 bojilova |
|
1018 |
* 'changed to |
|
1019 |
* 'response.sendRedirect(response.encodeRedirectUrl("/xmltodb/lib/index.html")); |
|
1020 |
* ' |
|
1021 |
* 'Revision 1.33 2000/06/27 04:50:33 jones |
|
1022 |
* 'Updated javadoc documentation. |
|
1023 |
* ' |
|
1024 |
* 'Revision 1.32 2000/06/27 04:31:07 jones |
|
1025 |
* 'Fixed bugs associated with the new UPDATE and DELETE functions of |
|
1026 |
* 'DBWriter. There were problematic interactions between some static |
|
1027 |
* 'variables used in DBEntityResolver and the way in which the |
|
1028 |
* 'Servlet objects are re-used across multiple client invocations. |
|
1029 |
* ' |
|
1030 |
* 'Generally cleaned up error reporting. Now all errors and success |
|
1031 |
* 'results are reported as XML documents from MetaCatServlet. Need |
|
1032 |
* 'to make the command line tools do the same. |
|
1033 |
* ' |
|
1034 |
* 'Revision 1.31 2000/06/26 10:35:05 jones |
|
1035 |
* 'Merged in substantial changes to DBWriter and associated classes and to |
|
1036 |
* 'the MetaCatServlet in order to accomodate the new UPDATE and DELETE |
|
1037 |
* 'functions. The command line tools and the parameters for the |
|
1038 |
* 'servlet have changed substantially. |
|
1039 |
* ' |
|
1040 |
* 'Revision 1.30.2.6 2000/06/26 10:18:06 jones |
|
1041 |
* 'Partial fix for MetaCatServlet INSERT?UPDATE bug. Only will work on |
|
1042 |
* 'the first call to the servlet. Subsequent calls fail. Seems to be |
|
1043 |
* 'related to exception handling. Multiple successive DELETE actions |
|
1044 |
* 'work fine. |
|
1045 |
* ' |
|
1046 |
* 'Revision 1.30.2.5 2000/06/26 09:09:53 jones |
|
1047 |
* 'Modified MetaCatServlet and associated files to handle the UPDATE |
|
1048 |
* 'and DELETE actions for DBWriter. |
|
1049 |
* ' |
|
1050 |
* 'Revision 1.30.2.4 2000/06/26 00:51:06 jones |
|
1051 |
* 'If docid passed to DBWriter.write() is not unique, classes now generate |
|
1052 |
* 'an AccessionNumberException containing the new docid generated as a |
|
1053 |
* 'replacement. The docid is then extracted from the exception and |
|
1054 |
* 'returned to the calling application for user feedback or client processing. |
|
1055 |
* ' |
|
1056 |
* 'Revision 1.30.2.3 2000/06/25 23:38:17 jones |
|
1057 |
* 'Added RCSfile keyword |
|
1058 |
* ' |
|
1059 |
* 'Revision 1.30.2.2 2000/06/25 23:34:18 jones |
|
1060 |
* 'Changed documentation formatting, added log entries at bottom of source files |
|
1061 |
* '' |
|
1062 |
*/ |
Also available in: Unified diff
Modified behavior of handleSQuery() to now send the resultset document
back to the client application -- this was a bug introduced by recent
changes to the servlet. Also, generally cleaned up the servlet to
produce cleaner documentation and removed some extraneous code and remarks.
Removed the 'Log' entries at the end of the code -- they were causing too much
extraneous output in source diff's.