Project

General

Profile

« Previous | Next » 

Revision 1458

Added by Jing Tao over 21 years ago

Add code to put back inline data from file system.

View differences:

src/edu/ucsb/nceas/metacat/DocumentImpl.java
90 90
                              "http://xml.org/sax/features/namespaces";
91 91
   public static final String NAMESPACEPREFIXESFEATURE = 
92 92
                              "http://xml.org/sax/features/namespace-prefixes";
93
   private static final String EMLNAMESPACE = 
94
                                          "eml://ecoinformatics.org/eml-2.0.0";
93 95
  
94 96
  
95 97
  static final int ALL = 1;
......
806 808
  public void toXml(Writer pw, String user, String[] groups) 
807 809
                                                          throws McdbException
808 810
  {
811
    // flag for process  eml2
812
    boolean proccessEml2 = false;
813
    if (doctype != null && doctype.equals(EMLNAMESPACE))
814
    {
815
      proccessEml2 = true;
816
    }
817
    // flag for process inline data
818
    boolean prcocessInlineData = false;
819
    
809 820
    TreeSet nodeRecordLists = null;
810 821
    PrintWriter out = null;
811 822
    if (pw instanceof PrintWriter) {
......
919 930
        } else {
920 931
          out.print("<" + currentNode.nodename);
921 932
        }
933
        
934
        // if currentNode is inline and handle eml2, set flag proccess in
935
        if (currentNode.nodename != null && 
936
            currentNode.nodename.equals(EmlSAXHandler.INLINE) && proccessEml2)
937
        {
938
          prcocessInlineData = true;
939
        }
922 940

  
923 941
      // Handle the ATTRIBUTE nodes
924 942
      } else if (currentNode.nodetype.equals("ATTRIBUTE")) {
......
940 958
        if (previousNodeWasElement) {
941 959
          out.print(">");
942 960
        }
943
        out.print(currentNode.nodedata);
961
        if (!prcocessInlineData)
962
        {
963
          // if it is not inline data just out put data
964
          out.print(currentNode.nodedata);
965
        }
966
        else
967
        {
968
          // if it is inline data pull out from file system and output it
969
          // for inline data, the data base only store the file name, so we
970
          // can combine the file name and inline data file path, to get it
971
          String fileName = currentNode.nodedata;
972
          String content = readInlineDataFromFileSystem(fileName);
973
          out.print(content);
974
        }
975
        // reset proccess inline data false
976
        prcocessInlineData =false;
944 977
        previousNodeWasElement = false;
945 978

  
946 979
      // Handle the COMMENT nodes
......
983 1016
    out.flush();
984 1017
  }
985 1018
  
1019
  /* In eml2, the inline data wouldn't store in db, it store in file system
1020
   * The db stores file name(without path).
1021
   */
1022
  private String readInlineDataFromFileSystem(String fileName) 
1023
                                              throws McdbException
1024
  {
1025
    String data = null;
1026
    String path = MetaCatUtil.getOption("inlinedatafilepath");
1027
    // the new file name will look like path/docid.rev.2
1028
    File inlineDataDirectory = new File(path);
1029
    File dataFile = new File(inlineDataDirectory, fileName);
1030
    try
1031
    {
1032
      FileReader fileReader = new FileReader(dataFile);
1033
      BufferedReader stringReader = new BufferedReader(fileReader);
1034
      // read first line of data
1035
      String tmp = stringReader.readLine();
1036
      // pass first line data to data varible
1037
      data = tmp;
1038
      // at the end tmp will be null
1039
      while (tmp != null)
1040
      {
1041
        // read a new line
1042
        tmp = stringReader.readLine();
1043
        // append new line to data
1044
        data = data+tmp;
1045
      }
1046
      
1047
    }
1048
    catch (Exception e)
1049
    {
1050
      throw new McdbException(e.getMessage());
1051
    }
1052
    return data;
1053
  }
1054
  
986 1055
  private boolean isRevisionOnly(DocumentIdentifier docid) throws Exception
987 1056
  {
988 1057
    //System.out.println("inRevisionOnly");

Also available in: Unified diff