Project

General

Profile

« Previous | Next » 

Revision 680

Added by bojilova over 23 years ago

included new servlet parameter "public" specifing public read access for the submitted document
the expected values are "yes" or "no"
public parameter is optional and if it is not specified, means "no"

View differences:

src/edu/ucsb/nceas/metacat/MetaCatServlet.java
1150 1150
      // Get the document indicated
1151 1151
      String[] doctext = (String[])params.get("doctext");
1152 1152

  
1153
      StringReader acl = null;
1154
      if(params.containsKey("acltext"))
1155
      {
1156
        String[] acltext = (String[])params.get("acltext");
1157
        try {
1158
          if ( !acltext[0].equals("") ) {
1159
            acl = new StringReader(acltext[0]);
1160
          }
1161
        } catch (NullPointerException npe) {}
1153
      String pub = null;
1154
      if (params.containsKey("public")) {
1155
        pub = ((String[])params.get("public"))[0];
1162 1156
      }
1157

  
1163 1158
      StringReader dtd = null;
1164
      if(params.containsKey("dtdtext"))
1165
      {
1159
      if (params.containsKey("dtdtext")) {
1166 1160
        String[] dtdtext = (String[])params.get("dtdtext");
1167 1161
        try {
1168 1162
          if ( !dtdtext[0].equals("") ) {
......
1187 1181
        }
1188 1182

  
1189 1183
        try {
1190
            // get a connection from the pool
1191
            conn = util.getConnection();
1184
          // get a connection from the pool
1185
          conn = util.getConnection();
1192 1186

  
1193
            // write the document to the database
1194
            try {
1195
                String accNumber = docid[0];
1196
                if (accNumber.equals("")) {
1197
                    accNumber = null;
1198
                }
1199
                newdocid = DocumentImpl.write(conn, xml, acl, dtd, doAction,
1200
                                              accNumber, user, group);
1201
                
1202
            } catch (NullPointerException npe) {
1203
              newdocid = DocumentImpl.write(conn, xml, acl, dtd, doAction,
1204
                                            null, user, group);
1187
          // write the document to the database
1188
          try {
1189
            String accNumber = docid[0];
1190
            if (accNumber.equals("")) {
1191
              accNumber = null;
1205 1192
            }
1206
//        } catch (Exception e) {
1207
//          response.setContentType("text/html");
1208
//          out.println(e.getMessage());
1193
            newdocid = DocumentImpl.write(conn, xml, pub, dtd, doAction,
1194
                                          accNumber, user, group);
1195
          } catch (NullPointerException npe) {
1196
            newdocid = DocumentImpl.write(conn, xml, pub, dtd, doAction,
1197
                                          null, user, group);
1198
          }
1209 1199
        } finally {
1210 1200
          util.returnConnection(conn);
1211 1201
        }    
src/edu/ucsb/nceas/metacat/DBSAXHandler.java
64 64
   private String   docid = null;
65 65
   private String   user = null;
66 66
   private String   group = null;
67
   private String   pub = null;
67 68
   private Thread   xmlIndex;
68 69
   private boolean endDocument = false;
69 70
   private int serverCode = 1;
......
89 90
     }
90 91
   }
91 92
   
92
   public DBSAXHandler(Connection conn, String action, String docid,
93
                       String user, String group, int serverCode)
94
   {
95
     this(conn);
96
     this.action = action;
97
     this.docid = docid;
98
     this.user = user;
99
     this.group = group;
100
     this.xmlIndex = new Thread(this);
101
     this.serverCode = serverCode;
102
   }
103
 
104 93
   /** Construct an instance of the handler class 
105 94
    *
106 95
    * @param conn the JDBC connection to which information is written
107 96
    * @param action - "INSERT" or "UPDATE"
108 97
    * @param docid to be inserted or updated into JDBC connection
109
    * @param user the user connected to MetaCat servlet
98
    * @param user the user connected to MetaCat servlet and owns the document
99
    * @param group the group to which user belongs
100
    * @param pub flag for public "read" access on document
101
    * @param serverCode the serverid from xml_replication on which this document
102
    *        resides.
103
    *
110 104
    */
111
   public DBSAXHandler(Connection conn,String action,String docid,
112
                       String user, String group)
105
   public DBSAXHandler(Connection conn, String action, String docid,
106
                       String user, String group, String pub, int serverCode)
113 107
   {
114 108
     this(conn);
115 109
     this.action = action;
116 110
     this.docid = docid;
117 111
     this.user = user;
118 112
     this.group = group;
113
     this.pub = pub;
114
     this.serverCode = serverCode;
119 115
     this.xmlIndex = new Thread(this);
120
     //this.xmlIndex.setPriority(Thread.MIN_PRIORITY);
121 116
   }
117
 
118
// NOT USED ANY MORE
119
//   public DBSAXHandler(Connection conn,String action,String docid,
120
//                       String user, String group)
121
//   {
122
//     this(conn);
123
//     this.action = action;
124
//     this.docid = docid;
125
//     this.user = user;
126
//     this.group = group;
127
//     this.xmlIndex = new Thread(this);
128
//     //this.xmlIndex.setPriority(Thread.MIN_PRIORITY);
129
//   }
122 130

  
123 131
   /** SAX Handler that receives notification of beginning of the document */
124 132
   public void startDocument() throws SAXException {
......
178 186
       rootNode.writeNodename(docname);
179 187
       try {
180 188
         currentDocument = new DocumentImpl(conn, rootNode.getNodeID(), 
181
                                       docname, doctype, docid, action, user, 
182
                                       this.serverCode);
189
                               docname, doctype, docid, action, user, this.pub,
190
                               this.serverCode);
183 191
       } catch (Exception ane) {
184 192
         throw (new SAXException("Error in DBSaxHandler.startElement " + 
185 193
                                 action, ane));
src/edu/ucsb/nceas/metacat/DocumentImpl.java
132 132
   *                  following the PUBLIC keyword in DOCTYPE declaration or
133 133
   *                  the docname if no Public ID provided or
134 134
   *                  null if no DOCTYPE declaration provided
135
   * @param docid the docid to use for the INSERT OR UPDATE
136
   * @param action the action to be performed (INSERT OR UPDATE)
137
   * @param user the user that owns the document
138
   * @param pub flag for public "read" access on document
139
   * @param serverCode the serverid from xml_replication on which this document
140
   *        resides.
135 141
   *
136 142
   */
137 143
  public DocumentImpl(Connection conn, long rootnodeid, String docname, 
138 144
                      String doctype, String docid, String action, String user,
139
                      int serverCode)
145
                      String pub, int serverCode)
140 146
                      throws SQLException, Exception
141 147
  {
142 148
    this.conn = conn;
......
144 150
    this.docname = docname;
145 151
    this.doctype = doctype;
146 152
    this.docid = docid;
147
    writeDocumentToDB(action, user, serverCode);
153
    writeDocumentToDB(action, user, pub, serverCode);
148 154
  }
149 155
  
150
  public DocumentImpl(Connection conn, long rootnodeid, String docname, 
151
                      String doctype, String docid, String action, String user)
152
                      throws SQLException, Exception
153
  {
154
    this.conn = conn;
155
    this.rootnodeid = rootnodeid;
156
    this.docname = docname;
157
    this.doctype = doctype;
158
    this.docid = docid;
159
    writeDocumentToDB(action, user);
160
  }
156
// NOT USED ANY MORE
157
//  public DocumentImpl(Connection conn, long rootnodeid, String docname, 
158
//                      String doctype, String docid, String action, String user)
159
//                      throws SQLException, Exception
160
//  {
161
//    this.conn = conn;
162
//    this.rootnodeid = rootnodeid;
163
//    this.docname = docname;
164
//    this.doctype = doctype;
165
//    this.docid = docid;
166
//    writeDocumentToDB(action, user);
167
//  }
161 168

  
162 169
  /**
163 170
   * get the document name
......
614 621
  private void writeDocumentToDB(String action, String user)
615 622
               throws SQLException, Exception
616 623
  {
617
    writeDocumentToDB(action, user, 1);
624
    writeDocumentToDB(action, user, null, 1);
618 625
  }
619 626

  
620 627
 /** creates SQL code and inserts new document into DB connection */
621
  private void writeDocumentToDB(String action, String user, int serverCode) 
628
  private void writeDocumentToDB(String action, String user, String pub, 
629
                                 int serverCode) 
622 630
               throws SQLException, Exception {
623 631
    try {
624 632
      PreparedStatement pstmt = null;
......
628 636
        //this.docid = ac.generate(docid, "INSERT");
629 637
        pstmt = conn.prepareStatement(
630 638
            "INSERT INTO xml_documents " +
631
            "(docid, rootnodeid, docname, doctype, user_owner, " +
632
            "user_updated, date_created, date_updated, server_location) " +
633
            "VALUES (?, ?, ?, ?, ?, ?, sysdate, sysdate, ?)");
639
            "(docid, rootnodeid, docname, doctype, user_owner, user_updated, " +
640
            "date_created, date_updated, public_access, server_location) " +
641
            "VALUES (?, ?, ?, ?, ?, ?, sysdate, sysdate, ?, ?)");
634 642
        //note that the server_location is set to 1. 
635 643
        //this means that "localhost" in the xml_replication table must
636 644
        //always be the first entry!!!!!
......
642 650
        pstmt.setString(4, doctype);
643 651
        pstmt.setString(5, user);
644 652
        pstmt.setString(6, user);
645
        pstmt.setInt(7, serverCode);
653
        if ( pub == null ) {
654
          pstmt.setString(7, null);
655
        } else if ( pub.toUpperCase().equals("YES") ) {
656
          pstmt.setInt(7, 1);
657
        } else if ( pub.toUpperCase().equals("NO") ) {
658
          pstmt.setInt(7, 0);
659
        }
660
        pstmt.setInt(8, serverCode);
646 661
      } else if (action.equals("UPDATE")) {
647 662

  
648 663
        // Save the old document entry in a backup table
......
662 677
            "UPDATE xml_documents " +
663 678
            "SET rootnodeid = ?, docname = ?, doctype = ?, " +
664 679
            "user_updated = ?, date_updated = sysdate, " +
665
            "server_location = ?, rev = ? WHERE docid LIKE ?");
680
            "server_location = ?, rev = ?, public_access = ? " +
681
            "WHERE docid LIKE ?");
666 682
        // Bind the values to the query
667 683
        pstmt.setLong(1, rootnodeid);
668 684
        pstmt.setString(2, docname);
......
670 686
        pstmt.setString(4, user);
671 687
        pstmt.setInt(5, serverCode);
672 688
        pstmt.setInt(6, thisrev);
673
        pstmt.setString(7, this.docid);
689
        if ( pub == null ) {
690
          pstmt.setString(7, null);
691
        } else if ( pub.toUpperCase().equals("YES") ) {
692
          pstmt .setInt(7, 1);
693
        } else if ( pub.toUpperCase().equals("NO") ) {
694
          pstmt.setInt(7, 0);
695
        }
696
        pstmt.setString(8, this.docid);
674 697

  
675 698
      } else {
676 699
        System.err.println("Action not supported: " + action);
......
726 749
   *
727 750
   * @param conn the JDBC connection to the database
728 751
   * @param filename the filename to be loaded into the database
752
   * @param pub flag for public "read" access on document
753
   * @param dtdfilename the dtd to be uploaded on server's file system
729 754
   * @param action the action to be performed (INSERT OR UPDATE)
730 755
   * @param docid the docid to use for the INSERT OR UPDATE
756
   * @param user the user that owns the document
757
   * @param group the group to which user belongs
731 758
   */
732 759
  public static String write(Connection conn,String filename,
733
                             String aclfilename,String dtdfilename,
760
                             String pub, String dtdfilename,
734 761
                             String action, String docid, String user,
735 762
                             String group )
736 763
                throws Exception {
737 764
                  
738
    Reader acl = null;
739
    if ( aclfilename != null ) {
740
      acl = new FileReader(new File(aclfilename).toString());
741
    }
742 765
    Reader dtd = null;
743 766
    if ( dtdfilename != null ) {
744 767
      dtd = new FileReader(new File(dtdfilename).toString());
745 768
    }
746 769
    return write ( conn, new FileReader(new File(filename).toString()),
747
                   acl, dtd, action, docid, user, group);
770
                   pub, dtd, action, docid, user, group);
748 771
  }
749 772

  
750
  public static String write(Connection conn,Reader xml,Reader acl,Reader dtd,
773
  public static String write(Connection conn,Reader xml,String pub,Reader dtd,
751 774
                             String action, String docid, String user,
752 775
                             String group )
753 776
                throws Exception {
754
    return write ( conn, xml, acl, dtd, action, docid, user, group, 1, false);
777
    return write ( conn, xml, pub, dtd, action, docid, user, group, 1, false);
755 778
  }
756 779

  
757
  public static String write(Connection conn,Reader xml,Reader acl,
780
  public static String write(Connection conn, Reader xml, String pub,
758 781
                             String action, String docid, String user,
759 782
                             String group )
760 783
                throws Exception {
......
763 786
     //originally inserted document.
764 787
      DocumentImpl doc = new DocumentImpl(conn, docid);
765 788
      int servercode = doc.getServerlocation();
766
      return write(conn,xml,acl,action,docid,user,group,servercode);
789
      return write(conn, xml, pub, action, docid, user, group, servercode);
767 790
    }
768 791
    else
769 792
    {//if the file is being inserted then the servercode is always 1
770
      return write(conn, xml, acl, action, docid, user, group, 1);
793
      return write(conn, xml, pub, action, docid, user, group, 1);
771 794
    }
772 795
  }
773 796
  
......
779 802
    return write(conn,xml,null,action,docid,user,group,serverCode);
780 803
  }
781 804
  
782
  public static String write( Connection conn,Reader xml,Reader acl,
805
  public static String write( Connection conn, Reader xml, String pub,
783 806
                              String action, String docid, String user,
784 807
                              String group, int serverCode) 
785 808
                throws Exception
786 809
  {
787
    return write(conn,xml,acl,null,action,docid,user,group,serverCode,false);
810
    return write(conn,xml,pub,null,action,docid,user,group,serverCode,false);
788 811
  }
789 812
  
790
  public static String write( Connection conn,Reader xml,Reader acl,
813
  public static String write( Connection conn, Reader xml, String pub,
791 814
                              String action, String docid, String user,
792 815
                              String group, int serverCode, boolean override)
793 816
                throws Exception
794 817
  {
795
    return write(conn,xml,acl,null,action,docid,user,group,serverCode,override);
818
    return write(conn,xml,pub,null,action,docid,user,group,serverCode,override);
796 819
  }
797 820
  
798 821
  /**
......
800 823
   *
801 824
   * @param conn the JDBC connection to the database
802 825
   * @param xml the xml stream to be loaded into the database
826
   * @param pub flag for public "read" access on xml document
827
   * @param dtd the dtd to be uploaded on server's file system
803 828
   * @param action the action to be performed (INSERT OR UPDATE)
804 829
   * @param docid the docid to use for the INSERT OR UPDATE
805 830
   * @param user the user that owns the document
......
813 838
   *        update will be locked and version checked.
814 839
   */
815 840

  
816
  public static String write( Connection conn,Reader xml,Reader acl,Reader dtd,
841
  public static String write( Connection conn,Reader xml,String pub,Reader dtd,
817 842
                              String action, String docid, String user,
818 843
                              String group, int serverCode, boolean override)
819 844
                throws Exception
......
858 883
          MetacatReplication.replLog("lock granted for " + docid + " from " +
859 884
                                      server);
860 885
          XMLReader parser = initializeParser(conn, action, newdocid, 
861
                                              user, group, serverCode, dtd);
886
                                              user, group, pub, serverCode, dtd);
862 887
          conn.setAutoCommit(false);
863 888
          parser.parse(new InputSource(xml));
864 889
          conn.commit();
......
920 945
    try 
921 946
    { 
922 947
      XMLReader parser = initializeParser(conn, action, newdocid, 
923
                                          user, group, serverCode, dtd);
948
                                          user, group, pub, serverCode, dtd);
924 949
      conn.setAutoCommit(false);
925 950
      parser.parse(new InputSource(xml));
926 951
      conn.commit();
......
1024 1049
   */
1025 1050
  private static XMLReader initializeParser(Connection conn, String action,
1026 1051
                                   String docid, String user, String group,
1027
                                   int serverCode, Reader dtd) 
1052
                                   String pub, int serverCode, Reader dtd) 
1028 1053
                           throws Exception 
1029 1054
  {
1030 1055
    XMLReader parser = null;
......
1033 1058
    //
1034 1059
    try {
1035 1060
      ContentHandler chandler = new DBSAXHandler(conn, action, docid,
1036
                                                 user, group, serverCode);
1061
                                                 user, group, pub, serverCode);
1037 1062
      EntityResolver eresolver= new DBEntityResolver(conn,
1038 1063
                                                 (DBSAXHandler)chandler, dtd);
1039 1064
      DTDHandler dtdhandler   = new DBDTDHandler(conn);
......
1105 1130
     
1106 1131
    try {
1107 1132
      String filename    = null;
1108
      String aclfilename = null;
1109 1133
      String dtdfilename = null;
1110 1134
      String action      = null;
1111 1135
      String docid       = null;
......
1116 1140
      for ( int i=0 ; i < args.length; ++i ) {
1117 1141
        if ( args[i].equals( "-f" ) ) {
1118 1142
          filename =  args[++i];
1119
        } else if ( args[i].equals( "-c" ) ) {
1120
          aclfilename =  args[++i];
1121 1143
        } else if ( args[i].equals( "-r" ) ) {
1122 1144
          dtdfilename =  args[++i];
1123 1145
        } else if ( args[i].equals( "-a" ) ) {
......
1161 1183
        System.err.println("Wrong number of arguments!!!");
1162 1184
        System.err.println(
1163 1185
          "USAGE: java DocumentImpl [-t] <-a INSERT> [-d docid] <-f filename> "+
1164
          "[-c aclfilename] [-r dtdfilename]");
1186
          "[-r dtdfilename]");
1165 1187
        System.err.println(
1166 1188
          "   OR: java DocumentImpl [-t] <-a UPDATE -d docid -f filename> " +
1167
          "[-c aclfilename] [-r dtdfilename]");
1189
          "[-r dtdfilename]");
1168 1190
        System.err.println(
1169 1191
          "   OR: java DocumentImpl [-t] <-a DELETE -d docid>");
1170 1192
        System.err.println(
......
1192 1214
        DocumentImpl.delete(dbconn, docid, null, null);
1193 1215
        System.out.println("Document deleted: " + docid);
1194 1216
      } else {
1195
        String newdocid = DocumentImpl.write(dbconn, filename, aclfilename,
1217
        String newdocid = DocumentImpl.write(dbconn, filename, null,
1196 1218
                                             dtdfilename, action, docid,
1197 1219
                                             null, null);
1198 1220
        if ((docid != null) && (!docid.equals(newdocid))) {

Also available in: Unified diff