Project

General

Profile

« Previous | Next » 

Revision 1483

Added by Jing Tao over 21 years ago

Add a new action readilninedata for metacat. By this action, user can read inline data only.

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
332 332
        handleExportAction(params, response, username, groupnames, password);
333 333
      } else if (action.equals("read")) {
334 334
        handleReadAction(params, response, username,password, groupnames);
335
      } else if (action.equals("readinlinedata")) {
336
        handleReadInlineDataAction(params, response, username, 
337
                                   password, groupnames);
335 338
      } else if (action.equals("insert") || action.equals("update")) {
336 339
        PrintWriter out = response.getWriter();
337 340
        if ( (username != null) &&  !username.equals("public") ) {
......
817 820

  
818 821
  }//handleExportAction
819 822

  
823
  
824
   //read inline data section
825
 /**
826
   * In eml2 document, the xml can have inline data and data was stripped off 
827
   * and store in file system. This action can be used to read inline data only
828
   * @param params the Hashtable of HTTP request parameters
829
   * @param response the HTTP response object linked to the client
830
   * @param user the username sent the request
831
   * @param groups the user's groupnames
832
   */
833
  private void handleReadInlineDataAction(Hashtable params,
834
                                          HttpServletResponse response,
835
                                          String user, String passWord,
836
                                          String[] groups)
837
  {
838
    String[] docs = new String[10];
839
    String inlineDataId = null;
840
    String docId = "";
841
    ServletOutputStream out = null;
842

  
843
    try
844
    {
845
      // read the params
846
      if (params.containsKey("dataid"))
847
      {
848
        docs = (String[])params.get("dataid");
849
      }//if
850
      // Get the docid
851
      inlineDataId=docs[0];
852
      // Make sure the client specify docid
853
      if (inlineDataId == null || inlineDataId.equals(""))
854
      {
855
        // Get a printwriter
856
        PrintWriter pw = response.getWriter();
857
        // Send back message
858
        pw.println("<?xml version=\"1.0\"?>");
859
        pw.println("<error>");
860
        pw.println("You didn't specify requested docid");
861
        pw.println("</error>");
862
        // Close printwriter
863
        pw.close();
864
        return;
865
      }//if
866
      
867
      // check for permission
868
      docId = MetaCatUtil.getDocIdWithRevFromInlineDataID(inlineDataId);
869
      
870
      // Get output stream
871
      out = response.getOutputStream();
872
      // read the inline data from the file
873
      String inlinePath = MetaCatUtil.getOption("inlinedatafilepath");
874
      File lineData = new File(inlinePath, inlineDataId);
875
      FileInputStream input = new FileInputStream(lineData);
876
      byte [] buffer = new byte[4*1024];
877
      int bytes = input.read(buffer);
878
      while (bytes != -1)
879
      {
880
        out.write(buffer, 0, bytes);
881
        bytes = input.read(buffer);
882
      }
883
      out.close();
884

  
885
    }//try
886
    catch (Exception e)
887
    {
888
      try
889
      {
890
        // Send error message back
891
        if (out != null)
892
        {
893
            PrintWriter pw = new PrintWriter(out);
894
            pw.println("<?xml version=\"1.0\"?>");
895
            pw.println("<error>");
896
            pw.println(e.getMessage());
897
            pw.println("</error>");
898
            // Close printwriter
899
            pw.close();
900
            // Close output stream
901
            out.close();
902
        }//if
903
     }//try
904
     catch (IOException ioe)
905
     {
906
        MetaCatUtil.debugMessage("Problem with the servlet output " +
907
                           "in MetacatServlet.handleExportAction: " +
908
                           ioe.getMessage(), 30);
909
     }//catch
910

  
911
      MetaCatUtil.debugMessage("Error in MetacatServlet.handleReadInlineDataAction: " 
912
                                + e.getMessage(), 30);
913
   
914
    }//catch
915

  
916
  }//handleReadInlineDataAction
917
  
918
  
919
  
920
  
820 921
  // READ SECTION
821 922
  /**
822 923
   * Handle the "read" request of metadata/data files from Metacat

Also available in: Unified diff