Project

General

Profile

« Previous | Next » 

Revision 465

Added by berkley almost 24 years ago

Added backtrack functionality. Backtracking works by passing a returndoc parameter. There can be more than one. If a document that is hit by a query is not of type returndoc then it searches the database for a related file of type returndoc. If one is found it is displayed, if no relation is found, the original is displayed.

Support was also added for an index of relations. the table xml_relation handles the all of the relation indexing.

View differences:

MetaCatServlet.java
103 103
  // in defaultdocpath dir
104 104
  private String executescript  = null;  
105 105

  
106

  
107 106
  /**
108 107
   * Initialize the servlet by creating appropriate database connections
109 108
   */
......
335 334
      PrintWriter out = response.getWriter();
336 335
      out.println("Error: action not registered.  Please report this error.");
337 336
    }
338

  
337
    util.closeConnections();
339 338
    // Close the stream to the client
340 339
    //out.close();
341 340
  }
......
414 413
  { 
415 414
    String xmlquery = ((String[])params.get("query"))[0];
416 415
    String qformat = ((String[])params.get("qformat"))[0];
417
    Hashtable doclist = runQuery(xmlquery, user, group);
418
    String resultdoc = createResultDocument(doclist, transformQuery(xmlquery));
416
    String resultdoc = null;
417
    String[] returndoc = null;
418
    if(params.contains("returndoc"))
419
    {
420
      returndoc = (String[])params.get("returndoc");
421
    }
422
    
423
    Hashtable doclist = runQuery(xmlquery, user, group, returndoc);
424
    //String resultdoc = createResultDocument(doclist, transformQuery(xmlquery));
419 425

  
426
    resultdoc = createResultDocument(doclist, transformQuery(xmlquery));
427
    
420 428
    //format and transform the results                                        
421 429
    if(qformat.equals("html")) {
422 430
      transformResultset(resultdoc, response, out);
......
440 448
                 HttpServletResponse response, String user, String group)
441 449
  {
442 450
    //create the query and run it
451
    String[] returndoc = null;
452
    if(params.containsKey("returndoc"))
453
    {
454
      returndoc = (String[])params.get("returndoc");
455
    }
443 456
    String xmlquery = DBQuery.createSQuery(params);
444
    Hashtable doclist = runQuery(xmlquery, user, group);
445
    String qformat = ((String[])params.get("qformat"))[0]; 
446
    String resultdoc = createResultDocument(doclist, transformQuery(params));
457
    Hashtable doclist = runQuery(xmlquery, user, group, returndoc);
458
    String qformat = ((String[])params.get("qformat"))[0];
459
    String resultdoc = null;
460
    
461
    resultdoc = createResultDocument(doclist, transformQuery(params));
447 462

  
448 463
    //format and transform the results                                        
449 464
    if(qformat.equals("html")) {
......
494 509
   *
495 510
   * @param xmlquery the query to run
496 511
   */
497
  private Hashtable runQuery(String xmlquery, String user, String group)
512
  private Hashtable runQuery(String xmlquery, String user, String group, 
513
                             String[] returndoc)
498 514
  {
499 515
    Hashtable doclist=null;
500 516
    Connection conn = null;
......
502 518
    {
503 519
      conn = util.getConnection();
504 520
      DBQuery queryobj = new DBQuery(conn, saxparser);
505
      doclist = queryobj.findDocuments(new StringReader(xmlquery),user,group);
521
      doclist = queryobj.findDocuments(new StringReader(xmlquery),user,group,
522
                                       returndoc);
506 523
      util.returnConnection(conn);
507 524
      return doclist;
508 525
    } 
......
544 561
  
545 562
  /**
546 563
   * Transforms a hashtable of documents to an xml or html result.
564
   * If there is a returndoc, then it only displays documents of
565
   * whatever type returndoc represents.  If a result is found in a document
566
   * that is not of type returndoc then this attempts to find a relation 
567
   * between this document and one that satifies the returndoc doctype.
547 568
   *
548 569
   * @param doclist- the hashtable to transform
549 570
   * @param xmlquery- the query that returned the dolist result
571
   * @param resultdoc- the document type to backtrack to.
550 572
   */
551 573
  protected String createResultDocument(Hashtable doclist, String xmlquery)
552 574
  {
......
558 580
    String document = null;
559 581
    resultset.append("<?xml version=\"1.0\"?>\n");
560 582
    resultset.append("<resultset>\n");
561
    
583
      
562 584
    resultset.append("  <query>" + xmlquery + "</query>");   
563
 
585
      
564 586
    Enumeration doclistkeys = doclist.keys(); 
565 587
    while (doclistkeys.hasMoreElements()) 
566 588
    {
......
648 670
          String[] murlParams = murl.getParam(0);
649 671
          if(murlParams[0].equals("docid"))
650 672
          {//the docid should be first
651
            murl.printParams();
673
            //murl.printParams();
652 674
            docid = murlParams[1]; //get the docid value
653 675
            conn = util.getConnection();
654 676
            xmldoc = new DocumentImpl(conn, docid);
......
796 818
                    accNumber = null;
797 819
                }
798 820
                newdocid = DocumentImpl.write(conn, xml, doAction, accNumber, 
799
                                                                  user, group);
821
                                              user, group);
822
                DocumentImpl xmldoc = new DocumentImpl(conn, newdocid);
823
                
824
               //if this is a package file then write the package info to 
825
               //the xml_relation table. relationHandler checks to see
826
               //if it is a package file so you don't have to do it here.
827
               relationHandler rth = new relationHandler(xmldoc);
828
                
800 829
            } catch (NullPointerException npe) {
801 830
              newdocid = DocumentImpl.write(conn,xml,doAction,null,user,group);
802 831
            }

Also available in: Unified diff