Project

General

Profile

« Previous | Next » 

Revision 1459

Added by Jing Tao about 21 years ago

Add the code to pull out inlinedata and store it into file system. Only the file name will be stored into db.

View differences:

src/edu/ucsb/nceas/metacat/EmlSAXHandler.java
29 29
package edu.ucsb.nceas.metacat;
30 30

  
31 31
import java.sql.*;
32
import java.io.File;
33
import java.io.FileWriter;
32 34
import java.io.StringReader;
33 35
import java.util.Stack;
34 36
import java.util.Vector;
......
65 67
                                      //additionalmetadata/describes
66 68
   private Stack subTreeInfoStack = new Stack();
67 69
   private Vector subTreeList = new Vector();// store the final subtree
70
   private int inLineDataIndex = 1;
68 71
 
69 72
 
70 73
   // Constant
......
73 76
   private static final String ORDER = "order";
74 77
   private static final String ID ="id";
75 78
   private static final String REFERENCES = "references";
79
   public  static final String INLINE = "inline";
76 80
      
77
   /** Construct an instance of the handler class
78
    *
79
    * @param conn the JDBC connection to which information is written
80
    * @param action - "INSERT" or "UPDATE"
81
    * @param docid to be inserted or updated into JDBC connection
82
    * @param user the user connected to MetaCat servlet and owns the document
83
    * @param groups the groups to which user belongs
84
    * @param pub flag for public "read" access on document
85
    * @param serverCode the serverid from xml_replication on which this document
86
    *        resides.
87
    *
88
    */
89
   public EmlSAXHandler(DBConnection conn, String action, String docid,
90
                      String user, String[] groups, String pub, int serverCode)
91
   {
92
     super(conn, action, docid, user, groups, pub, serverCode);
93
   }
94
   
81
  
95 82
    /** Construct an instance of the handler class
96 83
    * In this constructor, user can specify the version need to upadate
97 84
    *
......
342 329
     {
343 330
       accessObject = null;
344 331
     }
332
       
345 333
   
346 334
     // Add the node to the stack, so that any text data can be
347 335
     // added as it is encountered
......
436 424
          }
437 425
          
438 426
       }
439
       // write text to db
440
       MetaCatUtil.debugMessage("Write text into DB in End Element", 50);
441
       endNodeId = writeTextForDBSAXNode(textBuffer, currentNode);
427
       // write text to db if it is not inline data
428
       if (!localName.equals(INLINE))
429
       {
430
          MetaCatUtil.debugMessage("Write text into DB in End Element", 50);
431
          endNodeId = writeTextForDBSAXNode(textBuffer, currentNode);
432
       }
433
       else
434
       {
435
          MetaCatUtil.debugMessage("Write inline data into file system", 25);
436
          // write inline data into file system and return file name
437
          textBuffer = writeInlineDataIntoFile(textBuffer);
438
          // write file name into db
439
          endNodeId = writeTextForDBSAXNode(textBuffer, currentNode);
440
       }
442 441
     }//if
443 442
     
444 443
     //set hitText false
......
807 806
        throw new SAXException(ee.getMessage());
808 807
      }
809 808
    }
809
  }//deletePermissionsInAccessTable
810
  
811
  // write inline data into file system and return file name(without path)
812
  private StringBuffer writeInlineDataIntoFile(StringBuffer data) 
813
                                               throws SAXException
814
  {
815
    StringBuffer fileNameBuffer = null;
816
    String fileName = null;
817
    String docidWithoutRev = MetaCatUtil.getDocIdFromString(docid);
818
    String path = MetaCatUtil.getOption("inlinedatafilepath");
819
    String seperator = MetaCatUtil.getOption("accNumSeparator");
820
    // the new file name will look like path/docid.rev.2
821
    fileName = docidWithoutRev + seperator+revision+seperator +inLineDataIndex;
822
    File inlineDataDirectory = new File(path);
823
    File newFile = new File(inlineDataDirectory, fileName); 
824
    // incease inLinedataindex for next one
825
    inLineDataIndex++ ;
826
    try
827
    {
828
      FileWriter writer = new FileWriter(newFile);
829
      writer.write(data.toString());
830
    }
831
    catch (Exception e)
832
    {
833
      throw new SAXException(e.getMessage());
834
    }
835
    
836
    fileNameBuffer = new StringBuffer(fileName);
837
    return fileNameBuffer;
810 838
  }
811 839
 
812 840
}

Also available in: Unified diff