Project

General

Profile

« Previous | Next » 

Revision 437

Added by berkley over 24 years ago

added support for getabstract action

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
260 260
      if(params.containsKey("query"))
261 261
      {
262 262
        handleSQuery(out, params, response); 
263
        //handleSQuery(((String[])params.get("query"))[0]);
264 263
      }
265 264
      else
266 265
      {
......
288 287
        out.println("Permission denied for " + action);
289 288
      }  
290 289
    } else if (action.equals("validate")) {
291
      handleValidateAction(out, params, response);  
290
      handleValidateAction(out, params, response); 
291
    } else if (action.equals("getabstract")) {
292
      try{
293
        handleViewAbstractAction(out, params, response);
294
      }
295
      catch(Exception e)
296
      {
297
        out.println("error viewing abstract: " + e.getMessage());
298
      }
292 299
    } else if (action.equals("getdatadoc")) {
293 300
      handleGetDataDocumentAction(out, params, response);  
294 301
    } else if (action.equals("getdoctypes")) {
......
532 539
    resultset.append("</resultset>");
533 540
    return resultset.toString();
534 541
  }
542
  
543
  /**
544
   * Handle the request to view the abstract of a document.
545
   */
546
  private void handleViewAbstractAction(PrintWriter out, Hashtable params,
547
               HttpServletResponse response) throws IOException, SQLException
548
  {
549
    String abstractpath = null;
550
    String docid = null;
551
    Connection conn = null;
552
    response.setContentType("text/html");
553
    try
554
    {
555
      docid = ((String[])params.get("docid"))[0];
556
      if(params.containsKey("abstractpath"))
557
      {
558
        abstractpath = ((String[])params.get("abstractpath"))[0];
559
      }
560
      else
561
      {
562
        out.println("error: no abstractpath parameter"); 
563
      }
564
      conn = util.getConnection();
565
    
566
      Object[] abstracts = DBQuery.getNodeContent(abstractpath, docid, conn);
567
    
568
      out.println("<html><head><title>Abstract</title></head><body>");
569
      out.println("<h1>Abstract</h1>");
570
      for(int i=0; i<abstracts.length; i++)
571
      {
572
        out.println("<p>" + (String)abstracts[i] + "</p>");
573
      }
574
      out.println("</body></html>");
575
    }
576
    catch (IOException ioe)
577
    {
578
       System.out.println(ioe.getMessage());
579
    }
580
    catch(SQLException sqle)
581
    {
582
      System.out.println(sqle.getMessage()); 
583
    }
584
    catch(Exception e)
585
    {
586
      System.out.println(e.getMessage());
587
    }
588
    
589
    util.returnConnection(conn);
590
  }
535 591

  
536 592
  /** 
537 593
   * Handle the database getdocument request and return a XML document, 
......
549 605
      // Find the document id number
550 606
      docidstr = ((String[])params.get("docid"))[0]; 
551 607
      docid = docidstr;
552

  
553 608
      conn = util.getConnection();
554 609
      DocumentImpl xmldoc = new DocumentImpl(conn, docid);
555 610
      // Get the document indicated from the db
556 611
      //doc = docreader.readXMLDocument(docid);
557 612

  
558 613
      // Return the document in XML or HTML format
559
      String qformat = ((String[])params.get("qformat"))[0]; 
560
      if (qformat.equals("xml")) {
614
      String qformat=null;
615
      if(params.containsKey("qformat"))
616
      {
617
        qformat = ((String[])params.get("qformat"))[0];
618
      }
619
      else
620
      {
621
        qformat = "html";        
622
      }
623
      if (qformat.equals("xml")) { 
561 624
        // set content type and other response header fields first
562 625
        response.setContentType("text/xml");
563 626
        xmldoc.toXml(out);
564 627
        //out.println(xmldoc);
565 628
      } else if (qformat.equals("html")) {
566

  
629
        response.setContentType("text/html");
567 630
        // Look up the document type
568 631
        String sourcetype = xmldoc.getDoctype();
569

  
570 632
        // Transform the document to the new doctype
571 633
        DBTransform dbt = new DBTransform(conn);
572 634
        dbt.transformXMLDocument(xmldoc.toString(), sourcetype, 

Also available in: Unified diff