Project

General

Profile

« Previous | Next » 

Revision 361

Added by berkley over 24 years ago

remove handleQueryAction() in favor of directly calling handleQuery() and handleSQuery() from doGetOrPost()

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
3 3
 *    Purpose: A Class that implements a metadata catalog as a java Servlet
4 4
 *  Copyright: 2000 Regents of the University of California and the
5 5
 *             National Center for Ecological Analysis and Synthesis
6
 *    Authors: Matt Jones, Dan Higgins, Jivka Bojilova
6
 *    Authors: Matt Jones, Dan Higgins, Jivka Bojilova, Chad Berkley
7 7
 *    Release: @release@
8 8
 *
9 9
 *   '$Author$'
......
30 30
import java.sql.ResultSet;
31 31
import java.sql.Connection;
32 32
import java.sql.SQLException;
33
import java.lang.reflect.*;
33 34

  
34 35
import javax.servlet.ServletConfig;
35 36
import javax.servlet.ServletContext;
......
226 227
        out.println("</success>");
227 228
        return;
228 229
      }    
230

  
229 231
      response.sendRedirect(htmlpath + "/index.html"); 
232

  
230 233
    // aware of session expiration on every request  
231 234
    } else {   
232 235
      HttpSession sess = request.getSession(true);
......
234 237
        // session expired or has not been stored b/w user requests
235 238
        // redirect to default page for query only access
236 239

  
240

  
237 241
      //  response.sendRedirect(htmlpath + "/sexpire.html");
242

  
238 243
      } 
239 244
    }    
240 245
// End of Jivka added
241 246

  
242
    if (action.equals("query") || action.equals("squery")) {
243
      handleQueryAction(out, params, response);
244
    } else if (action.equals("getdocument")) {
247
    try
248
    {
249
      Class[] x = {Class.forName("PrintWriter"), 
250
                   Class.forName("Hashtable"), 
251
                   Class.forName("HttpServletResponse")};
252
      Class c = Class.forName("edu.ucsb.nceas.metacat.MetaCatServlet");
253
      Method m = c.getDeclaredMethod("handleQueryAction", x);
254
 
255
    }
256
    catch(Exception e)
257
    {
258
       
259
    }
260

  
261
    if(action.equals("query"))
262
    {
263
      handleQuery(out, params, response); 
264
    }
265
    else if(action.equals("squery")) 
266
    {
267
      handleSQuery(out, params, response);
268
    } 
269
    else if (action.equals("getdocument")) {
245 270
      try {
246 271
        handleGetDocumentAction(out, params, response);
247 272
      } catch (ClassNotFoundException e) {
......
393 418
    * @param params is the Hashtable of parameters that should be included
394 419
    * in the squery.
395 420
    */
396
  private String handleSQuery(Hashtable params) 
421
  private void handleSQuery(PrintWriter out, Hashtable params, 
422
                            HttpServletResponse response) 
397 423
  {
398 424
    //create the squery and return it to be processed
399 425
    String doctype = null;
......
408 434
    {
409 435
      doctype="ANY"; 
410 436
    }
411
    return DBQuery.createSQuery(params, doctype);
437
    String xmlquery = DBQuery .createSQuery(params, doctype);
438
    Hashtable doclist = runQuery(xmlquery);
439
    String qformat = ((String[])params.get("qformat"))[0]; 
440
    transformDocument(doclist, qformat, xmlquery, out, response);
412 441
  }
413 442
  
414 443
   /**
......
417 446
    * @param doctype is the doctype parameter returned through the CGI. 
418 447
    * If no doctype filter is required, set it to null or "".
419 448
    */
420
  private String handleQuery(Hashtable params)
449
  private void handleQuery(PrintWriter out, Hashtable params, 
450
                           HttpServletResponse response)
421 451
  {
422 452
    String doctype=null; 
423 453
    String[] doctypeArr=null; 
......
449 479
    {
450 480
      doctype="ANY"; 
451 481
    }
452
    return DBQuery.createQuery(query,doctype);
482
    String xmlquery = DBQuery.createQuery(query, doctype);
483
    Hashtable doclist = runQuery(xmlquery);
484
    String qformat = ((String[])params.get("qformat"))[0]; 
485
    transformDocument(doclist, qformat, xmlquery, out, response);
453 486
  }
454 487
  
455 488
  /**
456 489
    * Run the query and return a hashtable of results.
457 490
    */
458
  private Hashtable runQuery(StringBuffer xmlquery)
491
  private Hashtable runQuery(String xmlquery)
459 492
  {
460 493
    Hashtable doclist=null;
461 494
    Connection conn = null;
......
463 496
    {
464 497
        conn = util.getConnection();
465 498
        DBQuery queryobj = new DBQuery(conn, saxparser);
466
        doclist = queryobj.findDocuments(new StringReader(xmlquery.toString()));
499
        doclist = queryobj.findDocuments(new StringReader(xmlquery));
467 500
        util.returnConnection(conn);
468 501
        return doclist;
469 502
    } 
......
534 567
      }
535 568
    }
536 569
  }
537
                              
538
  /** 
539
   * Handle the database query request and return a result set, possibly
540
   * transformed from XML into HTML
541
   */ 
542
  private void handleQueryAction(PrintWriter out, Hashtable params, 
543
                                 HttpServletResponse response)  
544
  {
545
      String action = ((String[])params.get("action"))[0];
546
      Hashtable doclist = null;
547
      String[] doctypeArr = null;
548
      String doctype = null;
549
      StringBuffer xmlquery = null;
550
      Connection conn = null;
551 570

  
552
      if(action.equals("query"))
553
      {
554
        xmlquery = new StringBuffer(handleQuery(params));
555
      }
556
      else if(action.equals("squery"))
557
      {
558
        xmlquery = new StringBuffer(handleSQuery(params));
559
      }
560
      //System.out.println("Query is: ");
561
      //System.out.println(xmlquery.toString());
562
      
563
      doclist = runQuery(xmlquery);
564
      //System.out.println("result is: " );
565
      //System.out.println(doclist.toString());
566
      String qformat = ((String[])params.get("qformat"))[0]; 
567
      transformDocument(doclist, qformat, xmlquery.toString(), out, response);
568
  }
569

  
570 571
  /** 
571 572
   * Handle the database getdocument request and return a XML document, 
572 573
   * possibly transformed from XML into HTML
......
932 933

  
933 934
/**
934 935
 * '$Log$
936
 * 'Revision 1.70  2000/08/15 20:02:15  bojilova
937
 * 'Cleared hardcoded paths for the location of .html files and use
938
 * 'the new "htmlpath" property from metacat.properties file
939
 * '
935 940
 * 'Revision 1.69  2000/08/15 15:58:03  berkley
936 941
 * 'Added decodeMouseAction(Hashtable) to decode the mouse click action outside of handleGetOrPost to allow for easy modification of images in a different application.
937 942
 * '

Also available in: Unified diff