Project

General

Profile

« Previous | Next » 

Revision 943

Added by Jing Tao over 22 years ago

A new action named export was add to it. This action will export a zip output stream for a data package. In the zip output stream, meta data documents, data files and a html summary file are include. The stucture will looks like:
package----/metadata/metadata docments |
----/data/data files |
----html file

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
72 72
 * <p>Valid parameters are:<br>
73 73
 * action=query -- query the values of all elements and attributes
74 74
 *                     and return a result set of nodes<br>
75
 * action=squery -- structured query (see pathquery.dtd)<br>
75
 * action=squery -- structured query (see pathquery.dtd)<br> 
76
 * action= -- export a zip format for data packadge<br>
76 77
 * action=read -- read any metadata/data file from Metacat and from Internet<br>
77 78
 * action=insert -- insert an XML document into the database store<br>
78 79
 * action=update -- update an XML document that is in the database store<br>
......
206 207
    if (ctype != null && ctype.startsWith("multipart/form-data")) {
207 208
      handleMultipartForm(request, response);
208 209
    } else {
209
      // This probably means the data is "application/x-www-url-encoded", we hope :-)
210
    
210 211
  
211 212
      String name = null;
212 213
      String[] value = null;
......
281 282
        handleQuery(response.getWriter(),params,response,username,groupnames);
282 283
      } else if(action.equals("squery")) {
283 284
        if(params.containsKey("query")) {
284
          handleSQuery(response.getWriter(),params,response,username,groupnames); 
285
         handleSQuery(response.getWriter(),params,response,username,groupnames); 
285 286
        } else {
286 287
          PrintWriter out = response.getWriter();
287 288
          out.println("Illegal action squery without \"query\" parameter");
288 289
        }
290
      } else if (action.equals("export")) {
291
        //username and groupname have to continue using though they are 
292
        //not standard
293
        handleExportAction(params, response, username, groupnames);
289 294
      } else if (action.equals("read")) {
290 295
        handleReadAction(params, response, username, groupnames);
291 296
      } else if (action.equals("insert") || action.equals("update")) {
......
642 647
  }
643 648
  // END OF SQUERY & QUERY SECTION
644 649
  
650
 //Exoport section
651
 /**
652
   * Handle the "export" request of data package from Metacat in zip format
653
   * @param params the Hashtable of HTTP request parameters
654
   * @param response the HTTP response object linked to the client
655
   * @param user the username sent the request
656
   * @param groups the user's groupnames
657
   */
658
  private void handleExportAction(Hashtable params,
659
                    HttpServletResponse response, String user, String[] groups)
660
  {
661
    ServletOutputStream out = null;
662
    ZipOutputStream zOut = null;
663
    DocumentImpl docImpls=null;
664
    DBQuery queryObj=null;
665
    Connection conn = null;
666
    String[] docs = new String[10];
667
    String docId = "";
668

  
669
    try
670
    {
671
      // read the params
672
      if (params.containsKey("docid")) {
673
        docs = (String[])params.get("docid");
674
      }
675

  
676
      //get the connection to database
677
      conn = util.getConnection();
678
      queryObj = new DBQuery(conn, saxparser);//"saxparser" have to use though
679
                                              //it is not standard
680
      docId=docs[0];
681
      out = response.getOutputStream();
682
      response.setContentType("application/zip"); //MIME type
683
      zOut = new ZipOutputStream(out);
684
      zOut =queryObj.getZippedPackage(docId, out, user, groups);
685
      zOut.finish(); //terminate the zip file
686
      zOut.close();  //close the zip stream
687
    } 
688
    catch (Exception e)
689
    {
690
      try
691
      {
692
        response.setContentType("text/xml"); //MIME type
693
        if (out != null)
694
        {
695
            PrintWriter pw = new PrintWriter(out);
696
            pw.println("<?xml version=\"1.0\"?>");
697
            pw.println("<error>");
698
            pw.println(e.getMessage());
699
            pw.println("</error>");
700
            pw.close();
701
        }
702

  
703
        if ( zOut != null )
704
        {
705
          zOut.close();
706
        }
707
      }
708
      catch (IOException ioe)
709
      {
710
        util.debugMessage("Problem with the servlet output " +
711
                           "in MetacatServlet.handleReadAction: " +
712
                           ioe.getMessage());
713
        
714

  
715
      }
716

  
717
      util.debugMessage("Error in MetacatServlet.handleReadAction: " +
718
                         e.getMessage());
719
      
720
    }//catch
721

  
722
  }//handleExportAction
723
  
645 724
  // READ SECTION
646 725
  /** 
647 726
   * Handle the "read" request of metadata/data files from Metacat
......
771 850
  // read metadata or data from Metacat
772 851
  private void readFromMetacat(HttpServletResponse response, String docid,
773 852
                               String qformat, String abstrpath, String user,
774
                               String[] groups, boolean zip, ZipOutputStream zout)
853
                             String[] groups, boolean zip, ZipOutputStream zout)
775 854
               throws ClassNotFoundException, IOException, SQLException, 
776 855
                      McdbException, Exception
777 856
  {
......
1489 1568

  
1490 1569
    try {
1491 1570
      // MBJ: need to put filesize limit in Metacat config (metacat.properties)
1492
      MultipartParser mp = new MultipartParser(request, 200*1024*1024); // 200MB
1571
      MultipartParser mp = new MultipartParser(request, 200*1024*1024); //200MB
1493 1572
      Part part;
1494 1573
      while ((part = mp.readNextPart()) != null) {
1495 1574
        String name = part.getName();
......
1558 1637
        try {
1559 1638
          out = response.getWriter();
1560 1639
        } catch (IOException ioe2) {
1561
          System.err.println("Fatal Error: couldn't get response output stream.");
1640
          util.debugMessage("Fatal Error: couldn't get response "+
1641
                                                              "output stream.");
1562 1642
        }
1563 1643
        out.println("<?xml version=\"1.0\"?>");
1564 1644
        out.println("<error>");

Also available in: Unified diff