Project

General

Profile

« Previous | Next » 

Revision 1517

Added by Jing Tao about 21 years ago

Add code for checking if a user try to update inline data.

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.BufferedReader;
32 33
import java.io.File;
34
import java.io.FileReader;
33 35
import java.io.FileWriter;
34 36
import java.io.StringReader;
35 37
import java.util.Stack;
......
698 700
       else
699 701
       {
700 702
          MetaCatUtil.debugMessage("Write inline data into file system", 35);
703
          
704
          //check if user changed inine data or not if user doesn't have
705
          // write permission
706
          if (startCriticalSubTree)
707
          {
708
            NodeRecord node = null;
709
            String inlineData;
710
            try
711
            {
712
              node = (NodeRecord)currentUnChangedableSubtreeNodeStack.pop();
713
              // get file name from db
714
              String fileName = node.getNodeData();
715
              MetaCatUtil.debugMessage("in handle inline data", 35);
716
              MetaCatUtil.debugMessage("the inline data file name from node is: "+
717
                                      fileName, 40);
718
              inlineData = readInlineDataFromFileSystem(fileName);
719
            }
720
            catch (EmptyStackException ee)
721
            {
722
              MetaCatUtil.debugMessage("the stack is empty for text data", 32);
723
              throw new SAXException(PERMISSIONERROR);
724
            }
725
            catch (McdbException eee)
726
            {
727
              throw new SAXException(eee.getMessage());
728
            }
729
            
730
            if (!(textBuffer.toString()).equals(inlineData))
731
            {
732
              MetaCatUtil.debugMessage("inline data was changed by a user" +
733
                                       " who doesn't have permission", 30);
734
              throw new SAXException(PERMISSIONERROR);
735
            }//if
736
          }//if
701 737
          // write inline data into file system and return file name
702 738
          textBuffer = writeInlineDataIntoFile(textBuffer);
703 739
          // write file name into db
......
1292 1328
    fileNameBuffer = new StringBuffer(fileName);
1293 1329
    return fileNameBuffer;
1294 1330
  }
1295
 
1331
  
1332
  /* In eml2, the inline data wouldn't store in db, it store in file system
1333
   * The db stores file name(without path).
1334
   */
1335
  public static String readInlineDataFromFileSystem(String fileName) 
1336
                                              throws McdbException
1337
  {
1338
    String data = null;
1339
    String path = MetaCatUtil.getOption("inlinedatafilepath");
1340
    // the new file name will look like path/docid.rev.2
1341
    File inlineDataDirectory = new File(path);
1342
    File dataFile = new File(inlineDataDirectory, fileName);
1343
    try
1344
    {
1345
      FileReader fileReader = new FileReader(dataFile);
1346
      BufferedReader stringReader = new BufferedReader(fileReader);
1347
      // read first line of data
1348
      String tmp = stringReader.readLine();
1349
      // pass first line data to data varible
1350
      data = tmp;
1351
      // at the end tmp will be null
1352
      while (tmp != null)
1353
      {
1354
        // read a new line
1355
        tmp = stringReader.readLine();
1356
        // append new line to data
1357
        if (tmp != null)
1358
        {
1359
          data = data+tmp;
1360
        }
1361
      }
1362
      
1363
    }
1364
    catch (Exception e)
1365
    {
1366
      throw new McdbException(e.getMessage());
1367
    }
1368
    MetaCatUtil.debugMessage("the inline data retrieve from file: "+data, 50);
1369
    return data;
1370
  }
1296 1371
}

Also available in: Unified diff